Example (#4730)
* add tests for example feature * refactor ParameterRow value setter logic * aside: fix property access in sampleFromSchema * prioritize media type examples for OAS3 responses * use `example` in schema level example * refactor: move stringify to utils * prioritize media type examples in OAS3 request bodies * modify nightwatch config * fix parameter/response regressions * reorder and broaden default value sources * update lockfile
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import { fromJS } from "immutable"
|
||||
import { getSampleSchema } from "core/utils"
|
||||
import { getSampleSchema, stringify } from "core/utils"
|
||||
|
||||
const NOOP = Function.prototype
|
||||
|
||||
@@ -67,9 +67,11 @@ export default class RequestBodyEditor extends PureComponent {
|
||||
|
||||
sample = (explicitMediaType) => {
|
||||
let { requestBody, mediaType } = this.props
|
||||
let schema = requestBody.getIn(["content", explicitMediaType || mediaType, "schema"]).toJS()
|
||||
let mediaTypeValue = requestBody.getIn(["content", explicitMediaType || mediaType])
|
||||
let schema = mediaTypeValue.get("schema").toJS()
|
||||
let mediaTypeExample = mediaTypeValue.get("example") !== undefined ? stringify(mediaTypeValue.get("example")) : null
|
||||
|
||||
return getSampleSchema(schema, explicitMediaType || mediaType, {
|
||||
return mediaTypeExample || getSampleSchema(schema, explicitMediaType || mediaType, {
|
||||
includeWriteOnly: true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -52,10 +52,10 @@ export const sampleFromSchema = (schema, config={}) => {
|
||||
let props = objectify(properties)
|
||||
let obj = {}
|
||||
for (var name in props) {
|
||||
if ( props[name].readOnly && !includeReadOnly ) {
|
||||
if ( props[name] && props[name].readOnly && !includeReadOnly ) {
|
||||
continue
|
||||
}
|
||||
if ( props[name].writeOnly && !includeWriteOnly ) {
|
||||
if ( props[name] && props[name].writeOnly && !includeWriteOnly ) {
|
||||
continue
|
||||
}
|
||||
obj[name] = sampleFromSchema(props[name], config)
|
||||
|
||||
Reference in New Issue
Block a user