diff --git a/src/core/curlify.js b/src/core/curlify.js index a1385f5f35a..c12f18965a3 100644 --- a/src/core/curlify.js +++ b/src/core/curlify.js @@ -1,5 +1,19 @@ import win from "./window" +/** + * if duplicate key name existed from FormData entries, + * we mutated the key name by appending a hashIdx + * @param {String} k - possibly mutated key name + * @return {String} - src key name + */ +const extractKey = (k) => { + const hashIdx = "_**[]" + if (k.indexOf(hashIdx) < 0) { + return k + } + return k.split(hashIdx)[0].trim() +} + export default function curl( request ){ let curlified = [] let type = "" @@ -21,11 +35,12 @@ export default function curl( request ){ if(type === "multipart/form-data" && request.get("method") === "POST") { for( let [ k,v ] of request.get("body").entrySeq()) { + let extractedKey = extractKey(k) curlified.push( "-F" ) if (v instanceof win.File) { - curlified.push( `"${k}=@${v.name}${v.type ? `;type=${v.type}` : ""}"` ) + curlified.push(`"${extractedKey}=@${v.name}${v.type ? `;type=${v.type}` : ""}"` ) } else { - curlified.push( `"${k}=${v}"` ) + curlified.push(`"${extractedKey}=${v}"` ) } } } else { diff --git a/src/core/json-schema-components.jsx b/src/core/json-schema-components.jsx index 50a3b729f00..f44f0e933b7 100644 --- a/src/core/json-schema-components.jsx +++ b/src/core/json-schema-components.jsx @@ -47,6 +47,7 @@ export class JsonSchemaForm extends Component { let { schema, errors, value, onChange, getComponent, fn, disabled } = this.props const format = schema && schema.get ? schema.get("format") : null const type = schema && schema.get ? schema.get("type") : null + let getComponentSilently = (name) => getComponent(name, false, { failSilently: true }) let Comp = type ? format ? getComponentSilently(`JsonSchema_${type}_${format}`) : @@ -63,7 +64,7 @@ export class JsonSchema_string extends Component { static propTypes = JsonSchemaPropShape static defaultProps = JsonSchemaDefaultProps onChange = (e) => { - const value = this.props.schema && this.props.schema["type"] === "file" ? e.target.files[0] : e.target.value + const value = this.props.schema && this.props.schema.get("type") === "file" ? e.target.files[0] : e.target.value this.props.onChange(value, this.props.keyName) } onEnumChange = (val) => this.props.onChange(val) @@ -92,23 +93,27 @@ export class JsonSchema_string extends Component { const isDisabled = disabled || (schemaIn && schemaIn === "formData" && !("FormData" in window)) const Input = getComponent("Input") if (type && type === "file") { - return () + return ( + + ) } else { - return () + return ( + + ) } } } @@ -170,6 +175,7 @@ export class JsonSchema_array extends PureComponent { const schemaItemsSchema = schema.getIn(["items", "schema"]) let ArrayItemsComponent let isArrayItemText = false + let isArrayItemFile = schemaItemsType === "file" ? true : false if (schemaItemsType && schemaItemsFormat) { ArrayItemsComponent = getComponent(`JsonSchema_${schemaItemsType}_${schemaItemsFormat}`) } else if (schemaItemsType === "boolean" || schemaItemsType === "array" || schemaItemsType === "object") { @@ -177,7 +183,7 @@ export class JsonSchema_array extends PureComponent { } // if ArrayItemsComponent not assigned or does not exist, // use default schemaItemsType === "string" & JsonSchemaArrayItemText component - if (!ArrayItemsComponent) { + if (!ArrayItemsComponent && !isArrayItemFile) { isArrayItemText = true } @@ -205,22 +211,30 @@ export class JsonSchema_array extends PureComponent { return (
{ - isArrayItemText ? - this.onItemChange(val, i)} - disabled={disabled} - errors={errors} - /> - : this.onItemChange(val, i)} - disabled={disabled} - errors={errors} - schema={schemaItemsSchema} - getComponent={getComponent} - fn={fn} + isArrayItemFile ? + this.onItemChange(val, i)} + disabled={disabled} + errors={errors} + getComponent={getComponent} /> + : isArrayItemText ? + this.onItemChange(val, i)} + disabled={disabled} + errors={errors} + /> + : this.onItemChange(val, i)} + disabled={disabled} + errors={errors} + schema={schemaItemsSchema} + getComponent={getComponent} + fn={fn} + /> } {!disabled ? (