fix: handle urlencoded array data correctly + don't stringify non-object sample values (#4704)
* fix: handle urlencoded array data correctly * fix: don't stringify non-object sample values * fix linter
This commit is contained in:
@@ -111,7 +111,7 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
|
|
||||||
constructor(props, context) {
|
constructor(props, context) {
|
||||||
super(props, context)
|
super(props, context)
|
||||||
this.state = {value: props.value}
|
this.state = { value: valueOrEmptyList(props.value)}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(props) {
|
componentWillReceiveProps(props) {
|
||||||
@@ -135,7 +135,7 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
|
|
||||||
addItem = () => {
|
addItem = () => {
|
||||||
this.setState(state => {
|
this.setState(state => {
|
||||||
state.value = state.value || List()
|
state.value = valueOrEmptyList(state.value)
|
||||||
return {
|
return {
|
||||||
value: state.value.push("")
|
value: state.value.push("")
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{ !value || value.count() < 1 ? null :
|
{ !value || !value.count || value.count() < 1 ? null :
|
||||||
value.map( (item,i) => {
|
value.map( (item,i) => {
|
||||||
let schema = Object.assign({}, itemSchema)
|
let schema = Object.assign({}, itemSchema)
|
||||||
if ( errors.length ) {
|
if ( errors.length ) {
|
||||||
@@ -264,3 +264,7 @@ export class JsonSchema_object extends PureComponent {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function valueOrEmptyList(value) {
|
||||||
|
return List.isList(value) ? value : List()
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ const RequestBody = ({
|
|||||||
getComponent,
|
getComponent,
|
||||||
getConfigs,
|
getConfigs,
|
||||||
specSelectors,
|
specSelectors,
|
||||||
|
fn,
|
||||||
contentType,
|
contentType,
|
||||||
isExecute,
|
isExecute,
|
||||||
specPath,
|
specPath,
|
||||||
@@ -85,6 +86,7 @@ const RequestBody = ({
|
|||||||
<td className="col parameters-col_description">
|
<td className="col parameters-col_description">
|
||||||
{isExecute ?
|
{isExecute ?
|
||||||
<JsonSchemaForm
|
<JsonSchemaForm
|
||||||
|
fn={fn}
|
||||||
dispatchInitialValue={!isFile}
|
dispatchInitialValue={!isFile}
|
||||||
schema={prop}
|
schema={prop}
|
||||||
getComponent={getComponent}
|
getComponent={getComponent}
|
||||||
@@ -132,6 +134,7 @@ RequestBody.propTypes = {
|
|||||||
requestBodyValue: ImPropTypes.orderedMap.isRequired,
|
requestBodyValue: ImPropTypes.orderedMap.isRequired,
|
||||||
getComponent: PropTypes.func.isRequired,
|
getComponent: PropTypes.func.isRequired,
|
||||||
getConfigs: PropTypes.func.isRequired,
|
getConfigs: PropTypes.func.isRequired,
|
||||||
|
fn: PropTypes.object.isRequired,
|
||||||
specSelectors: PropTypes.object.isRequired,
|
specSelectors: PropTypes.object.isRequired,
|
||||||
contentType: PropTypes.string,
|
contentType: PropTypes.string,
|
||||||
isExecute: PropTypes.bool.isRequired,
|
isExecute: PropTypes.bool.isRequired,
|
||||||
|
|||||||
@@ -628,7 +628,9 @@ export const getSampleSchema = (schema, contentType="", config={}) => {
|
|||||||
return memoizedCreateXMLExample(schema, config)
|
return memoizedCreateXMLExample(schema, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
return JSON.stringify(memoizedSampleFromSchema(schema, config), null, 2)
|
const res = memoizedSampleFromSchema(schema, config)
|
||||||
|
|
||||||
|
return typeof res === "object" ? JSON.stringify(res, null, 2) : res
|
||||||
}
|
}
|
||||||
|
|
||||||
export const parseSearch = () => {
|
export const parseSearch = () => {
|
||||||
|
|||||||
@@ -3,3 +3,4 @@ env:
|
|||||||
rules:
|
rules:
|
||||||
"react/prop-types": 1 # bah humbug
|
"react/prop-types": 1 # bah humbug
|
||||||
"no-unused-vars": 1 # unused vars in tests can be useful for indicating a full signature
|
"no-unused-vars": 1 # unused vars in tests can be useful for indicating a full signature
|
||||||
|
"no-global-assign": 1
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ import {
|
|||||||
getCommonExtensions,
|
getCommonExtensions,
|
||||||
sanitizeUrl,
|
sanitizeUrl,
|
||||||
extractFileNameFromContentDispositionHeader,
|
extractFileNameFromContentDispositionHeader,
|
||||||
deeplyStripKey
|
deeplyStripKey,
|
||||||
|
getSampleSchema
|
||||||
} from "core/utils"
|
} from "core/utils"
|
||||||
import win from "core/window"
|
import win from "core/window"
|
||||||
|
|
||||||
@@ -1186,5 +1187,30 @@ describe("utils", function() {
|
|||||||
expect(sanitizeUrl({})).toEqual("")
|
expect(sanitizeUrl({})).toEqual("")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
describe("getSampleSchema", function() {
|
||||||
|
const oriDate = Date
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
Date = function () {
|
||||||
|
this.toISOString = function () {
|
||||||
|
return "2018-07-07T07:07:05.189Z"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
Date = oriDate
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not unnecessarily stringify non-object values", function() {
|
||||||
|
// Given
|
||||||
|
const res = getSampleSchema({
|
||||||
|
type: "string",
|
||||||
|
format: "date-time"
|
||||||
|
})
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(res).toEqual(new Date().toISOString())
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user