feat: introduce samples framework for JSON Schema 2020-12

Refs #8577
This commit is contained in:
Vladimir Gorej
2023-05-30 13:40:15 +02:00
committed by Vladimír Gorej
parent 3059a63a0a
commit ac3b69fb3c
6 changed files with 811 additions and 6 deletions

View File

@@ -20,6 +20,12 @@ import {
isOAS31 as isOAS31Fn,
createOnlyOAS31Selector as createOnlyOAS31SelectorFn,
createSystemSelector as createSystemSelectorFn,
wrapInferSchema,
wrapSampleFromSchema,
wrapSampleFromSchemaGeneric,
wrapCreateXMLExample,
wrapMemoizedSampleFromSchema,
wrapMemoizedCreateXMLExample,
} from "./fn"
import {
license as selectLicense,
@@ -82,6 +88,15 @@ const OAS31Plugin = ({ getSystem }) => {
getProperties,
}
}
// wraps schema generators and make them specific to OpenAPI version
if (typeof system.fn.inferSchema === "function") {
pluginFn.inferSchema = wrapInferSchema(getSystem)
pluginFn.sampleFromSchema = wrapSampleFromSchema(getSystem)
pluginFn.sampleFromSchemaGeneric = wrapSampleFromSchemaGeneric(getSystem)
pluginFn.createXMLExample = wrapCreateXMLExample(getSystem)
pluginFn.memoizedSampleFromSchema = wrapMemoizedSampleFromSchema(getSystem)
pluginFn.memoizedCreateXMLExample = wrapMemoizedCreateXMLExample(getSystem)
}
return {
fn: pluginFn,