refactor: use samples plugin to generate schemas examples (#8728)

Refs #8577
This commit is contained in:
Vladimír Gorej
2023-05-30 15:26:50 +02:00
parent 027f53c302
commit 1ce9ce0cda
8 changed files with 22 additions and 98 deletions

View File

@@ -1,7 +1,6 @@
import React, { PureComponent } from "react"
import PropTypes from "prop-types"
import { fromJS, List } from "immutable"
import { getSampleSchema } from "core/utils"
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
const NOOP = Function.prototype
@@ -67,10 +66,10 @@ export default class ParamBody extends PureComponent {
}
sample = (xml) => {
let { param, fn:{inferSchema} } = this.props
let schema = inferSchema(param.toJS())
let { param, fn} = this.props
let schema = fn.inferSchema(param.toJS())
return getSampleSchema(schema, xml, {
return fn.getSampleSchema(schema, xml, {
includeWriteOnly: true
})
}

View File

@@ -3,7 +3,7 @@ import { Map, List } from "immutable"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import win from "core/window"
import { getSampleSchema, getExtensions, getCommonExtensions, numberToString, stringify, isEmptyValue } from "core/utils"
import { getExtensions, getCommonExtensions, numberToString, stringify, isEmptyValue } from "core/utils"
import getParameterSchema from "../../helpers/get-parameter-schema.js"
export default class ParameterRow extends Component {
@@ -94,7 +94,7 @@ export default class ParameterRow extends Component {
}
setDefaultValue = () => {
let { specSelectors, pathMethod, rawParam, oas3Selectors } = this.props
let { specSelectors, pathMethod, rawParam, oas3Selectors, fn } = this.props
const paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
const { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
@@ -104,7 +104,7 @@ export default class ParameterRow extends Component {
.first()
// getSampleSchema could return null
const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, {
const generatedSampleValue = schema ? fn.getSampleSchema(schema.toJS(), parameterMediaType, {
includeWriteOnly: true
}) : null

View File

@@ -3,7 +3,7 @@ import PropTypes from "prop-types"
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 { getExtensions, fromJSOrdered, stringify } from "core/utils"
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
@@ -93,7 +93,7 @@ export default class Response extends React.Component {
oas3Actions,
} = this.props
let { inferSchema } = fn
let { inferSchema, getSampleSchema } = fn
let isOAS3 = specSelectors.isOAS3()
const { showExtensions } = getConfigs()