fix: provide JSON editor for x-www-form-urlencoded bodies lacking properties (via #5180)

This commit is contained in:
kyle
2019-02-13 18:47:01 -06:00
committed by GitHub
parent 3f0c0666ba
commit 373da3bee3
5 changed files with 102 additions and 9 deletions

View File

@@ -30,7 +30,8 @@ const RequestBody = ({
const requestBodyContent = (requestBody && requestBody.get("content")) || new OrderedMap()
contentType = contentType || requestBodyContent.keySeq().first()
const mediaTypeValue = requestBodyContent.get(contentType)
const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap())
const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap())
if(!mediaTypeValue) {
return null
@@ -55,15 +56,17 @@ const RequestBody = ({
return <Input type={"file"} onChange={handleFile} />
}
if(
if (
isObjectContent &&
(contentType === "application/x-www-form-urlencoded"
|| contentType.indexOf("multipart/") === 0))
{
(
contentType === "application/x-www-form-urlencoded" ||
contentType.indexOf("multipart/") === 0
) &&
schemaForMediaType.get("properties", OrderedMap()).size > 0
) {
const JsonSchemaForm = getComponent("JsonSchemaForm")
const ParameterExt = getComponent("ParameterExt")
const schemaForContentType = requestBody.getIn(["content", contentType, "schema"], OrderedMap())
const bodyProperties = schemaForContentType.getIn([ "properties"], OrderedMap())
const bodyProperties = schemaForMediaType.get("properties", OrderedMap())
requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap()
return <div className="table-container">
@@ -75,7 +78,7 @@ const RequestBody = ({
{
bodyProperties.map((prop, key) => {
let commonExt = showCommonExtensions ? getCommonExtensions(prop) : null
const required = schemaForContentType.get("required", List()).includes(key)
const required = schemaForMediaType.get("required", List()).includes(key)
const type = prop.get("type")
const format = prop.get("format")
const description = prop.get("description")

View File

@@ -171,7 +171,7 @@ class Parameters extends Component {
</div> : "" }
{
isOAS3() && requestBody && this.state.parametersVisible &&
<div className="opblock-section">
<div className="opblock-section opblock-section-request-body">
<div className="opblock-section-header">
<h4 className={`opblock-title parameter__name ${requestBody.get("required") && "required"}`}>Request body</h4>
<label>