Skip to content

Commit 288c89b

Browse files
mathis-mtim-lai
andauthored
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 <[email protected]>
1 parent 64ae7af commit 288c89b

File tree

8 files changed

+478
-218
lines changed

8 files changed

+478
-218
lines changed

src/core/components/response.jsx

+7-23
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ImPropTypes from "react-immutable-proptypes"
44
import cx from "classnames"
55
import { fromJS, Seq, Iterable, List, Map } from "immutable"
66
import { getExtensions, getSampleSchema, fromJSOrdered, stringify } from "core/utils"
7-
import { isFunc } from "../utils"
7+
88

99
const getExampleComponent = ( sampleResponse, HighlightCode, getConfigs ) => {
1010
if (
@@ -121,21 +121,6 @@ export default class Response extends React.Component {
121121
specPathWithPossibleSchema = response.has("schema") ? specPath.push("schema") : specPath
122122
}
123123

124-
const overrideSchemaExample = (oldSchema, newExample) => {
125-
if(newExample === undefined)
126-
return oldSchema
127-
128-
if(!oldSchema)
129-
oldSchema = { }
130-
131-
if(isFunc(oldSchema.toJS))
132-
oldSchema = oldSchema.toJS()
133-
134-
oldSchema.example = newExample && isFunc(newExample.toJS)
135-
? newExample.toJS()
136-
: newExample
137-
return oldSchema
138-
}
139124
let mediaTypeExample
140125
let shouldOverrideSchemaExample = false
141126
let sampleSchema
@@ -170,13 +155,12 @@ export default class Response extends React.Component {
170155
}
171156
}
172157

173-
const schemaForSampleGeneration = shouldOverrideSchemaExample
174-
? overrideSchemaExample(sampleSchema, mediaTypeExample)
175-
: sampleSchema
176-
177-
const sampleResponse = schemaForSampleGeneration
178-
? getSampleSchema(schemaForSampleGeneration, activeContentType, sampleGenConfig)
179-
: null
158+
const sampleResponse = getSampleSchema(
159+
sampleSchema,
160+
activeContentType,
161+
sampleGenConfig,
162+
shouldOverrideSchemaExample ? mediaTypeExample : undefined
163+
)
180164

181165
let example = getExampleComponent( sampleResponse, HighlightCode, getConfigs )
182166

0 commit comments

Comments
 (0)