fix(try-it-out): pass Parameter validation messages around in props for OAS3 (#4162)
* default to empty `ImmutableMap` when grabbing op metadata * pass `errors` into JsonSchema components * Account for Immutable data structure in JavaScriptonSchema... ...and create empty Lists instead of Maps by default. * Pass ImmutableList through to JsonSchema child components
This commit is contained in:
@@ -158,7 +158,7 @@ export default class ParameterRow extends Component {
|
|||||||
<Markdown source={
|
<Markdown source={
|
||||||
"<i>Available values</i>: " + paramItemsEnum.map(function(item) {
|
"<i>Available values</i>: " + paramItemsEnum.map(function(item) {
|
||||||
return item
|
return item
|
||||||
}).toArray().join(", ")}/>
|
}).toArray().join(", ")}/>
|
||||||
: null
|
: null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,6 +181,7 @@ export default class ParameterRow extends Component {
|
|||||||
required={ required }
|
required={ required }
|
||||||
description={param.get("description") ? `${param.get("name")} - ${param.get("description")}` : `${param.get("name")}`}
|
description={param.get("description") ? `${param.get("name")} - ${param.get("description")}` : `${param.get("name")}`}
|
||||||
onChange={ this.onChangeWrapper }
|
onChange={ this.onChangeWrapper }
|
||||||
|
errors={ param.get("errors") }
|
||||||
schema={ isOAS3 && isOAS3() ? param.get("schema") : param }/>
|
schema={ isOAS3 && isOAS3() ? param.get("schema") : param }/>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React, { PureComponent, Component } from "react"
|
import React, { PureComponent, Component } from "react"
|
||||||
import PropTypes from "prop-types"
|
import PropTypes from "prop-types"
|
||||||
import { List, fromJS } from "immutable"
|
import { List, fromJS } from "immutable"
|
||||||
|
import ImPropTypes from "react-immutable-proptypes"
|
||||||
//import "less/json-schema-form"
|
//import "less/json-schema-form"
|
||||||
|
|
||||||
const noop = ()=> {}
|
const noop = ()=> {}
|
||||||
@@ -11,6 +12,7 @@ const JsonSchemaPropShape = {
|
|||||||
keyName: PropTypes.any,
|
keyName: PropTypes.any,
|
||||||
fn: PropTypes.object.isRequired,
|
fn: PropTypes.object.isRequired,
|
||||||
schema: PropTypes.object,
|
schema: PropTypes.object,
|
||||||
|
errors: ImPropTypes.list,
|
||||||
required: PropTypes.bool,
|
required: PropTypes.bool,
|
||||||
description: PropTypes.any
|
description: PropTypes.any
|
||||||
}
|
}
|
||||||
@@ -20,7 +22,8 @@ const JsonSchemaDefaultProps = {
|
|||||||
onChange: noop,
|
onChange: noop,
|
||||||
schema: {},
|
schema: {},
|
||||||
keyName: "",
|
keyName: "",
|
||||||
required: false
|
required: false,
|
||||||
|
errors: List()
|
||||||
}
|
}
|
||||||
|
|
||||||
export class JsonSchemaForm extends Component {
|
export class JsonSchemaForm extends Component {
|
||||||
@@ -29,7 +32,7 @@ export class JsonSchemaForm extends Component {
|
|||||||
static defaultProps = JsonSchemaDefaultProps
|
static defaultProps = JsonSchemaDefaultProps
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { schema, value, onChange, getComponent, fn } = this.props
|
let { schema, errors, value, onChange, getComponent, fn } = this.props
|
||||||
|
|
||||||
if(schema.toJS)
|
if(schema.toJS)
|
||||||
schema = schema.toJS()
|
schema = schema.toJS()
|
||||||
@@ -37,7 +40,7 @@ export class JsonSchemaForm extends Component {
|
|||||||
let { type, format="" } = schema
|
let { type, format="" } = schema
|
||||||
|
|
||||||
let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string")
|
let Comp = (format ? getComponent(`JsonSchema_${type}_${format}`) : getComponent(`JsonSchema_${type}`)) || getComponent("JsonSchema_string")
|
||||||
return <Comp { ...this.props } fn={fn} getComponent={getComponent} value={value} onChange={onChange} schema={schema}/>
|
return <Comp { ...this.props } errors={errors} fn={fn} getComponent={getComponent} value={value} onChange={onChange} schema={schema}/>
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -51,14 +54,15 @@ export class JsonSchema_string extends Component {
|
|||||||
}
|
}
|
||||||
onEnumChange = (val) => this.props.onChange(val)
|
onEnumChange = (val) => this.props.onChange(val)
|
||||||
render() {
|
render() {
|
||||||
let { getComponent, value, schema, required, description } = this.props
|
let { getComponent, value, schema, errors, required, description } = this.props
|
||||||
let enumValue = schema["enum"]
|
let enumValue = schema["enum"]
|
||||||
let errors = schema.errors || []
|
|
||||||
|
errors = errors.toJS ? errors.toJS() : []
|
||||||
|
|
||||||
if ( enumValue ) {
|
if ( enumValue ) {
|
||||||
const Select = getComponent("Select")
|
const Select = getComponent("Select")
|
||||||
return (<Select className={ errors.length ? "invalid" : ""}
|
return (<Select className={ errors.length ? "invalid" : ""}
|
||||||
title={ errors.length ? errors : ""}
|
title={ errors.length ? errors : ""}
|
||||||
allowedValues={ enumValue }
|
allowedValues={ enumValue }
|
||||||
value={ value }
|
value={ value }
|
||||||
allowEmptyValue={ !required }
|
allowEmptyValue={ !required }
|
||||||
@@ -70,14 +74,14 @@ export class JsonSchema_string extends Component {
|
|||||||
if (schema["type"] === "file") {
|
if (schema["type"] === "file") {
|
||||||
return (<Input type="file"
|
return (<Input type="file"
|
||||||
className={ errors.length ? "invalid" : ""}
|
className={ errors.length ? "invalid" : ""}
|
||||||
title={ errors.length ? errors : ""}
|
title={ errors.length ? errors : ""}
|
||||||
onChange={ this.onChange }
|
onChange={ this.onChange }
|
||||||
disabled={isDisabled}/>)
|
disabled={isDisabled}/>)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return (<Input type={ schema.format === "password" ? "password" : "text" }
|
return (<Input type={ schema.format === "password" ? "password" : "text" }
|
||||||
className={ errors.length ? "invalid" : ""}
|
className={ errors.length ? "invalid" : ""}
|
||||||
title={ errors.length ? errors : ""}
|
title={ errors.length ? errors : ""}
|
||||||
value={value}
|
value={value}
|
||||||
placeholder={description}
|
placeholder={description}
|
||||||
onChange={ this.onChange }
|
onChange={ this.onChange }
|
||||||
@@ -131,9 +135,10 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let { getComponent, required, schema, fn } = this.props
|
let { getComponent, required, schema, errors, fn } = this.props
|
||||||
|
|
||||||
|
errors = errors.toJS ? errors.toJS() : []
|
||||||
|
|
||||||
let errors = schema.errors || []
|
|
||||||
let itemSchema = fn.inferSchema(schema.items)
|
let itemSchema = fn.inferSchema(schema.items)
|
||||||
|
|
||||||
const JsonSchemaForm = getComponent("JsonSchemaForm")
|
const JsonSchemaForm = getComponent("JsonSchemaForm")
|
||||||
@@ -145,7 +150,7 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
if ( enumValue ) {
|
if ( enumValue ) {
|
||||||
const Select = getComponent("Select")
|
const Select = getComponent("Select")
|
||||||
return (<Select className={ errors.length ? "invalid" : ""}
|
return (<Select className={ errors.length ? "invalid" : ""}
|
||||||
title={ errors.length ? errors : ""}
|
title={ errors.length ? errors : ""}
|
||||||
multiple={ true }
|
multiple={ true }
|
||||||
value={ value }
|
value={ value }
|
||||||
allowedValues={ enumValue }
|
allowedValues={ enumValue }
|
||||||
@@ -160,7 +165,7 @@ export class JsonSchema_array extends PureComponent {
|
|||||||
let schema = Object.assign({}, itemSchema)
|
let schema = Object.assign({}, itemSchema)
|
||||||
if ( errors.length ) {
|
if ( errors.length ) {
|
||||||
let err = errors.filter((err) => err.index === i)
|
let err = errors.filter((err) => err.index === i)
|
||||||
if (err.length) schema.errors = [ err[0].error + i ]
|
if (err.length) errors = [ err[0].error + i ]
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<div key={i} className="json-schema-form-item">
|
<div key={i} className="json-schema-form-item">
|
||||||
@@ -182,12 +187,13 @@ export class JsonSchema_boolean extends Component {
|
|||||||
|
|
||||||
onEnumChange = (val) => this.props.onChange(val)
|
onEnumChange = (val) => this.props.onChange(val)
|
||||||
render() {
|
render() {
|
||||||
let { getComponent, value, schema } = this.props
|
let { getComponent, value, errors, schema } = this.props
|
||||||
let errors = schema.errors || []
|
errors = errors.toJS ? errors.toJS() : []
|
||||||
|
|
||||||
const Select = getComponent("Select")
|
const Select = getComponent("Select")
|
||||||
|
|
||||||
return (<Select className={ errors.length ? "invalid" : ""}
|
return (<Select className={ errors.length ? "invalid" : ""}
|
||||||
title={ errors.length ? errors : ""}
|
title={ errors.length ? errors : ""}
|
||||||
value={ String(value) }
|
value={ String(value) }
|
||||||
allowedValues={ fromJS(schema.enum || ["true", "false"]) }
|
allowedValues={ fromJS(schema.enum || ["true", "false"]) }
|
||||||
allowEmptyValue={ !this.props.required }
|
allowEmptyValue={ !this.props.required }
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
[VALIDATE_PARAMS]: ( state, { payload: { pathMethod, isOAS3 } } ) => {
|
[VALIDATE_PARAMS]: ( state, { payload: { pathMethod, isOAS3 } } ) => {
|
||||||
let meta = state.getIn( [ "meta", "paths", ...pathMethod ] )
|
let meta = state.getIn( [ "meta", "paths", ...pathMethod ], fromJS({}) )
|
||||||
let isXml = /xml/i.test(meta.get("consumes_value"))
|
let isXml = /xml/i.test(meta.get("consumes_value"))
|
||||||
|
|
||||||
return state.updateIn( [ "resolved", "paths", ...pathMethod, "parameters" ], fromJS([]), parameters => {
|
return state.updateIn( [ "resolved", "paths", ...pathMethod, "parameters" ], fromJS([]), parameters => {
|
||||||
@@ -68,7 +68,7 @@ export default {
|
|||||||
return state.updateIn( [ "resolved", "paths", ...pathMethod, "parameters" ], fromJS([]), parameters => {
|
return state.updateIn( [ "resolved", "paths", ...pathMethod, "parameters" ], fromJS([]), parameters => {
|
||||||
return parameters.withMutations( parameters => {
|
return parameters.withMutations( parameters => {
|
||||||
for ( let i = 0, len = parameters.count(); i < len; i++ ) {
|
for ( let i = 0, len = parameters.count(); i < len; i++ ) {
|
||||||
parameters.setIn([i, "errors"], fromJS({}))
|
parameters.setIn([i, "errors"], fromJS([]))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user