Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid rendering empty response schemas #9667

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
char0n marked this conversation as resolved.
Show resolved Hide resolved
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: {}