Skip to content

Commit

Permalink
fix(spec): render response body for non-200 responses (#9555)
Browse files Browse the repository at this point in the history
Refs #9556
  • Loading branch information
glowcloud authored Feb 7, 2024
1 parent 6362bc3 commit a88bed5
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/core/plugins/spec/actions.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
})
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/core/plugins/spec/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
})
})
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a88bed5

Please sign in to comment.