Skip to content

Commit 54276c9

Browse files
authored
fix: gracefully handle empty request bodies (via #4859)
1 parent eb6c434 commit 54276c9

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

src/core/plugins/oas3/components/request-body.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ const RequestBody = ({
2929

3030
const mediaTypeValue = requestBodyContent.get(contentType)
3131

32-
const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object"
33-
3432
if(!mediaTypeValue) {
3533
return null
3634
}
3735

36+
const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object"
37+
3838
if(
3939
contentType === "application/octet-stream"
4040
|| contentType.indexOf("image/") === 0

src/core/plugins/oas3/wrap-components/parameters.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react"
22
import PropTypes from "prop-types"
3-
import Im, { Map } from "immutable"
3+
import Im, { Map, List } from "immutable"
44
import ImPropTypes from "react-immutable-proptypes"
55
import { OAS3ComponentWrapFactory } from "../helpers"
66

@@ -177,7 +177,7 @@ class Parameters extends Component {
177177
<label>
178178
<ContentType
179179
value={oas3Selectors.requestContentType(...pathMethod)}
180-
contentTypes={ requestBody.get("content").keySeq() }
180+
contentTypes={ requestBody.get("content", List()).keySeq() }
181181
onChange={(value) => {
182182
oas3Actions.setRequestContentType({ value, pathMethod })
183183
}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: "3.0.0"
2+
3+
paths:
4+
/some/route:
5+
post:
6+
description: This should be visible
7+
tags:
8+
- Some
9+
requestBody: {}
10+
responses:
11+
'200':
12+
description: Description
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import repeat from "lodash/repeat"
2+
3+
describe("#4838: empty request bodies result in endless loading", () => {
4+
it("should render model content changes correctly", () => {
5+
cy
6+
.visit("/?url=/documents/bugs/4838.yaml")
7+
.get("#operations-Some-post_some_route")
8+
.click()
9+
.contains("This should be visible")
10+
})
11+
})

0 commit comments

Comments
 (0)