diff --git a/src/core/plugins/spec/actions.js b/src/core/plugins/spec/actions.js index c0cf5fa01c7..36811439ed8 100644 --- a/src/core/plugins/spec/actions.js +++ b/src/core/plugins/spec/actions.js @@ -1,7 +1,6 @@ import YAML, { JSON_SCHEMA } from "js-yaml" import { Map as ImmutableMap } from "immutable" import parseUrl from "url-parse" -import { serializeError } from "serialize-error" import isString from "lodash/isString" import debounce from "lodash/debounce" import set from "lodash/set" @@ -482,7 +481,7 @@ export const executeRequest = (req) => err.message = "**Failed to fetch.** \n**Possible Reasons:** \n - CORS \n - Network Failure \n - URL scheme must be \"http\" or \"https\" for CORS request." } specActions.setResponse(req.pathName, req.method, { - error: true, err: serializeError(err) + error: true, err }) } ) diff --git a/src/core/plugins/spec/reducers.js b/src/core/plugins/spec/reducers.js index ce1b4cf2828..5a664491a16 100644 --- a/src/core/plugins/spec/reducers.js +++ b/src/core/plugins/spec/reducers.js @@ -123,8 +123,8 @@ export default { let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) ) // ImmutableJS messes up Blob. Needs to reset its value. - if (win.Blob && res.data instanceof win.Blob) { - newState = newState.setIn( [ "responses", path, method, "text" ], res.data) + if (win.Blob && result.data instanceof win.Blob) { + newState = newState.setIn( [ "responses", path, method, "text" ], result.data) } return newState }, diff --git a/test/e2e-cypress/e2e/features/try-it-out-non-200-response-body.cy.js b/test/e2e-cypress/e2e/features/try-it-out-non-200-response-body.cy.js new file mode 100644 index 00000000000..4fbbd52eb05 --- /dev/null +++ b/test/e2e-cypress/e2e/features/try-it-out-non-200-response-body.cy.js @@ -0,0 +1,26 @@ +/** + * @prettier + */ +describe("#9556: SwaggerUI doesn't render response bodies for non-200 responses", () => { + beforeEach(() => { + const staticResponse = { + statusCode: 400, + headers: { "content-type": "plain/text" }, + body: "This should render", + } + cy.intercept("GET", "/400-any", staticResponse).as("request") + }) + + it("should render response body for a response with 400 status code", () => { + cy.visit("?url=/documents/features/try-it-out-non-200-response-body.yaml") + .get("#operations-default-get_400_any") + .click() + .get(".try-out__btn") + .click() + .get(".execute") + .click() + .wait("@request") + .get(".response-col_description .highlight-code .microlight") + .should("have.text", "This should render") + }) +}) diff --git a/test/e2e-cypress/static/documents/features/try-it-out-non-200-response-body.yaml b/test/e2e-cypress/static/documents/features/try-it-out-non-200-response-body.yaml new file mode 100644 index 00000000000..06d357ce714 --- /dev/null +++ b/test/e2e-cypress/static/documents/features/try-it-out-non-200-response-body.yaml @@ -0,0 +1,12 @@ +openapi: 3.0.0 +info: + version: 1.0.0 + title: Test API + description: Test API +paths: + /400-any: + get: + description: returns 400 + responses: + default: + description: ok