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) {
|
componentWillReceiveProps(props) {
|
||||||
if(props.value !== this.state.value)
|
const value = valueOrEmptyList(props.value)
|
||||||
this.setState({ value: props.value })
|
if(value !== this.state.value)
|
||||||
|
this.setState({ value })
|
||||||
|
|
||||||
if(props.schema !== this.state.schema)
|
if(props.schema !== this.state.schema)
|
||||||
this.setState({ schema: props.schema })
|
this.setState({ schema: props.schema })
|
||||||
@@ -382,5 +383,5 @@ export class JsonSchema_object extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function valueOrEmptyList(value) {
|
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 description = prop.get("description")
|
||||||
const currentValue = requestBodyValue.getIn([key, "value"])
|
const currentValue = requestBodyValue.getIn([key, "value"])
|
||||||
const currentErrors = requestBodyValue.getIn([key, "errors"]) || requestBodyErrors
|
const currentErrors = requestBodyValue.getIn([key, "errors"]) || requestBodyErrors
|
||||||
|
const included = requestBodyInclusionSetting.get(key) || false
|
||||||
let initialValue = prop.get("default") || prop.get("example") || ""
|
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 (initialValue === "") {
|
if(type === "array" && !hasNonEmptyInitialVal) {
|
||||||
if(type === "object") {
|
initialValue = []
|
||||||
|
} else if (hasNonEmptyInitialVal) {
|
||||||
|
// TODO: what about example or examples from requestBody could be passed as exampleOverride
|
||||||
initialValue = getSampleSchema(prop, false, {
|
initialValue = getSampleSchema(prop, false, {
|
||||||
includeWriteOnly: true
|
includeWriteOnly: true
|
||||||
})
|
})
|
||||||
} else if(type === "array") {
|
|
||||||
initialValue = []
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof initialValue !== "string" && type === "object") {
|
if (typeof initialValue !== "string" && type === "object") {
|
||||||
initialValue = stringify(initialValue)
|
initialValue = stringify(initialValue)
|
||||||
}
|
}
|
||||||
|
if (typeof initialValue === "string" && type === "array") {
|
||||||
|
initialValue = JSON.parse(initialValue)
|
||||||
|
}
|
||||||
|
|
||||||
const isFile = type === "string" && (format === "binary" || format === "base64")
|
const isFile = type === "string" && (format === "binary" || format === "base64")
|
||||||
|
|
||||||
@@ -196,7 +197,7 @@ const RequestBody = ({
|
|||||||
{required ? null : (
|
{required ? null : (
|
||||||
<ParameterIncludeEmpty
|
<ParameterIncludeEmpty
|
||||||
onChange={(value) => onChangeIncludeEmpty(key, value)}
|
onChange={(value) => onChangeIncludeEmpty(key, value)}
|
||||||
isIncluded={requestBodyInclusionSetting.get(key) || false}
|
isIncluded={included}
|
||||||
isIncludedOptions={setIsIncludedOptions(key)}
|
isIncludedOptions={setIsIncludedOptions(key)}
|
||||||
isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)}
|
isDisabled={Array.isArray(currentValue) ? currentValue.length !== 0 : !isEmptyValue(currentValue)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user