diff --git a/src/core/components/param-body.jsx b/src/core/components/param-body.jsx index a6097c76..d1b556f6 100644 --- a/src/core/components/param-body.jsx +++ b/src/core/components/param-body.jsx @@ -47,7 +47,7 @@ export default class ParamBody extends PureComponent { updateValues = (props) => { let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props - let parameter = specSelectors ? specSelectors.parameterWithMeta(pathMethod, param.get("name"), param.get("in")) : fromJS({}) + let parameter = (specSelectors ? specSelectors.parameterWithMeta(pathMethod, param.get("name"), param.get("in")) : fromJS({})) || param let isXml = /xml/i.test(consumesValue) let isJson = /json/i.test(consumesValue) let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value") diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index ae12fae9..3ec47a55 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -30,7 +30,7 @@ export default class ParameterRow extends Component { let { isOAS3 } = specSelectors let example = param.get("example") - let parameter = specSelectors.parameterWithMeta(pathMethod, param.get("name"), param.get("in")) + let parameter = specSelectors.parameterWithMeta(pathMethod, param.get("name"), param.get("in")) || param let enumValue if(isOAS3()) { @@ -156,7 +156,7 @@ export default class ParameterRow extends Component { } return ( - +
{ param.get("name") } diff --git a/src/core/json-schema-components.js b/src/core/json-schema-components.js index 8d7f3a3b..20ae40d5 100644 --- a/src/core/json-schema-components.js +++ b/src/core/json-schema-components.js @@ -34,6 +34,13 @@ export class JsonSchemaForm extends Component { static propTypes = JsonSchemaPropShape static defaultProps = JsonSchemaDefaultProps + componentDidMount() { + const { dispatchInitialValue, value, onChange } = this.props + if(dispatchInitialValue) { + onChange(value) + } + } + render() { let { schema, errors, value, onChange, getComponent, fn } = this.props diff --git a/src/core/plugins/oas3/components/request-body.jsx b/src/core/plugins/oas3/components/request-body.jsx index cf4a67bd..00defeb3 100644 --- a/src/core/plugins/oas3/components/request-body.jsx +++ b/src/core/plugins/oas3/components/request-body.jsx @@ -1,10 +1,12 @@ import React from "react" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" -import { OrderedMap } from "immutable" +import { getSampleSchema } from "core/utils" +import Im, { Map, OrderedMap, List } from "immutable" const RequestBody = ({ requestBody, + requestBodyValue, getComponent, getConfigs, specSelectors, @@ -13,6 +15,10 @@ const RequestBody = ({ specPath, onChange }) => { + const handleFile = (e) => { + onChange(e.target.files[0]) + } + const Markdown = getComponent("Markdown") const ModelExample = getComponent("modelExample") const RequestBodyEditor = getComponent("RequestBodyEditor") @@ -23,10 +29,80 @@ const RequestBody = ({ const mediaTypeValue = requestBodyContent.get(contentType) + const isObjectContent = mediaTypeValue.getIn(["schema", "type"]) === "object" + if(!mediaTypeValue) { return null } + if(contentType === "application/octet-stream") { + const Input = getComponent("Input") + + if(!isExecute) { + return + Example values are not available for application/octet-stream media types. + + } + + return + } + + if( + isObjectContent && + (contentType === "application/x-www-form-urlencoded" + || contentType.indexOf("multipart/") === 0)) + { + const JsonSchemaForm = getComponent("JsonSchemaForm") + const HighlightCode = getComponent("highlightCode") + const bodyProperties = requestBody.getIn(["content", contentType, "schema", "properties"], OrderedMap()) + requestBodyValue = Map.isMap(requestBodyValue) ? requestBodyValue : OrderedMap() + + return
+ + + { + bodyProperties.map((prop, key) => { + const required = prop.get("required") + const type = prop.get("type") + const format = prop.get("format") + + const isFile = type === "string" && (format === "binary" || format === "base64") + + return + + + + }) + } + +
+
+ { key } + { !required ? null :  * } +
+
+ { type } + { format && (${format})} +
+
+ { prop.get("deprecated") ? "deprecated": null } +
+
+ {isExecute ? + { + onChange(value, [key]) + }} + /> + : } +
+
+ } + return
{ requestBodyDescription && @@ -53,6 +129,7 @@ const RequestBody = ({ RequestBody.propTypes = { requestBody: ImPropTypes.orderedMap.isRequired, + requestBodyValue: ImPropTypes.orderedMap.isRequired, getComponent: PropTypes.func.isRequired, getConfigs: PropTypes.func.isRequired, specSelectors: PropTypes.object.isRequired, diff --git a/src/core/plugins/oas3/wrap-components/index.js b/src/core/plugins/oas3/wrap-components/index.js index 910dcf29..fd0c99f5 100644 --- a/src/core/plugins/oas3/wrap-components/index.js +++ b/src/core/plugins/oas3/wrap-components/index.js @@ -4,11 +4,13 @@ import parameters from "./parameters" import VersionStamp from "./version-stamp" import OnlineValidatorBadge from "./online-validator-badge" import Model from "./model" +import JsonSchema_string from "./json-schema-string" export default { Markdown, AuthItem, parameters, + JsonSchema_string, VersionStamp, model: Model, onlineValidatorBadge: OnlineValidatorBadge, diff --git a/src/core/plugins/oas3/wrap-components/json-schema-string.js b/src/core/plugins/oas3/wrap-components/json-schema-string.js new file mode 100644 index 00000000..ceec8521 --- /dev/null +++ b/src/core/plugins/oas3/wrap-components/json-schema-string.js @@ -0,0 +1,26 @@ +import React from "react" +import { OAS3ComponentWrapFactory } from "../helpers" + +export default OAS3ComponentWrapFactory(({ Ori, ...props }) => { + const { + schema, + getComponent, + errors, + onChange + } = props + + const { type, format } = schema + const Input = getComponent("Input") + + if(type === "string" && (format === "binary" || format === "base64")) { + return { + onChange(e.target.files[0]) + }} + disabled={Ori.isDisabled}/> + } else { + return + } +}) diff --git a/src/core/plugins/oas3/wrap-components/parameters.jsx b/src/core/plugins/oas3/wrap-components/parameters.jsx index b1457086..31b70f7f 100644 --- a/src/core/plugins/oas3/wrap-components/parameters.jsx +++ b/src/core/plugins/oas3/wrap-components/parameters.jsx @@ -185,8 +185,17 @@ class Parameters extends Component { { + onChange={(value, path) => { + if(path) { + const lastValue = oas3Selectors.requestBodyValue(...pathMethod) + const usableValue = Map.isMap(lastValue) ? lastValue : Map() + return oas3Actions.setRequestBodyValue({ + pathMethod, + value: usableValue.setIn(path, value) + }) + } oas3Actions.setRequestBodyValue({ value, pathMethod }) }} contentType={oas3Selectors.requestContentType(...pathMethod)}/> diff --git a/src/core/plugins/spec/actions.js b/src/core/plugins/spec/actions.js index 9bd9908c..d35e09e5 100644 --- a/src/core/plugins/spec/actions.js +++ b/src/core/plugins/spec/actions.js @@ -348,7 +348,9 @@ export const executeRequest = (req) => if(isJSONObject(requestBody)) { req.requestBody = JSON.parse(requestBody) - } else { + } else if(requestBody && requestBody.toJS) { + req.requestBody = requestBody.toJS() + } else{ req.requestBody = requestBody } }