-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(resolver): expose resolve strategies (#2854)
Part of this commit is consolidation of resolve strategies and introduction of new 'strategies' option for resolve and resolveSubTree functions. The way this has been implemented allow effective tree shaking. Full API backward compatibility has remained.
- Loading branch information
Showing
34 changed files
with
141 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import resolveGenericStrategy from './resolve.js'; | ||
import normalize from './normalize.js'; | ||
import { plugins } from '../../../specmap/index.js'; | ||
|
||
export function clearCache() { | ||
plugins.refs.clearCache(); | ||
} | ||
|
||
const genericStrategy = { | ||
name: 'generic', | ||
match() { | ||
return true; | ||
}, | ||
normalize({ spec }) { | ||
const { spec: normalized } = normalize({ spec }); | ||
return normalized; | ||
}, | ||
async resolve(options) { | ||
return resolveGenericStrategy(options); | ||
}, | ||
}; | ||
export default genericStrategy; |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import resolveOpenAPI2Strategy from './resolve.js'; | ||
import normalize from './normalize.js'; | ||
import { isOpenAPI2 } from '../../../helpers/openapi-predicates.js'; | ||
|
||
export { clearCache } from '../generic/index.js'; | ||
|
||
const openApi2Strategy = { | ||
name: 'openapi-2', | ||
match({ spec }) { | ||
return isOpenAPI2(spec); | ||
}, | ||
normalize({ spec }) { | ||
const { spec: normalized } = normalize({ spec }); | ||
return normalized; | ||
}, | ||
async resolve(options) { | ||
return resolveOpenAPI2Strategy(options); | ||
}, | ||
}; | ||
export default openApi2Strategy; |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export { default } from '../generic/normalize.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,5 @@ | ||
import resolveGenericStrategy from '../generic/resolve.js'; | ||
|
||
export default async function resolveOpenAPI2Strategy(options) { | ||
return resolveGenericStrategy(options); | ||
} |
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,20 @@ | ||
import resolveOpenAPI30Strategy from './resolve.js'; | ||
import normalize from './normalize.js'; | ||
import { isOpenAPI30 } from '../../../helpers/openapi-predicates.js'; | ||
|
||
export { clearCache } from '../generic/index.js'; | ||
|
||
const openApi30Strategy = { | ||
name: 'openapi-3-0', | ||
match({ spec }) { | ||
return isOpenAPI30(spec); | ||
}, | ||
normalize({ spec }) { | ||
const { spec: normalized } = normalize({ spec }); | ||
return normalized; | ||
}, | ||
async resolve(options) { | ||
return resolveOpenAPI30Strategy(options); | ||
}, | ||
}; | ||
export default openApi30Strategy; |
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,2 @@ | ||
// eslint-disable-next-line no-restricted-exports | ||
export { default } from '../generic/normalize.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,5 @@ | ||
import resolveGenericStrategy from '../generic/resolve.js'; | ||
|
||
export default async function resolveOpenAPI30Strategy(options) { | ||
return resolveGenericStrategy(options); | ||
} |
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,17 @@ | ||
import resolveOpenAPI31Strategy from './resolve.js'; | ||
import normalize, { pojoAdapter } from './normalize.js'; | ||
import { isOpenAPI31 } from '../../../helpers/openapi-predicates.js'; | ||
|
||
const openApi31ApiDOMStrategy = { | ||
name: 'openapi-3-1-apidom', | ||
match({ spec }) { | ||
return isOpenAPI31(spec); | ||
}, | ||
normalize({ spec }) { | ||
return pojoAdapter(normalize)(spec); | ||
}, | ||
async resolve(options) { | ||
return resolveOpenAPI31Strategy(options); | ||
}, | ||
}; | ||
export default openApi31ApiDOMStrategy; |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...er/strategies/openapi-2--3-0/normalize.js → .../resolver/strategies/generic/normalize.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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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