Skip to content

Commit

Permalink
fix: avoid rendering empty response schemas (#9667)
Browse files Browse the repository at this point in the history
Refs #9666
Co-authored-by: Pierre Paysant-Le Roux <[email protected]>
  • Loading branch information
glowcloud authored Mar 6, 2024
1 parent e2be707 commit 32e7ce4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
6 changes: 5 additions & 1 deletion 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,6 +28,10 @@ export default class ModelExample extends React.Component {
activeTab = "example"
}

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

if(isExecute) {
activeTab = "example"
}
Expand Down
39 changes: 39 additions & 0 deletions test/e2e-cypress/e2e/features/default-model-rendering.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* @prettier
*/

describe("defaultModelRendering set to model", () => {
it("should not render schemas for responses with no defined schemas", () => {
cy.visit(
"/?defaultModelRendering=model&url=/documents/features/default-model-rendering.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"')
.should("exist")
.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"')
.should("exist")
.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")
.should("not.exist")
})
})
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 32e7ce4

Please sign in to comment.