improvement: urlencoded Request Body rendering (via #4823)
* use request body schema `required` for marking required urlencoded properties * don't use sample schema value as a fallback * modify property layout to mimic regular parameters * clean up * use default or example for iniital values
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
import React from "react"
|
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 { getSampleSchema } from "core/utils"
|
import { Map, OrderedMap, List } from "immutable"
|
||||||
import { Map, OrderedMap } from "immutable"
|
|
||||||
|
|
||||||
const RequestBody = ({
|
const RequestBody = ({
|
||||||
requestBody,
|
requestBody,
|
||||||
@@ -59,8 +58,8 @@ const RequestBody = ({
|
|||||||
|| contentType.indexOf("multipart/") === 0))
|
|| contentType.indexOf("multipart/") === 0))
|
||||||
{
|
{
|
||||||
const JsonSchemaForm = getComponent("JsonSchemaForm")
|
const JsonSchemaForm = getComponent("JsonSchemaForm")
|
||||||
const HighlightCode = getComponent("highlightCode")
|
const schemaForContentType = requestBody.getIn(["content", contentType, "schema"], OrderedMap())
|
||||||
const bodyProperties = requestBody.getIn(["content", contentType, "schema", "properties"], OrderedMap())
|
const bodyProperties = schemaForContentType.getIn([ "properties"], OrderedMap())
|
||||||
requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap()
|
requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap()
|
||||||
|
|
||||||
return <div className="table-container">
|
return <div className="table-container">
|
||||||
@@ -68,9 +67,11 @@ const RequestBody = ({
|
|||||||
<tbody>
|
<tbody>
|
||||||
{
|
{
|
||||||
bodyProperties.map((prop, key) => {
|
bodyProperties.map((prop, key) => {
|
||||||
const required = prop.get("required")
|
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 currentValue = requestBodyValue.get(key)
|
||||||
|
const initialValue = prop.get("default") || prop.get("example") || ""
|
||||||
|
|
||||||
const isFile = type === "string" && (format === "binary" || format === "base64")
|
const isFile = type === "string" && (format === "binary" || format === "base64")
|
||||||
|
|
||||||
@@ -89,18 +90,18 @@ const RequestBody = ({
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td className="col parameters-col_description">
|
<td className="col parameters-col_description">
|
||||||
{isExecute ?
|
{ prop.get("description") }
|
||||||
<JsonSchemaForm
|
{isExecute ? <div><JsonSchemaForm
|
||||||
fn={fn}
|
fn={fn}
|
||||||
dispatchInitialValue={!isFile}
|
dispatchInitialValue={!isFile}
|
||||||
schema={prop}
|
schema={prop}
|
||||||
|
description={key + " - " + prop.get("description")}
|
||||||
getComponent={getComponent}
|
getComponent={getComponent}
|
||||||
value={requestBodyValue.get(key) || getSampleSchema(prop)}
|
value={currentValue === undefined ? initialValue : currentValue}
|
||||||
onChange={(value) => {
|
onChange={(value) => {
|
||||||
onChange(value, [key])
|
onChange(value, [key])
|
||||||
}}
|
}}
|
||||||
/>
|
/></div> : null }
|
||||||
: <HighlightCode className="example" value={ getSampleSchema(prop) } />}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user