From d9ad9a0efb73821984fd384ac59b408160268ec2 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 28 Sep 2018 19:20:00 -0500 Subject: [PATCH] improve: multipart + formencoded rendering --- .../plugins/oas3/components/request-body.jsx | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index 44ed5be8618..a5411b1dcac 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -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 = ({ { 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 = ({
{ type } { format && (${format})} + {!showCommonExtensions || !commonExt.size ? null : commonExt.map((v, key) => )}
{ prop.get("deprecated") ? "deprecated": null }
- { prop.get("description") } + { description } {isExecute ?
{