improve: multipart + formencoded rendering (via #4910)
This commit is contained in:
@@ -2,6 +2,7 @@ import React from "react"
|
||||
import PropTypes from "prop-types"
|
||||
import ImPropTypes from "react-immutable-proptypes"
|
||||
import { Map, OrderedMap, List } from "immutable"
|
||||
import { getCommonExtensions, getSampleSchema } from "core/utils"
|
||||
|
||||
const RequestBody = ({
|
||||
requestBody,
|
||||
@@ -23,6 +24,8 @@ const RequestBody = ({
|
||||
const ModelExample = getComponent("modelExample")
|
||||
const RequestBodyEditor = getComponent("RequestBodyEditor")
|
||||
|
||||
const { showCommonExtensions } = getConfigs()
|
||||
|
||||
const requestBodyDescription = (requestBody && requestBody.get("description")) || null
|
||||
const requestBodyContent = (requestBody && requestBody.get("content")) || new OrderedMap()
|
||||
contentType = contentType || requestBodyContent.keySeq().first()
|
||||
@@ -58,6 +61,7 @@ const RequestBody = ({
|
||||
|| contentType.indexOf("multipart/") === 0))
|
||||
{
|
||||
const JsonSchemaForm = getComponent("JsonSchemaForm")
|
||||
const ParameterExt = getComponent("ParameterExt")
|
||||
const schemaForContentType = requestBody.getIn(["content", contentType, "schema"], OrderedMap())
|
||||
const bodyProperties = schemaForContentType.getIn([ "properties"], OrderedMap())
|
||||
requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap()
|
||||
@@ -67,11 +71,20 @@ const RequestBody = ({
|
||||
<tbody>
|
||||
{
|
||||
bodyProperties.map((prop, key) => {
|
||||
let commonExt = showCommonExtensions ? getCommonExtensions(prop) : null
|
||||
const required = schemaForContentType.get("required", List()).includes(key)
|
||||
const type = prop.get("type")
|
||||
const format = prop.get("format")
|
||||
const description = prop.get("description")
|
||||
const currentValue = requestBodyValue.get(key)
|
||||
const initialValue = prop.get("default") || prop.get("example") || ""
|
||||
|
||||
let initialValue = prop.get("default") || prop.get("example") || ""
|
||||
|
||||
if(initialValue === "" && type === "object") {
|
||||
initialValue = getSampleSchema(prop, false, {
|
||||
includeWriteOnly: true
|
||||
})
|
||||
}
|
||||
|
||||
const isFile = type === "string" && (format === "binary" || format === "base64")
|
||||
|
||||
@@ -84,18 +97,19 @@ const RequestBody = ({
|
||||
<div className="parameter__type">
|
||||
{ type }
|
||||
{ format && <span className="prop-format">(${format})</span>}
|
||||
{!showCommonExtensions || !commonExt.size ? null : commonExt.map((v, key) => <ParameterExt key={`${key}-${v}`} xKey={key} xVal={v} />)}
|
||||
</div>
|
||||
<div className="parameter__deprecated">
|
||||
{ prop.get("deprecated") ? "deprecated": null }
|
||||
</div>
|
||||
</td>
|
||||
<td className="col parameters-col_description">
|
||||
{ prop.get("description") }
|
||||
{ description }
|
||||
{isExecute ? <div><JsonSchemaForm
|
||||
fn={fn}
|
||||
dispatchInitialValue={!isFile}
|
||||
schema={prop}
|
||||
description={key + " - " + prop.get("description")}
|
||||
description={key}
|
||||
getComponent={getComponent}
|
||||
value={currentValue === undefined ? initialValue : currentValue}
|
||||
onChange={(value) => {
|
||||
|
||||
Reference in New Issue
Block a user