feat(json-schema): expose API that generates examples from JSON Schema (#9190)

This allows to use the samples API in a static way
without fully instantiating SwaggerUI.

Refs #9188
This commit is contained in:
Vladimír Gorej
2023-09-05 14:13:53 +02:00
committed by GitHub
parent edd1153723
commit 113996f627
83 changed files with 292 additions and 88 deletions

View File

@@ -0,0 +1,30 @@
/**
* @prettier
*/
const makeGetSampleSchema =
(getSystem) =>
(schema, contentType = "", config = {}, exampleOverride = undefined) => {
const { fn } = getSystem()
if (typeof schema?.toJS === "function") {
schema = schema.toJS()
}
if (typeof exampleOverride?.toJS === "function") {
exampleOverride = exampleOverride.toJS()
}
if (/xml/.test(contentType)) {
return fn.getXmlSampleSchema(schema, config, exampleOverride)
}
if (/(yaml|yml)/.test(contentType)) {
return fn.getYamlSampleSchema(
schema,
config,
contentType,
exampleOverride
)
}
return fn.getJsonSampleSchema(schema, config, contentType, exampleOverride)
}
export default makeGetSampleSchema