ft: JsonSchema components are now ImmutableJS compliant (#5952)

bug: JsonSchema components should validate schema properties exists
  - schema
  - type
  - format
  - enum
bug: fix a debounce error in JsonSchema_string if value is null
ft: new simplified JsonSchemaArrayItemText component
test: use immutableJS for `json-schema-form` test
test: add dev scripts to run `cypress open`
test: new cypress `schema-form` tests
This commit is contained in:
Tim Lai
2020-05-06 13:57:58 -07:00
committed by GitHub
parent b38203e21a
commit 5eb23cdd48
9 changed files with 1508 additions and 113 deletions

View File

@@ -42,7 +42,7 @@ export default class ParameterRow extends Component {
if(isOAS3) {
let { schema } = getParameterSchema(parameterWithMeta, { isOAS3 })
enumValue = schema.get("enum")
enumValue = schema ? schema.get("enum") : undefined
} else {
enumValue = parameterWithMeta ? parameterWithMeta.get("enum") : undefined
}
@@ -59,7 +59,7 @@ export default class ParameterRow extends Component {
if ( value !== undefined && value !== paramValue ) {
this.onChangeWrapper(numberToString(value))
}
// todo: could check if schema here; if not, do not call. impact?
this.setDefaultValue()
}
@@ -97,17 +97,16 @@ export default class ParameterRow extends Component {
let { specSelectors, pathMethod, rawParam, oas3Selectors } = this.props
const paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
const { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
const parameterMediaType = paramWithMeta
.get("content", Map())
.keySeq()
.first()
const generatedSampleValue = getSampleSchema(schema.toJS(), parameterMediaType, {
// getSampleSchema could return null
const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, {
includeWriteOnly: true
})
}) : null
if (!paramWithMeta || paramWithMeta.get("value") !== undefined) {
return
@@ -121,14 +120,14 @@ export default class ParameterRow extends Component {
if (specSelectors.isSwagger2()) {
initialValue = paramWithMeta.get("x-example")
|| paramWithMeta.getIn(["schema", "example"])
|| schema.getIn(["default"])
|| (schema && schema.getIn(["default"]))
} else if (specSelectors.isOAS3()) {
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
initialValue = paramWithMeta.getIn(["examples", currentExampleKey, "value"])
|| paramWithMeta.getIn(["content", parameterMediaType, "example"])
|| paramWithMeta.get("example")
|| schema.get("example")
|| schema.get("default")
|| (schema && schema.get("example"))
|| (schema && schema.get("default"))
|| paramWithMeta.get("default") // ensures support for `parameterMacro`
}
@@ -144,7 +143,7 @@ export default class ParameterRow extends Component {
if(initialValue !== undefined) {
this.onChangeWrapper(initialValue)
} else if(
schema.get("type") === "object"
schema && schema.get("type") === "object"
&& generatedSampleValue
&& !paramWithMeta.get("examples")
) {
@@ -212,12 +211,12 @@ export default class ParameterRow extends Component {
let { schema } = getParameterSchema(param, { isOAS3 })
let paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
let format = schema.get("format")
let type = schema.get("type")
let format = schema ? schema.get("format") : null
let type = schema ? schema.get("type") : null
let itemType = schema ? schema.getIn(["items", "type"]) : null
let isFormData = inType === "formData"
let isFormDataSupported = "FormData" in win
let required = param.get("required")
let itemType = schema.getIn(["items", "type"])
let value = paramWithMeta ? paramWithMeta.get("value") : ""
let commonExt = showCommonExtensions ? getCommonExtensions(schema) : null
@@ -229,24 +228,26 @@ export default class ParameterRow extends Component {
let paramExample // undefined
let isDisplayParamEnum = false
if ( param !== undefined ) {
if ( param !== undefined && schema ) {
paramItems = schema.get("items")
}
if (paramItems !== undefined) {
paramEnum = paramItems.get("enum")
paramDefaultValue = paramItems.get("default")
} else {
} else if (schema) {
paramEnum = schema.get("enum")
}
if ( paramEnum !== undefined && paramEnum.size > 0) {
if ( paramEnum && paramEnum.size && paramEnum.size > 0) {
isDisplayParamEnum = true
}
// Default and Example Value for readonly doc
if ( param !== undefined ) {
paramDefaultValue = schema.get("default")
if (schema) {
paramDefaultValue = schema.get("default")
}
if (paramDefaultValue === undefined) {
paramDefaultValue = param.get("default")
}