fix: gracefully handle empty request bodies (via #4859)

This commit is contained in:
kyle
2018-09-07 16:18:13 -07:00
committed by GitHub
parent eb6c43405f
commit 54276c95e2
4 changed files with 27 additions and 4 deletions

View File

@@ -29,12 +29,12 @@ const RequestBody = ({
const mediaTypeValue = requestBodyContent.get(contentType) const mediaTypeValue = requestBodyContent.get(contentType)
const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object"
if(!mediaTypeValue) { if(!mediaTypeValue) {
return null return null
} }
const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object"
if( if(
contentType === "application/octet-stream" contentType === "application/octet-stream"
|| contentType.indexOf("image/") === 0 || contentType.indexOf("image/") === 0

View File

@@ -1,6 +1,6 @@
import React, { Component } from "react" import React, { Component } from "react"
import PropTypes from "prop-types" import PropTypes from "prop-types"
import Im, { Map } from "immutable" import Im, { Map, List } from "immutable"
import ImPropTypes from "react-immutable-proptypes" import ImPropTypes from "react-immutable-proptypes"
import { OAS3ComponentWrapFactory } from "../helpers" import { OAS3ComponentWrapFactory } from "../helpers"
@@ -177,7 +177,7 @@ class Parameters extends Component {
<label> <label>
<ContentType <ContentType
value={oas3Selectors.requestContentType(...pathMethod)} value={oas3Selectors.requestContentType(...pathMethod)}
contentTypes={ requestBody.get("content").keySeq() } contentTypes={ requestBody.get("content", List()).keySeq() }
onChange={(value) => { onChange={(value) => {
oas3Actions.setRequestContentType({ value, pathMethod }) oas3Actions.setRequestContentType({ value, pathMethod })
}} }}

View File

@@ -0,0 +1,12 @@
openapi: "3.0.0"
paths:
/some/route:
post:
description: This should be visible
tags:
- Some
requestBody: {}
responses:
'200':
description: Description

View File

@@ -0,0 +1,11 @@
import repeat from "lodash/repeat"
describe("#4838: empty request bodies result in endless loading", () => {
it("should render model content changes correctly", () => {
cy
.visit("/?url=/documents/bugs/4838.yaml")
.get("#operations-Some-post_some_route")
.click()
.contains("This should be visible")
})
})