Skip to content

Commit

Permalink
fix(schema example): xml gen should follow json gen behavior (#6555)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
mathis-m and tim-lai authored Nov 3, 2020
1 parent 64ae7af commit 288c89b
Show file tree
Hide file tree
Showing 8 changed files with 478 additions and 218 deletions.
30 changes: 7 additions & 23 deletions src/core/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 )

Expand Down
Loading

0 comments on commit 288c89b

Please sign in to comment.