-
Notifications
You must be signed in to change notification settings - Fork 9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(oas31): introduce selector composition mechanism (#8484)
Refs #8474
- Loading branch information
Showing
6 changed files
with
197 additions
and
176 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/** | ||
* @prettier | ||
*/ | ||
|
||
export const isOAS31 = (jsSpec) => { | ||
const oasVersion = jsSpec.get("openapi") | ||
|
||
return ( | ||
typeof oasVersion === "string" && /^3\.1\.(?:[1-9]\d*|0)$/.test(oasVersion) | ||
) | ||
} | ||
|
||
/** | ||
* Creates selector that returns value of the original | ||
* selector when spec is OpenAPI 3.1.0., null otherwise. | ||
* | ||
* @param selector | ||
* @returns {function(*, ...[*]): function(*): (*|null)} | ||
*/ | ||
export const createOnlyOAS31Selector = | ||
(selector) => | ||
(state, ...args) => | ||
(system) => { | ||
if (system.getSystem().specSelectors.isOAS31()) { | ||
const selectedValue = selector(state, ...args) | ||
return typeof selectedValue === "function" | ||
? selectedValue(system) | ||
: selectedValue | ||
} else { | ||
return null | ||
} | ||
} | ||
|
||
/** | ||
* Creates selector that provides system as the | ||
* second argument. This allows to create memoized | ||
* composed selectors from different plugins. | ||
* | ||
* @param selector | ||
* @returns {function(*, ...[*]): function(*): *} | ||
*/ | ||
export const createSystemSelector = | ||
(selector) => | ||
(state, ...args) => | ||
(system) => { | ||
const selectedValue = selector(state, system, ...args) | ||
return typeof selectedValue === "function" | ||
? selectedValue(system) | ||
: selectedValue | ||
} |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.