feat: sample-gen mulit and form media-type (#6874)
* application/x-www-form-urlencoded || **multipart/** initial value should rely on sample gen
This commit is contained in:
@@ -129,8 +129,9 @@ export class JsonSchema_array extends PureComponent {
|
||||
}
|
||||
|
||||
componentWillReceiveProps(props) {
|
||||
if(props.value !== this.state.value)
|
||||
this.setState({ value: props.value })
|
||||
const value = valueOrEmptyList(props.value)
|
||||
if(value !== this.state.value)
|
||||
this.setState({ value })
|
||||
|
||||
if(props.schema !== this.state.schema)
|
||||
this.setState({ schema: props.schema })
|
||||
@@ -382,5 +383,5 @@ export class JsonSchema_object extends PureComponent {
|
||||
}
|
||||
|
||||
function valueOrEmptyList(value) {
|
||||
return List.isList(value) ? value : List()
|
||||
return List.isList(value) ? value : Array.isArray(value) ? fromJS(value) : List()
|
||||
}
|
||||
|
||||
@@ -143,22 +143,23 @@ const RequestBody = ({
|
||||
const description = prop.get("description")
|
||||
const currentValue = requestBodyValue.getIn([key, "value"])
|
||||
const currentErrors = requestBodyValue.getIn([key, "errors"]) || requestBodyErrors
|
||||
|
||||
let initialValue = prop.get("default") || prop.get("example") || ""
|
||||
|
||||
if (initialValue === "") {
|
||||
if(type === "object") {
|
||||
const included = requestBodyInclusionSetting.get(key) || false
|
||||
let hasNonEmptyInitialVal = prop.has("default") || prop.has("example") || prop.hasIn(["items", "example"]) || prop.hasIn(["items", "default"]) || prop.has("enum") && prop.get("enum").size === 1
|
||||
let initialValue = ""
|
||||
if(type === "array" && !hasNonEmptyInitialVal) {
|
||||
initialValue = []
|
||||
} else if (hasNonEmptyInitialVal) {
|
||||
// TODO: what about example or examples from requestBody could be passed as exampleOverride
|
||||
initialValue = getSampleSchema(prop, false, {
|
||||
includeWriteOnly: true
|
||||
})
|
||||
} else if(type === "array") {
|
||||
initialValue = []
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof initialValue !== "string" && type === "object") {
|
||||
initialValue = stringify(initialValue)
|
||||
}
|
||||
if (typeof initialValue === "string" && type === "array") {
|
||||
initialValue = JSON.parse(initialValue)
|
||||
}
|
||||
|
||||
const isFile = type === "string" && (format === "binary" || format === "base64")
|
||||
|
||||
@@ -196,7 +197,7 @@ const RequestBody = ({
|
||||
{required ? null : (
|
||||
<ParameterIncludeEmpty
|
||||
onChange={(value) => onChangeIncludeEmpty(key, value)}
|
||||
isIncluded={requestBodyInclusionSetting.get(key) || false}
|
||||
isIncluded={included}
|
||||
isIncludedOptions={setIsIncludedOptions(key)}
|
||||
isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user