Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reference): add resolver strategy that handles abstract RefEleme…
- Loading branch information
Showing
31 changed files
with
568 additions
and
132 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
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
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
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
44 changes: 44 additions & 0 deletions
44
packages/apidom-reference/src/resolve/strategies/apidom/index.ts
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,44 @@ | ||
import stampit from 'stampit'; | ||
import { isElement, visit, cloneDeep } from '@swagger-api/apidom-core'; | ||
|
||
import ResolveStrategy from '../ResolveStrategy'; | ||
import { | ||
File as IFile, | ||
ReferenceOptions as IReferenceOptions, | ||
ResolveStrategy as IResolveStrategy, | ||
} from '../../../types'; | ||
import ReferenceSet from '../../../ReferenceSet'; | ||
import Reference from '../../../Reference'; | ||
import ApiDOMResolveVisitor from './visitor'; | ||
|
||
// @ts-ignore | ||
const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')]; | ||
|
||
const ApiDOMResolveStrategy: stampit.Stamp<IResolveStrategy> = stampit(ResolveStrategy, { | ||
init() { | ||
this.name = 'apidom'; | ||
}, | ||
methods: { | ||
canResolve(file: IFile) { | ||
return ( | ||
file.mediaType.startsWith('application/vnd.apidom') && isElement(file.parseResult?.result) | ||
); | ||
}, | ||
|
||
async resolve(file: IFile, options: IReferenceOptions) { | ||
const referenceValue = options.resolve.strategyOpts.apidom?.clone | ||
? cloneDeep(file.parseResult) | ||
: file.parseResult; | ||
const reference = Reference({ uri: file.uri, value: referenceValue }); | ||
const visitor = ApiDOMResolveVisitor({ reference, options }); | ||
const refSet = ReferenceSet(); | ||
refSet.add(reference); | ||
|
||
await visitAsync(refSet.rootRef.value, visitor); | ||
|
||
return refSet; | ||
}, | ||
}, | ||
}); | ||
|
||
export default ApiDOMResolveStrategy; |
7 changes: 7 additions & 0 deletions
7
packages/apidom-reference/src/resolve/strategies/apidom/visitor.ts
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,7 @@ | ||
import stampit from 'stampit'; | ||
|
||
import ApiDOMDereferenceVisitor from '../../../dereference/strategies/apidom/visitor'; | ||
|
||
const ApiDOMResolveVisitor = stampit(ApiDOMDereferenceVisitor); | ||
|
||
export default ApiDOMResolveVisitor; |
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
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
1 change: 1 addition & 0 deletions
1
packages/apidom-reference/test/dereference/strategies/apidom/local/fixtures/apidom.json
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 @@ | ||
{"element":"object","content":[{"element":"member","content":{"key":{"element":"string","content":"element"},"value":{"element":"string","meta":{"id":{"element":"string","content":"unique-id"}},"content":"b"}}},{"element":"member","content":{"key":{"element":"string","content":"ref"},"value":{"element":"ref","attributes":{"path":{"element":"string","content":"element"}},"content":"unique-id"}}}]} |
3 changes: 3 additions & 0 deletions
3
packages/apidom-reference/test/dereference/strategies/apidom/local/fixtures/object.json
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,3 @@ | ||
{ | ||
"a": "b" | ||
} |
Oops, something went wrong.