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:
@@ -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 )
|
||||
|
||||
|
||||
Reference in New Issue
Block a user