From 708a96dcab1eb46c9c50fb55be83537516f67e31 Mon Sep 17 00:00:00 2001 From: kyle Date: Fri, 17 Aug 2018 18:00:06 -0700 Subject: [PATCH] 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 --- .../plugins/oas3/components/request-body.jsx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index fb0baab2..27b7bd5b 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -1,8 +1,7 @@ import React from "react" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" -import { getSampleSchema } from "core/utils" -import { Map, OrderedMap } from "immutable" +import { Map, OrderedMap, List } from "immutable" const RequestBody = ({ requestBody, @@ -59,8 +58,8 @@ const RequestBody = ({ || contentType.indexOf("multipart/") === 0)) { const JsonSchemaForm = getComponent("JsonSchemaForm") - const HighlightCode = getComponent("highlightCode") - const bodyProperties = requestBody.getIn(["content", contentType, "schema", "properties"], OrderedMap()) + const schemaForContentType = requestBody.getIn(["content", contentType, "schema"], OrderedMap()) + const bodyProperties = schemaForContentType.getIn([ "properties"], OrderedMap()) requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap() return
@@ -68,9 +67,11 @@ const RequestBody = ({ { bodyProperties.map((prop, key) => { - const required = prop.get("required") + const required = schemaForContentType.get("required", List()).includes(key) const type = prop.get("type") 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") @@ -89,18 +90,18 @@ const RequestBody = ({
- {isExecute ? - { onChange(value, [key]) }} - /> - : } + /> : null } })