diff --git a/src/core/components/model-example.jsx b/src/core/components/model-example.jsx index 54c726c84fc..721ebc9fa2b 100644 --- a/src/core/components/model-example.jsx +++ b/src/core/components/model-example.jsx @@ -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 @@ -28,7 +28,7 @@ export default class ModelExample extends React.Component { activeTab = "example" } - if(isExecute) { + if(isExecute || !schema) { activeTab = "example" } @@ -114,7 +114,7 @@ export default class ModelExample extends React.Component { )} - {this.state.activeTab === "model" && ( + {schema && this.state.activeTab === "model" && (
) : null} - { example || schema ? ( + { hasContent && (example || schema) ? ( { + 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"') + }) +}) diff --git a/test/e2e-cypress/static/configs/default-model-rendering-model.yaml b/test/e2e-cypress/static/configs/default-model-rendering-model.yaml new file mode 100644 index 00000000000..c227d2054d8 --- /dev/null +++ b/test/e2e-cypress/static/configs/default-model-rendering-model.yaml @@ -0,0 +1 @@ +defaultModelRendering: model \ No newline at end of file diff --git a/test/e2e-cypress/static/documents/bugs/oas31-empty-response.yaml b/test/e2e-cypress/static/documents/bugs/oas31-empty-response.yaml new file mode 100644 index 00000000000..573ec3530e6 --- /dev/null +++ b/test/e2e-cypress/static/documents/bugs/oas31-empty-response.yaml @@ -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: {} \ No newline at end of file