Skip to content

Commit

Permalink
fix: oas31 response rendering
Browse files Browse the repository at this point in the history
Refs #9199
  • Loading branch information
pplr committed Dec 21, 2023
1 parent f846f8f commit de43af7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/components/model-example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class ModelExample extends React.Component {

constructor(props, context) {
super(props, context)
let { getConfigs, isExecute } = this.props
let { getConfigs, isExecute, schema } = this.props
let { defaultModelRendering } = getConfigs()

let activeTab = defaultModelRendering
Expand All @@ -28,7 +28,7 @@ export default class ModelExample extends React.Component {
activeTab = "example"
}

if(isExecute) {
if(isExecute || !schema) {
activeTab = "example"
}

Expand Down Expand Up @@ -114,7 +114,7 @@ export default class ModelExample extends React.Component {
</div>
)}

{this.state.activeTab === "model" && (
{schema && this.state.activeTab === "model" && (
<div
aria-hidden={this.state.activeTab === "example"}
aria-labelledby={modelTabId}
Expand Down
3 changes: 2 additions & 1 deletion src/core/components/response.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default class Response extends React.Component {
const activeContentType = this.state.responseContentType || contentType
const activeMediaType = response.getIn(["content", activeContentType], Map({}))
const examplesForMediaType = activeMediaType.get("examples", null)
const hasContent = !isOAS3 || response.get("content")

// Goal: find a schema value for `schema`
if(isOAS3) {
Expand Down Expand Up @@ -235,7 +236,7 @@ export default class Response extends React.Component {
</section>
) : null}

{ example || schema ? (
{ hasContent && (example || schema) ? (
<ModelExample
specPath={specPathWithPossibleSchema}
getComponent={ getComponent }
Expand Down
25 changes: 25 additions & 0 deletions test/e2e-cypress/e2e/bugs/oas31-empty-response.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe("OAS 3.1 Empty response", () => {
it("should not render an example for empty reponse", () => {
cy.visit(
"/?configUrl=/configs/default-model-rendering-model.yaml&url=/documents/bugs/oas31-empty-response.yaml"
)
.get("#operations-default-get_")
.click()
.get("#operations-default-get_ [data-code=200] .response-col_description__inner")
.contains("no content")
.get("#operations-default-get_ [data-code=200] .model-example")
.should("not.exist")
.get("#operations-default-get_ [data-code=201] .response-col_description__inner")
.contains("no schema but an example")
.get("#operations-default-get_ [data-code=201] .model-example")
.contains('"foo": "bar"')
.get("#operations-default-get_ [data-code=202] .response-col_description__inner")
.contains("no schema but examples")
.get("#operations-default-get_ [data-code=202] .model-example")
.contains('"foo": "bar"')
.get("#operations-default-get_ [data-code=203] .response-col_description__inner")
.contains("no schema no example")
.get("#operations-default-get_ [data-code=203] .model-example")
.contains('"string"')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
defaultModelRendering: model
31 changes: 31 additions & 0 deletions test/e2e-cypress/static/documents/bugs/oas31-empty-response.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
openapi: 3.1.0
info:
title: Empty response test case
version: '1'
paths:
'/':
get:
responses:
'200':
description: no content
'201':
description: no schema but an example
content:
application/json:
example:
foo: bar
'202':
description: no schema but examples
content:
application/json:
examples:
first:
value:
foo: bar
second:
value:
baz: foobar
'203':
description: no schema no example
content:
application/json: {}

0 comments on commit de43af7

Please sign in to comment.