-
Notifications
You must be signed in to change notification settings - Fork 762
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add OpenAPI 3.1.0 dereference strategy (#2740)
Refs #2717
- Loading branch information
Showing
329 changed files
with
8,429 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/helpers/apidom/reference/dereference/strategies/openapi-3-1-swagger-client/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* eslint-disable camelcase */ | ||
import { createNamespace, visit } from '@swagger-api/apidom-core'; | ||
import { ReferenceSet, Reference } from '@swagger-api/apidom-reference/configuration/empty'; | ||
import OpenApi3_1DereferenceStrategy from '@swagger-api/apidom-reference/dereference/strategies/openapi-3-1'; | ||
import openApi3_1Namespace, { getNodeType, keyMap } from '@swagger-api/apidom-ns-openapi-3-1'; | ||
|
||
import OpenApi3_1SwaggerClientDereferenceVisitor from './visitor.js'; | ||
|
||
const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')]; | ||
|
||
const OpenApi3_1SwaggerClientDereferenceStrategy = OpenApi3_1DereferenceStrategy.compose({ | ||
props: { | ||
useCircularStructures: true, | ||
allowMetaPatches: false, | ||
}, | ||
init({ | ||
useCircularStructures = this.useCircularStructures, | ||
allowMetaPatches = this.allowMetaPatches, | ||
} = {}) { | ||
this.name = 'openapi-3-1-swagger-client'; | ||
this.useCircularStructures = useCircularStructures; | ||
this.allowMetaPatches = allowMetaPatches; | ||
}, | ||
methods: { | ||
async dereference(file, options) { | ||
const namespace = createNamespace(openApi3_1Namespace); | ||
const refSet = options.dereference.refSet ?? ReferenceSet(); | ||
let reference; | ||
|
||
if (!refSet.has(file.uri)) { | ||
reference = Reference({ uri: file.uri, value: file.parseResult }); | ||
refSet.add(reference); | ||
} else { | ||
// pre-computed refSet was provided as configuration option | ||
reference = refSet.find((ref) => ref.uri === file.uri); | ||
} | ||
|
||
const visitor = OpenApi3_1SwaggerClientDereferenceVisitor({ | ||
reference, | ||
namespace, | ||
options, | ||
useCircularStructures: this.useCircularStructures, | ||
allowMetaPatches: this.allowMetaPatches, | ||
}); | ||
const dereferencedElement = await visitAsync(refSet.rootRef.value, visitor, { | ||
keyMap, | ||
nodeTypeGetter: getNodeType, | ||
}); | ||
|
||
/** | ||
* Release all memory if this refSet was not provided as a configuration option. | ||
* If provided as configuration option, then provider is responsible for cleanup. | ||
*/ | ||
if (options.dereference.refSet === null) { | ||
refSet.clean(); | ||
} | ||
|
||
return dereferencedElement; | ||
}, | ||
}, | ||
}); | ||
|
||
export default OpenApi3_1SwaggerClientDereferenceStrategy; | ||
/* eslint-enable camelcase */ |
Oops, something went wrong.