Skip to content

Commit a88bed5

Browse files
authored
fix(spec): render response body for non-200 responses (#9555)
Refs #9556
1 parent 6362bc3 commit a88bed5

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

src/core/plugins/spec/actions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import YAML, { JSON_SCHEMA } from "js-yaml"
22
import { Map as ImmutableMap } from "immutable"
33
import parseUrl from "url-parse"
4-
import { serializeError } from "serialize-error"
54
import isString from "lodash/isString"
65
import debounce from "lodash/debounce"
76
import set from "lodash/set"
@@ -482,7 +481,7 @@ export const executeRequest = (req) =>
482481
err.message = "**Failed to fetch.** \n**Possible Reasons:** \n - CORS \n - Network Failure \n - URL scheme must be \"http\" or \"https\" for CORS request."
483482
}
484483
specActions.setResponse(req.pathName, req.method, {
485-
error: true, err: serializeError(err)
484+
error: true, err
486485
})
487486
}
488487
)

src/core/plugins/spec/reducers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ export default {
123123
let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) )
124124

125125
// ImmutableJS messes up Blob. Needs to reset its value.
126-
if (win.Blob && res.data instanceof win.Blob) {
127-
newState = newState.setIn( [ "responses", path, method, "text" ], res.data)
126+
if (win.Blob && result.data instanceof win.Blob) {
127+
newState = newState.setIn( [ "responses", path, method, "text" ], result.data)
128128
}
129129
return newState
130130
},
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* @prettier
3+
*/
4+
describe("#9556: SwaggerUI doesn't render response bodies for non-200 responses", () => {
5+
beforeEach(() => {
6+
const staticResponse = {
7+
statusCode: 400,
8+
headers: { "content-type": "plain/text" },
9+
body: "This should render",
10+
}
11+
cy.intercept("GET", "/400-any", staticResponse).as("request")
12+
})
13+
14+
it("should render response body for a response with 400 status code", () => {
15+
cy.visit("?url=/documents/features/try-it-out-non-200-response-body.yaml")
16+
.get("#operations-default-get_400_any")
17+
.click()
18+
.get(".try-out__btn")
19+
.click()
20+
.get(".execute")
21+
.click()
22+
.wait("@request")
23+
.get(".response-col_description .highlight-code .microlight")
24+
.should("have.text", "This should render")
25+
})
26+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: 3.0.0
2+
info:
3+
version: 1.0.0
4+
title: Test API
5+
description: Test API
6+
paths:
7+
/400-any:
8+
get:
9+
description: returns 400
10+
responses:
11+
default:
12+
description: ok

0 commit comments

Comments
 (0)