Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(spec): render response body for non-200 responses #9555

Merged
merged 5 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading