Skip to content

Commit

Permalink
ft: JsonSchema components are now ImmutableJS compliant (swagger-api#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
tim-lai authored and mattyb678 committed Jun 24, 2020
1 parent b5ae062 commit 796c900
Show file tree
Hide file tree
Showing 9 changed files with 1,508 additions and 113 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"hot-e2e-cypress-server": "webpack-dev-server --config webpack/dev-e2e.babel.js --content-base test/e2e-cypress/static",
"hot-e2e-selenium-server": "webpack-dev-server --config webpack/dev-e2e.babel.js --content-base test/e2e-selenium/static",
"e2e-cypress": "run-p -r hot-e2e-cypress-server mock-api test-e2e-cypress",
"dev-test-e2e-cypress-open": "cypress open",
"dev-e2e-cypress": "run-p -r hot-e2e-cypress-server mock-api dev-e2e-cypress-open",
"e2e-selenium": "run-p -r hot-e2e-selenium-server mock-api test-e2e-selenium",
"open-static": "node -e \"require('open')('http://localhost:3002')\"",
"security-audit": "run-s -sc security-audit:all security-audit:prod",
Expand Down
35 changes: 18 additions & 17 deletions src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}

Expand Down Expand Up @@ -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
Expand All @@ -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`
}

Expand All @@ -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")
) {
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
Loading

0 comments on commit 796c900

Please sign in to comment.