Skip to content

Commit

Permalink
feat(json-schema-2020-12-sample): introduce option API (#9795)
Browse files Browse the repository at this point in the history
Refs #9739
  • Loading branch information
char0n committed Apr 9, 2024
1 parent 1267c04 commit 7db9c98
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/plugins/json-schema-2020-12-samples/fn/api/optionAPI.js
@@ -0,0 +1,17 @@
/**
* @prettier
*/

import OptionRegistry from "../class/OptionRegistry"

const registry = new OptionRegistry()

const optionAPI = (optionName, optionValue) => {
if (typeof optionValue !== "undefined") {
registry.register(optionName, optionValue)
}

return registry.get(optionName)
}

export default optionAPI
@@ -0,0 +1,16 @@
/**
* @prettier
*/
import Registry from "./Registry"

class OptionRegistry extends Registry {
#defaults = {}

data = { ...this.#defaults }

get defaults() {
return { ...this.#defaults }
}
}

export default OptionRegistry
1 change: 1 addition & 0 deletions src/core/plugins/json-schema-2020-12-samples/fn/index.js
Expand Up @@ -8,6 +8,7 @@ export {
memoizedSampleFromSchema,
memoizedCreateXMLExample,
} from "./main"
export { default as optionAPI } from "./api/optionAPI"
export { default as encoderAPI } from "./api/encoderAPI"
export { default as formatAPI } from "./api/formatAPI"
export { default as mediaTypeAPI } from "./api/mediaTypeAPI"
Expand Down
2 changes: 2 additions & 0 deletions src/core/plugins/json-schema-2020-12-samples/index.js
Expand Up @@ -7,6 +7,7 @@ import {
createXMLExample,
memoizedSampleFromSchema,
memoizedCreateXMLExample,
optionAPI,
encoderAPI,
mediaTypeAPI,
formatAPI,
Expand All @@ -28,6 +29,7 @@ const JSONSchema202012SamplesPlugin = ({ getSystem }) => {
jsonSchema202012: {
sampleFromSchema,
sampleFromSchemaGeneric,
sampleOptionAPI: optionAPI,
sampleEncoderAPI: encoderAPI,
sampleFormatAPI: formatAPI,
sampleMediaTypeAPI: mediaTypeAPI,
Expand Down

0 comments on commit 7db9c98

Please sign in to comment.