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