Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions src/core/plugins/oas3/components/request-body.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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")

Expand All @@ -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) => {
Expand Down