fix(schema example): xml gen should follow json gen behavior (#6555)

* ref: #6470 
* fixes: #6540
* fixes: #4943 

* add example override option to json
* add example override option to xml
* added basic oneOf and anyOf support
* fix anyof|oneof
* only lift xml to items


Co-authored-by: Tim Lai <timothy.lai@gmail.com>
This commit is contained in:
Mahtis Michel
2020-11-03 19:58:59 +01:00
committed by GitHub
parent 64ae7af565
commit 288c89bdbb
8 changed files with 488 additions and 228 deletions

View File

@@ -4,7 +4,7 @@ import ImPropTypes from "react-immutable-proptypes"
import cx from "classnames"
import { fromJS, Seq, Iterable, List, Map } from "immutable"
import { getExtensions, getSampleSchema, fromJSOrdered, stringify } from "core/utils"
import { isFunc } from "../utils"
const getExampleComponent = ( sampleResponse, HighlightCode, getConfigs ) => {
if (
@@ -121,21 +121,6 @@ export default class Response extends React.Component {
specPathWithPossibleSchema = response.has("schema") ? specPath.push("schema") : specPath
}
const overrideSchemaExample = (oldSchema, newExample) => {
if(newExample === undefined)
return oldSchema
if(!oldSchema)
oldSchema = { }
if(isFunc(oldSchema.toJS))
oldSchema = oldSchema.toJS()
oldSchema.example = newExample && isFunc(newExample.toJS)
? newExample.toJS()
: newExample
return oldSchema
}
let mediaTypeExample
let shouldOverrideSchemaExample = false
let sampleSchema
@@ -170,13 +155,12 @@ export default class Response extends React.Component {
}
}
const schemaForSampleGeneration = shouldOverrideSchemaExample
? overrideSchemaExample(sampleSchema, mediaTypeExample)
: sampleSchema
const sampleResponse = schemaForSampleGeneration
? getSampleSchema(schemaForSampleGeneration, activeContentType, sampleGenConfig)
: null
const sampleResponse = getSampleSchema(
sampleSchema,
activeContentType,
sampleGenConfig,
shouldOverrideSchemaExample ? mediaTypeExample : undefined
)
let example = getExampleComponent( sampleResponse, HighlightCode, getConfigs )