fix(components): add support for oneOf/anyOf JSON Schema keywords in parameter-row rendering (#9934)

Refs #7912
This commit is contained in:
Oliwia Rogala
2024-05-14 11:54:44 +02:00
committed by GitHub
parent dcc87aaca6
commit 9037acf508
6 changed files with 170 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import React, { Component } from "react"
import { Map, List } from "immutable"
import { Map, List, fromJS } from "immutable"
import PropTypes from "prop-types"
import ImPropTypes from "react-immutable-proptypes"
import win from "core/window"
@@ -97,7 +97,7 @@ export default class ParameterRow extends Component {
let { specSelectors, pathMethod, rawParam, oas3Selectors, fn } = this.props
const paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
const { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
let { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
const parameterMediaType = paramWithMeta
.get("content", Map())
.keySeq()
@@ -126,6 +126,8 @@ export default class ParameterRow extends Component {
? paramWithMeta.getIn(["schema", "example"])
: (schema && schema.getIn(["default"]))
} else if (specSelectors.isOAS3()) {
schema = this.composeJsonSchema(schema)
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
initialValue =
paramWithMeta.getIn(["examples", currentExampleKey, "value"]) !== undefined
@@ -181,6 +183,13 @@ export default class ParameterRow extends Component {
return `${param.get("name")}-${param.get("in")}`
}
composeJsonSchema(schema) {
const { fn } = this.props
const oneOf = schema.get("oneOf")?.get(0)?.toJS()
const anyOf = schema.get("anyOf")?.get(0)?.toJS()
return fromJS(fn.mergeJsonSchema(schema.toJS(), oneOf ?? anyOf ?? {}))
}
render() {
let {param, rawParam, getComponent, getConfigs, isExecute, fn, onChangeConsumes, specSelectors, pathMethod, specPath, oas3Selectors} = this.props
@@ -222,6 +231,10 @@ export default class ParameterRow extends Component {
let { schema } = getParameterSchema(param, { isOAS3 })
let paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
if (isOAS3) {
schema = this.composeJsonSchema(schema)
}
let format = schema ? schema.get("format") : null
let type = schema ? schema.get("type") : null
let itemType = schema ? schema.getIn(["items", "type"]) : null