Skip to content

Commit 5eb23cd

Browse files
authored
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
1 parent b38203e commit 5eb23cd

File tree

9 files changed

+1508
-113
lines changed

9 files changed

+1508
-113
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"hot-e2e-cypress-server": "webpack-dev-server --config webpack/dev-e2e.babel.js --content-base test/e2e-cypress/static",
4040
"hot-e2e-selenium-server": "webpack-dev-server --config webpack/dev-e2e.babel.js --content-base test/e2e-selenium/static",
4141
"e2e-cypress": "run-p -r hot-e2e-cypress-server mock-api test-e2e-cypress",
42+
"dev-test-e2e-cypress-open": "cypress open",
43+
"dev-e2e-cypress": "run-p -r hot-e2e-cypress-server mock-api dev-e2e-cypress-open",
4244
"e2e-selenium": "run-p -r hot-e2e-selenium-server mock-api test-e2e-selenium",
4345
"open-static": "node -e \"require('open')('http://localhost:3002')\"",
4446
"security-audit": "run-s -sc security-audit:all security-audit:prod",

src/core/components/parameter-row.jsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default class ParameterRow extends Component {
4242

4343
if(isOAS3) {
4444
let { schema } = getParameterSchema(parameterWithMeta, { isOAS3 })
45-
enumValue = schema.get("enum")
45+
enumValue = schema ? schema.get("enum") : undefined
4646
} else {
4747
enumValue = parameterWithMeta ? parameterWithMeta.get("enum") : undefined
4848
}
@@ -59,7 +59,7 @@ export default class ParameterRow extends Component {
5959
if ( value !== undefined && value !== paramValue ) {
6060
this.onChangeWrapper(numberToString(value))
6161
}
62-
62+
// todo: could check if schema here; if not, do not call. impact?
6363
this.setDefaultValue()
6464
}
6565

@@ -97,17 +97,16 @@ export default class ParameterRow extends Component {
9797
let { specSelectors, pathMethod, rawParam, oas3Selectors } = this.props
9898

9999
const paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
100-
101100
const { schema } = getParameterSchema(paramWithMeta, { isOAS3: specSelectors.isOAS3() })
102-
103101
const parameterMediaType = paramWithMeta
104102
.get("content", Map())
105103
.keySeq()
106104
.first()
107105

108-
const generatedSampleValue = getSampleSchema(schema.toJS(), parameterMediaType, {
106+
// getSampleSchema could return null
107+
const generatedSampleValue = schema ? getSampleSchema(schema.toJS(), parameterMediaType, {
109108
includeWriteOnly: true
110-
})
109+
}) : null
111110

112111
if (!paramWithMeta || paramWithMeta.get("value") !== undefined) {
113112
return
@@ -121,14 +120,14 @@ export default class ParameterRow extends Component {
121120
if (specSelectors.isSwagger2()) {
122121
initialValue = paramWithMeta.get("x-example")
123122
|| paramWithMeta.getIn(["schema", "example"])
124-
|| schema.getIn(["default"])
123+
|| (schema && schema.getIn(["default"]))
125124
} else if (specSelectors.isOAS3()) {
126125
const currentExampleKey = oas3Selectors.activeExamplesMember(...pathMethod, "parameters", this.getParamKey())
127126
initialValue = paramWithMeta.getIn(["examples", currentExampleKey, "value"])
128127
|| paramWithMeta.getIn(["content", parameterMediaType, "example"])
129128
|| paramWithMeta.get("example")
130-
|| schema.get("example")
131-
|| schema.get("default")
129+
|| (schema && schema.get("example"))
130+
|| (schema && schema.get("default"))
132131
|| paramWithMeta.get("default") // ensures support for `parameterMacro`
133132
}
134133

@@ -144,7 +143,7 @@ export default class ParameterRow extends Component {
144143
if(initialValue !== undefined) {
145144
this.onChangeWrapper(initialValue)
146145
} else if(
147-
schema.get("type") === "object"
146+
schema && schema.get("type") === "object"
148147
&& generatedSampleValue
149148
&& !paramWithMeta.get("examples")
150149
) {
@@ -212,12 +211,12 @@ export default class ParameterRow extends Component {
212211
let { schema } = getParameterSchema(param, { isOAS3 })
213212
let paramWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam) || Map()
214213

215-
let format = schema.get("format")
216-
let type = schema.get("type")
214+
let format = schema ? schema.get("format") : null
215+
let type = schema ? schema.get("type") : null
216+
let itemType = schema ? schema.getIn(["items", "type"]) : null
217217
let isFormData = inType === "formData"
218218
let isFormDataSupported = "FormData" in win
219219
let required = param.get("required")
220-
let itemType = schema.getIn(["items", "type"])
221220

222221
let value = paramWithMeta ? paramWithMeta.get("value") : ""
223222
let commonExt = showCommonExtensions ? getCommonExtensions(schema) : null
@@ -229,24 +228,26 @@ export default class ParameterRow extends Component {
229228
let paramExample // undefined
230229
let isDisplayParamEnum = false
231230

232-
if ( param !== undefined ) {
231+
if ( param !== undefined && schema ) {
233232
paramItems = schema.get("items")
234233
}
235234

236235
if (paramItems !== undefined) {
237236
paramEnum = paramItems.get("enum")
238237
paramDefaultValue = paramItems.get("default")
239-
} else {
238+
} else if (schema) {
240239
paramEnum = schema.get("enum")
241240
}
242241

243-
if ( paramEnum !== undefined && paramEnum.size > 0) {
242+
if ( paramEnum && paramEnum.size && paramEnum.size > 0) {
244243
isDisplayParamEnum = true
245244
}
246245

247246
// Default and Example Value for readonly doc
248247
if ( param !== undefined ) {
249-
paramDefaultValue = schema.get("default")
248+
if (schema) {
249+
paramDefaultValue = schema.get("default")
250+
}
250251
if (paramDefaultValue === undefined) {
251252
paramDefaultValue = param.get("default")
252253
}

0 commit comments

Comments
 (0)