From c1ffd9ee08baf6b63c8978666148fe0ce82b7ec6 Mon Sep 17 00:00:00 2001 From: Owen Conti Date: Thu, 6 Jul 2017 19:54:10 -0600 Subject: [PATCH] Fixes #3271 - Only trim parameter values if the parameter's content type is JSON. Change default value of parameter inputs to be '{}' only if the parameter's content type is JSON --- src/core/components/param-body.jsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/components/param-body.jsx b/src/core/components/param-body.jsx index 7de6766b..e64a65cc 100644 --- a/src/core/components/param-body.jsx +++ b/src/core/components/param-body.jsx @@ -49,10 +49,11 @@ export default class ParamBody extends PureComponent { let { specSelectors, pathMethod, param, isExecute, consumesValue="" } = props let parameter = specSelectors ? specSelectors.getParameter(pathMethod, param.get("name")) : {} let isXml = /xml/i.test(consumesValue) + let isJson = /json/i.test(consumesValue) let paramValue = isXml ? parameter.get("value_xml") : parameter.get("value") if ( paramValue !== undefined ) { - let val = !paramValue && !isXml ? "{}" : paramValue + let val = !paramValue && isJson ? "{}" : paramValue this.setState({ value: val }) this.onChange(val, {isXml: isXml, isEditBox: isExecute}) } else { @@ -79,8 +80,11 @@ export default class ParamBody extends PureComponent { _onChange = (val, isXml) => { (this.props.onChange || NOOP)(this.props.param, val, isXml) } handleOnChange = e => { - let {consumesValue} = this.props - this.onChange(e.target.value.trim(), {isXml: /xml/i.test(consumesValue)}) + const {consumesValue} = this.props + const isJson = /json/i.test(consumesValue) + const isXml = /xml/i.test(consumesValue) + const inputValue = isJson ? e.target.value.trim() : e.target.value + this.onChange(inputValue, {isXml}) } toggleIsEditBox = () => this.setState( state => ({isEditBox: !state.isEditBox}))