fix(oas3): add support for oneOf/anyOf JSON Schema keywords in request-body rendering (#9767)
Refs #9763
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React from "react"
|
import React from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import ImPropTypes from "react-immutable-proptypes"
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
import { Map, OrderedMap, List } from "immutable"
|
import { Map, OrderedMap, List, fromJS } from "immutable"
|
||||||
import { getCommonExtensions, stringify, isEmptyValue } from "core/utils"
|
import { getCommonExtensions, stringify, isEmptyValue } from "core/utils"
|
||||||
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
|
import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
|
||||||
|
|
||||||
@@ -153,24 +153,9 @@ const RequestBody = ({
|
|||||||
Map.isMap(bodyProperties) && bodyProperties.entrySeq().map(([key, schema]) => {
|
Map.isMap(bodyProperties) && bodyProperties.entrySeq().map(([key, schema]) => {
|
||||||
if (schema.get("readOnly")) return
|
if (schema.get("readOnly")) return
|
||||||
|
|
||||||
const schemaWithoutKeywords = schema.filter((v, k) => k !== "oneOf"
|
const oneOf = schema.get("oneOf")?.get(0)?.toJS()
|
||||||
&& k !== "anyOf"
|
const anyOf = schema.get("anyOf")?.get(0)?.toJS()
|
||||||
&& k !== "$$ref"
|
schema = fromJS(fn.mergeJsonSchema(schema.toJS(), oneOf ?? anyOf ?? {}))
|
||||||
)
|
|
||||||
|
|
||||||
if (schemaWithoutKeywords.size === 0) {
|
|
||||||
const oneOf = schema.get("oneOf")
|
|
||||||
const anyOf = schema.get("anyOf")
|
|
||||||
const nestedSchema = List.isList(oneOf)
|
|
||||||
? oneOf.get(0)
|
|
||||||
: List.isList(anyOf)
|
|
||||||
? anyOf.get(0)
|
|
||||||
: null
|
|
||||||
|
|
||||||
if (Map.isMap(nestedSchema)) {
|
|
||||||
schema = nestedSchema
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let commonExt = showCommonExtensions ? getCommonExtensions(schema) : null
|
let commonExt = showCommonExtensions ? getCommonExtensions(schema) : null
|
||||||
const required = schemaForMediaType.get("required", List()).includes(key)
|
const required = schemaForMediaType.get("required", List()).includes(key)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ describe("OpenAPI 3.0 oneOf and anyOf example", () => {
|
|||||||
.get(".try-out__btn")
|
.get(".try-out__btn")
|
||||||
.click()
|
.click()
|
||||||
.get("textarea")
|
.get("textarea")
|
||||||
.contains("documentDate")
|
.contains("NestedSchemaExample.pdf")
|
||||||
.should("exist")
|
.should("exist")
|
||||||
cy.contains("/documentsWithCombineOneOf").click()
|
cy.contains("/documentsWithCombineOneOf").click()
|
||||||
cy.contains("/documentsWithCombineAnyOf")
|
cy.contains("/documentsWithCombineAnyOf")
|
||||||
@@ -20,7 +20,7 @@ describe("OpenAPI 3.0 oneOf and anyOf example", () => {
|
|||||||
.contains("Try it out")
|
.contains("Try it out")
|
||||||
.click()
|
.click()
|
||||||
.get("textarea")
|
.get("textarea")
|
||||||
.contains("documentDate")
|
.contains("ParentSchemaExample.pdf")
|
||||||
.should("exist")
|
.should("exist")
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
default: ''
|
default: ''
|
||||||
maxLength: 64
|
maxLength: 64
|
||||||
example: MyDocument.pdf'
|
example: NestedSchemaExample.pdf'
|
||||||
category:
|
category:
|
||||||
type: string
|
type: string
|
||||||
pattern: ''
|
pattern: ''
|
||||||
@@ -172,6 +172,15 @@ components:
|
|||||||
- $ref: '#/components/schemas/ModelPostDocumentPolicy'
|
- $ref: '#/components/schemas/ModelPostDocumentPolicy'
|
||||||
- $ref: '#/components/schemas/ModelPostDocumentCustomer'
|
- $ref: '#/components/schemas/ModelPostDocumentCustomer'
|
||||||
- $ref: '#/components/schemas/ModelPostDocumentInvoice'
|
- $ref: '#/components/schemas/ModelPostDocumentInvoice'
|
||||||
|
example:
|
||||||
|
title: ParentSchemaExample.pdf
|
||||||
|
category: Policy
|
||||||
|
type: Policy
|
||||||
|
issuingApplicationId: App1
|
||||||
|
documentDate: '2021-01-01'
|
||||||
|
sharedWith:
|
||||||
|
- CustomerPortal
|
||||||
|
policyNumber: '132456'
|
||||||
ModelPostDocumentAnyOfCombineModelFile:
|
ModelPostDocumentAnyOfCombineModelFile:
|
||||||
allOf:
|
allOf:
|
||||||
- $ref: '#/components/schemas/ModelFile'
|
- $ref: '#/components/schemas/ModelFile'
|
||||||
|
|||||||
Reference in New Issue
Block a user