From d02b0526060680499956903a85f454023fb1b5b6 Mon Sep 17 00:00:00 2001 From: Pierre Paysant-Le Roux Date: Thu, 21 Dec 2023 17:05:41 +0100 Subject: [PATCH] fix: oas31 response rendering Refs #9199 --- src/core/components/model-example.jsx | 6 ++-- src/core/components/response.jsx | 3 +- .../e2e/bugs/oas31-empty-response.cy.js | 25 +++++++++++++++ .../default-model-rendering-model.yaml | 1 + .../documents/bugs/oas31-empty-response.yaml | 31 +++++++++++++++++++ 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 test/e2e-cypress/e2e/bugs/oas31-empty-response.cy.js create mode 100644 test/e2e-cypress/static/configs/default-model-rendering-model.yaml create mode 100644 test/e2e-cypress/static/documents/bugs/oas31-empty-response.yaml 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