fix(oas31): render responses with empty content field (#9664)
Refs #9199
This commit is contained in:
@@ -8,20 +8,16 @@ import { getKnownSyntaxHighlighterLanguage } from "core/utils/jsonParse"
|
|||||||
|
|
||||||
|
|
||||||
const getExampleComponent = ( sampleResponse, HighlightCode, getConfigs ) => {
|
const getExampleComponent = ( sampleResponse, HighlightCode, getConfigs ) => {
|
||||||
if (
|
if (sampleResponse == null) return null
|
||||||
sampleResponse !== undefined &&
|
|
||||||
sampleResponse !== null
|
const testValueForJson = getKnownSyntaxHighlighterLanguage(sampleResponse)
|
||||||
) {
|
const language = testValueForJson ? "json" : null
|
||||||
let language = null
|
|
||||||
let testValueForJson = getKnownSyntaxHighlighterLanguage(sampleResponse)
|
return (
|
||||||
if (testValueForJson) {
|
<div>
|
||||||
language = "json"
|
|
||||||
}
|
|
||||||
return <div>
|
|
||||||
<HighlightCode className="example" getConfigs={ getConfigs } language={ language } value={ stringify(sampleResponse) } />
|
<HighlightCode className="example" getConfigs={ getConfigs } language={ language } value={ stringify(sampleResponse) } />
|
||||||
</div>
|
</div>
|
||||||
}
|
)
|
||||||
return null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Response extends React.Component {
|
export default class Response extends React.Component {
|
||||||
@@ -171,7 +167,7 @@ export default class Response extends React.Component {
|
|||||||
shouldOverrideSchemaExample ? mediaTypeExample : undefined
|
shouldOverrideSchemaExample ? mediaTypeExample : undefined
|
||||||
)
|
)
|
||||||
|
|
||||||
let example = getExampleComponent( sampleResponse, HighlightCode, getConfigs )
|
const example = getExampleComponent( sampleResponse, HighlightCode, getConfigs )
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className={ "response " + ( className || "") } data-code={code}>
|
<tr className={ "response " + ( className || "") } data-code={code}>
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ export const sampleFromSchemaGeneric = (
|
|||||||
exampleOverride = undefined,
|
exampleOverride = undefined,
|
||||||
respectXML = false
|
respectXML = false
|
||||||
) => {
|
) => {
|
||||||
|
// there is nothing to generate schema from
|
||||||
|
if (schema == null && exampleOverride === undefined) return undefined
|
||||||
|
|
||||||
if (typeof schema?.toJS === "function") schema = schema.toJS()
|
if (typeof schema?.toJS === "function") schema = schema.toJS()
|
||||||
schema = typeCast(schema)
|
schema = typeCast(schema)
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ function afterLoad({ fn, getSystem }) {
|
|||||||
createXMLExample: fn.jsonSchema202012.createXMLExample,
|
createXMLExample: fn.jsonSchema202012.createXMLExample,
|
||||||
memoizedSampleFromSchema: fn.jsonSchema202012.memoizedSampleFromSchema,
|
memoizedSampleFromSchema: fn.jsonSchema202012.memoizedSampleFromSchema,
|
||||||
memoizedCreateXMLExample: fn.jsonSchema202012.memoizedCreateXMLExample,
|
memoizedCreateXMLExample: fn.jsonSchema202012.memoizedCreateXMLExample,
|
||||||
|
getJsonSampleSchema: fn.jsonSchema202012.getJsonSampleSchema,
|
||||||
|
getYamlSampleSchema: fn.jsonSchema202012.getYamlSampleSchema,
|
||||||
|
getXmlSampleSchema: fn.jsonSchema202012.getXmlSampleSchema,
|
||||||
|
getSampleSchema: fn.jsonSchema202012.getSampleSchema,
|
||||||
},
|
},
|
||||||
getSystem()
|
getSystem()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
|
||||||
|
describe("OpenAPI 3.1.0 response with empty content", () => {
|
||||||
|
it("should render a response", () => {
|
||||||
|
cy.visit(
|
||||||
|
"/?configUrl=/configs/oas31-response-no-content.yaml&url=/documents/features/oas31-response-empty-content.yaml"
|
||||||
|
)
|
||||||
|
.get("#operations-Enterprise-get_enterprise_detail")
|
||||||
|
.click()
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .response-col_description__inner"
|
||||||
|
)
|
||||||
|
.contains("No enterprise matching the requested ID could be found.")
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .model-example"
|
||||||
|
)
|
||||||
|
.should("not.exist")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
|
||||||
|
describe("OpenAPI 3.1.0 response with empty Media Type Object", () => {
|
||||||
|
it("should render a response", () => {
|
||||||
|
cy.visit(
|
||||||
|
"/?configUrl=/configs/oas31-response-no-content.yaml&url=/documents/features/oas31-response-empty-media-type.yaml"
|
||||||
|
)
|
||||||
|
.get("#operations-Enterprise-get_enterprise_detail")
|
||||||
|
.click()
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .response-col_description__inner"
|
||||||
|
)
|
||||||
|
.contains("No enterprise matching the requested ID could be found.")
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .model-example"
|
||||||
|
)
|
||||||
|
.should("not.exist")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
* @prettier
|
||||||
|
*/
|
||||||
|
|
||||||
|
describe("OpenAPI 3.1.0 response without content", () => {
|
||||||
|
it("should render a response", () => {
|
||||||
|
cy.visit(
|
||||||
|
"/?configUrl=/configs/oas31-response-no-content.yaml&url=/documents/features/oas31-response-no-content.yaml"
|
||||||
|
)
|
||||||
|
.get("#operations-Enterprise-get_enterprise_detail")
|
||||||
|
.click()
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .response-col_description__inner"
|
||||||
|
)
|
||||||
|
.contains("No enterprise matching the requested ID could be found.")
|
||||||
|
.get(
|
||||||
|
"#operations-Enterprise-get_enterprise_detail [data-code=404] .model-example"
|
||||||
|
)
|
||||||
|
.should("not.exist")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
defaultModelRendering: "model"
|
||||||
|
defaultModelExpandDepth: 0
|
||||||
|
defaultModelsExpandDepth: -1
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
openapi: '3.1.0'
|
||||||
|
|
||||||
|
info:
|
||||||
|
title: Our API
|
||||||
|
description: extended description of Our API
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
servers:
|
||||||
|
- url: http://localhost
|
||||||
|
description: included for completeness; not our actual url
|
||||||
|
|
||||||
|
tags:
|
||||||
|
- name: Enterprise
|
||||||
|
description: Operations with Enterprise ID
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/v0/enterprise/{id}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- Enterprise
|
||||||
|
summary: Get detailed info about an enterprise.
|
||||||
|
description: |
|
||||||
|
Returns detailed information for the specified Enterprise ID.
|
||||||
|
|
||||||
|
This operation may *only* be performed by a **platform admin** or a
|
||||||
|
client with sufficient permissions.
|
||||||
|
operationId: get_enterprise_detail
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/traceIDHeader'
|
||||||
|
- $ref: '#/components/parameters/enterpriseIDPath'
|
||||||
|
responses:
|
||||||
|
404:
|
||||||
|
description: No enterprise matching the requested ID could be found.
|
||||||
|
content: {}
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
enterpriseIDPath:
|
||||||
|
$ref: '#/components/parameters/idInPath'
|
||||||
|
description: The Enterprise ID used to perform this request.
|
||||||
|
example: "12422"
|
||||||
|
|
||||||
|
idInPath:
|
||||||
|
name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
traceIDHeader:
|
||||||
|
name: X-Trace-Id
|
||||||
|
in: header
|
||||||
|
description: Optional UUID for log tracing
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
schemas:
|
||||||
|
EnterpriseDetailResponse:
|
||||||
|
title: Enterprise Detail Response
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
description: Unique ID for this enterprise.
|
||||||
|
example: "3121"
|
||||||
|
mfa_enforced:
|
||||||
|
type: boolean
|
||||||
|
description: Indicates whether MFA is enforced for this enterprise.
|
||||||
|
example: true
|
||||||
|
modules:
|
||||||
|
type: array
|
||||||
|
description: List of modules this enterprise is authorized to access.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: [
|
||||||
|
human_resources,
|
||||||
|
project_management
|
||||||
|
]
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: The name of the enterprise.
|
||||||
|
example: Kathy's Plumbing
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Inidicates current status of this enterprise.
|
||||||
|
enum:
|
||||||
|
- offline
|
||||||
|
- online
|
||||||
|
- pending_deletion
|
||||||
|
- unknown
|
||||||
|
example: online
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
openapi: '3.1.0'
|
||||||
|
|
||||||
|
info:
|
||||||
|
title: Our API
|
||||||
|
description: extended description of Our API
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
servers:
|
||||||
|
- url: http://localhost
|
||||||
|
description: included for completeness; not our actual url
|
||||||
|
|
||||||
|
tags:
|
||||||
|
- name: Enterprise
|
||||||
|
description: Operations with Enterprise ID
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/v0/enterprise/{id}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- Enterprise
|
||||||
|
summary: Get detailed info about an enterprise.
|
||||||
|
description: |
|
||||||
|
Returns detailed information for the specified Enterprise ID.
|
||||||
|
|
||||||
|
This operation may *only* be performed by a **platform admin** or a
|
||||||
|
client with sufficient permissions.
|
||||||
|
operationId: get_enterprise_detail
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/traceIDHeader'
|
||||||
|
- $ref: '#/components/parameters/enterpriseIDPath'
|
||||||
|
responses:
|
||||||
|
404:
|
||||||
|
description: No enterprise matching the requested ID could be found.
|
||||||
|
content:
|
||||||
|
application/json: {}
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
enterpriseIDPath:
|
||||||
|
$ref: '#/components/parameters/idInPath'
|
||||||
|
description: The Enterprise ID used to perform this request.
|
||||||
|
example: "12422"
|
||||||
|
|
||||||
|
idInPath:
|
||||||
|
name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
traceIDHeader:
|
||||||
|
name: X-Trace-Id
|
||||||
|
in: header
|
||||||
|
description: Optional UUID for log tracing
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
schemas:
|
||||||
|
EnterpriseDetailResponse:
|
||||||
|
title: Enterprise Detail Response
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
description: Unique ID for this enterprise.
|
||||||
|
example: "3121"
|
||||||
|
mfa_enforced:
|
||||||
|
type: boolean
|
||||||
|
description: Indicates whether MFA is enforced for this enterprise.
|
||||||
|
example: true
|
||||||
|
modules:
|
||||||
|
type: array
|
||||||
|
description: List of modules this enterprise is authorized to access.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: [
|
||||||
|
human_resources,
|
||||||
|
project_management
|
||||||
|
]
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: The name of the enterprise.
|
||||||
|
example: Kathy's Plumbing
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Inidicates current status of this enterprise.
|
||||||
|
enum:
|
||||||
|
- offline
|
||||||
|
- online
|
||||||
|
- pending_deletion
|
||||||
|
- unknown
|
||||||
|
example: online
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
openapi: '3.1.0'
|
||||||
|
|
||||||
|
info:
|
||||||
|
title: Our API
|
||||||
|
description: extended description of Our API
|
||||||
|
version: 0.1.0
|
||||||
|
|
||||||
|
servers:
|
||||||
|
- url: http://localhost
|
||||||
|
description: included for completeness; not our actual url
|
||||||
|
|
||||||
|
tags:
|
||||||
|
- name: Enterprise
|
||||||
|
description: Operations with Enterprise ID
|
||||||
|
|
||||||
|
paths:
|
||||||
|
/v0/enterprise/{id}:
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- Enterprise
|
||||||
|
summary: Get detailed info about an enterprise.
|
||||||
|
description: |
|
||||||
|
Returns detailed information for the specified Enterprise ID.
|
||||||
|
|
||||||
|
This operation may *only* be performed by a **platform admin** or a
|
||||||
|
client with sufficient permissions.
|
||||||
|
operationId: get_enterprise_detail
|
||||||
|
parameters:
|
||||||
|
- $ref: '#/components/parameters/traceIDHeader'
|
||||||
|
- $ref: '#/components/parameters/enterpriseIDPath'
|
||||||
|
responses:
|
||||||
|
404:
|
||||||
|
description: No enterprise matching the requested ID could be found.
|
||||||
|
|
||||||
|
components:
|
||||||
|
parameters:
|
||||||
|
enterpriseIDPath:
|
||||||
|
$ref: '#/components/parameters/idInPath'
|
||||||
|
description: The Enterprise ID used to perform this request.
|
||||||
|
example: "12422"
|
||||||
|
|
||||||
|
idInPath:
|
||||||
|
name: id
|
||||||
|
in: path
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
traceIDHeader:
|
||||||
|
name: X-Trace-Id
|
||||||
|
in: header
|
||||||
|
description: Optional UUID for log tracing
|
||||||
|
required: false
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
|
||||||
|
schemas:
|
||||||
|
EnterpriseDetailResponse:
|
||||||
|
title: Enterprise Detail Response
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
type: string
|
||||||
|
description: Unique ID for this enterprise.
|
||||||
|
example: "3121"
|
||||||
|
mfa_enforced:
|
||||||
|
type: boolean
|
||||||
|
description: Indicates whether MFA is enforced for this enterprise.
|
||||||
|
example: true
|
||||||
|
modules:
|
||||||
|
type: array
|
||||||
|
description: List of modules this enterprise is authorized to access.
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
example: [
|
||||||
|
human_resources,
|
||||||
|
project_management
|
||||||
|
]
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
|
description: The name of the enterprise.
|
||||||
|
example: Kathy's Plumbing
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
description: Inidicates current status of this enterprise.
|
||||||
|
enum:
|
||||||
|
- offline
|
||||||
|
- online
|
||||||
|
- pending_deletion
|
||||||
|
- unknown
|
||||||
|
example: online
|
||||||
Reference in New Issue
Block a user