fix(spec): render response body for non-200 responses (#9555)
Refs #9556
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
import YAML, { JSON_SCHEMA } from "js-yaml"
|
import YAML, { JSON_SCHEMA } from "js-yaml"
|
||||||
import { Map as ImmutableMap } from "immutable"
|
import { Map as ImmutableMap } from "immutable"
|
||||||
import parseUrl from "url-parse"
|
import parseUrl from "url-parse"
|
||||||
import { serializeError } from "serialize-error"
|
|
||||||
import isString from "lodash/isString"
|
import isString from "lodash/isString"
|
||||||
import debounce from "lodash/debounce"
|
import debounce from "lodash/debounce"
|
||||||
import set from "lodash/set"
|
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."
|
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, {
|
specActions.setResponse(req.pathName, req.method, {
|
||||||
error: true, err: serializeError(err)
|
error: true, err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ export default {
|
|||||||
let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) )
|
let newState = state.setIn( [ "responses", path, method ], fromJSOrdered(result) )
|
||||||
|
|
||||||
// ImmutableJS messes up Blob. Needs to reset its value.
|
// ImmutableJS messes up Blob. Needs to reset its value.
|
||||||
if (win.Blob && res.data instanceof win.Blob) {
|
if (win.Blob && result.data instanceof win.Blob) {
|
||||||
newState = newState.setIn( [ "responses", path, method, "text" ], res.data)
|
newState = newState.setIn( [ "responses", path, method, "text" ], result.data)
|
||||||
}
|
}
|
||||||
return newState
|
return newState
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -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")
|
||||||
|
})
|
||||||
|
})
|
||||||
@@ -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
|
||||||
Reference in New Issue
Block a user