- | { key }: |
+
+ { key }{ isRequired && * }
+ |
+ bodyEl =
// Audio
} else if (/^audio\//i.test(contentType)) {
diff --git a/src/core/components/schemes.jsx b/src/core/components/schemes.jsx
index 8be4180a..f9fe8f81 100644
--- a/src/core/components/schemes.jsx
+++ b/src/core/components/schemes.jsx
@@ -19,8 +19,9 @@ export default class Schemes extends React.Component {
}
componentWillReceiveProps(nextProps) {
- if ( this.props.operationScheme && !nextProps.schemes.has(this.props.operationScheme) ) {
- //fire 'change' event if our selected scheme is no longer an option
+ if ( !this.props.operationScheme || !nextProps.schemes.has(this.props.operationScheme) ) {
+ // if we don't have a selected operationScheme or if our selected scheme is no longer an option,
+ // then fire 'change' event and select the first scheme in the list of options
this.setScheme(nextProps.schemes.first())
}
}
diff --git a/src/core/json-schema-components.js b/src/core/json-schema-components.js
index bf4ae514..338bd6e3 100644
--- a/src/core/json-schema-components.js
+++ b/src/core/json-schema-components.js
@@ -57,7 +57,8 @@ export class JsonSchema_string extends Component {
if ( enumValue ) {
const Select = getComponent("Select")
- return ()
@@ -121,6 +122,7 @@ export class JsonSchema_array extends PureComponent {
render() {
let { getComponent, required, schema, fn } = this.props
+ let errors = schema.errors || []
let itemSchema = fn.inferSchema(schema.items)
const JsonSchemaForm = getComponent("JsonSchemaForm")
@@ -131,19 +133,17 @@ export class JsonSchema_array extends PureComponent {
if ( enumValue ) {
const Select = getComponent("Select")
- return ()
}
- let errors = schema.errors || []
-
return (
- { !value || value.count() < 1 ?
- (errors.length ? { errors[0] } : null) :
+ { !value || value.count() < 1 ? null :
value.map( (item,i) => {
let schema = Object.assign({}, itemSchema)
if ( errors.length ) {
@@ -153,12 +153,12 @@ export class JsonSchema_array extends PureComponent {
return (
this.onItemChange(val, i)} schema={schema} />
-
+
)
}).toArray()
}
-
+
)
}
@@ -170,12 +170,14 @@ export class JsonSchema_boolean extends Component {
onEnumChange = (val) => this.props.onChange(val)
render() {
- let { getComponent, required, value } = this.props
+ let { getComponent, value, schema } = this.props
+ let errors = schema.errors || []
const Select = getComponent("Select")
- return ()
}
}
diff --git a/src/core/utils.js b/src/core/utils.js
index 95771fb4..7cc5beda 100644
--- a/src/core/utils.js
+++ b/src/core/utils.js
@@ -41,7 +41,7 @@ export function fromJSOrdered (js) {
return !isObject(js) ? js :
Array.isArray(js) ?
Im.Seq(js).map(fromJSOrdered).toList() :
- Im.Seq(js).map(fromJSOrdered).toOrderedMap()
+ Im.OrderedMap(js).map(fromJSOrdered)
}
export function bindToState(obj, state) {
@@ -468,6 +468,18 @@ export const validateFile = ( val ) => {
}
}
+export const validateBoolean = ( val ) => {
+ if ( !(val === "true" || val === "false" || val === true || val === false) ) {
+ return "Value must be a boolean"
+ }
+}
+
+export const validateString = ( val ) => {
+ if ( val && typeof val !== "string" ) {
+ return "Value must be a string"
+ }
+}
+
// validation of parameters before execute
export const validateParam = (param, isXml) => {
let errors = []
@@ -475,52 +487,66 @@ export const validateParam = (param, isXml) => {
let required = param.get("required")
let type = param.get("type")
- let stringCheck = type === "string" && !value
- let arrayCheck = type === "array" && Array.isArray(value) && !value.length
- let listCheck = type === "array" && Im.List.isList(value) && !value.count()
- let fileCheck = type === "file" && !(value instanceof win.File)
+ // If the parameter is required OR the parameter has a value (meaning optional, but filled in)
+ // then we should do our validation routine
+ if ( required || value ) {
+ // These checks should evaluate to true if the parameter's value is valid
+ let stringCheck = type === "string" && value && !validateString(value)
+ let arrayCheck = type === "array" && Array.isArray(value) && value.length
+ let listCheck = type === "array" && Im.List.isList(value) && value.count()
+ let fileCheck = type === "file" && value instanceof win.File
+ let booleanCheck = type === "boolean" && !validateBoolean(value)
+ let numberCheck = type === "number" && !validateNumber(value) // validateNumber returns undefined if the value is a number
+ let integerCheck = type === "integer" && !validateInteger(value) // validateInteger returns undefined if the value is an integer
- if ( required && (stringCheck || arrayCheck || listCheck || fileCheck) ) {
- errors.push("Required field is not provided")
- return errors
- }
+ if ( required && !(stringCheck || arrayCheck || listCheck || fileCheck || booleanCheck || numberCheck || integerCheck) ) {
+ errors.push("Required field is not provided")
+ return errors
+ }
- if ( value === null || value === undefined ) {
- return errors
- }
+ if ( type === "string" ) {
+ let err = validateString(value)
+ if (!err) return errors
+ errors.push(err)
+ } else if ( type === "boolean" ) {
+ let err = validateBoolean(value)
+ if (!err) return errors
+ errors.push(err)
+ } else if ( type === "number" ) {
+ let err = validateNumber(value)
+ if (!err) return errors
+ errors.push(err)
+ } else if ( type === "integer" ) {
+ let err = validateInteger(value)
+ if (!err) return errors
+ errors.push(err)
+ } else if ( type === "array" ) {
+ let itemType
- if ( type === "number" ) {
- let err = validateNumber(value)
- if (!err) return errors
- errors.push(err)
- } else if ( type === "integer" ) {
- let err = validateInteger(value)
- if (!err) return errors
- errors.push(err)
- } else if ( type === "array" ) {
- let itemType
+ if ( !value.count() ) { return errors }
- if ( !value.count() ) { return errors }
+ itemType = param.getIn(["items", "type"])
- itemType = param.getIn(["items", "type"])
+ value.forEach((item, index) => {
+ let err
- value.forEach((item, index) => {
- let err
+ if (itemType === "number") {
+ err = validateNumber(item)
+ } else if (itemType === "integer") {
+ err = validateInteger(item)
+ } else if (itemType === "string") {
+ err = validateString(item)
+ }
- if (itemType === "number") {
- err = validateNumber(item)
- } else if (itemType === "integer") {
- err = validateInteger(item)
- }
-
- if ( err ) {
- errors.push({ index: index, error: err})
- }
- })
- } else if ( type === "file" ) {
- let err = validateFile(value)
- if (!err) return errors
- errors.push(err)
+ if ( err ) {
+ errors.push({ index: index, error: err})
+ }
+ })
+ } else if ( type === "file" ) {
+ let err = validateFile(value)
+ if (!err) return errors
+ errors.push(err)
+ }
}
return errors
diff --git a/src/plugins/add-plugin.md b/src/plugins/add-plugin.md
index 7a77cb30..2e2d52e1 100644
--- a/src/plugins/add-plugin.md
+++ b/src/plugins/add-plugin.md
@@ -20,7 +20,7 @@ SwaggerUI({
})
```
-Or if you're updating the core plugins.. you'll add it to [src/js/bootstrap-plugin](https://github.com/SmartBear/swagger-ux/blob/master/src/js/bootstrap-plugin.js)
+Or if you're updating the core plugins.. you'll add it to the base preset: [src/core/presets/base.js](https://github.com/swagger-api/swagger-ui/blob/master/src/core/presets/base.js)
Each Plugin is a function that returns an object. That object will get merged with the `system` and later bound to the state.
Here is an example of each `type`
diff --git a/src/plugins/topbar/topbar.jsx b/src/plugins/topbar/topbar.jsx
index fd3654bb..ec9db730 100644
--- a/src/plugins/topbar/topbar.jsx
+++ b/src/plugins/topbar/topbar.jsx
@@ -130,7 +130,7 @@ export default class Topbar extends React.Component {
- 
+
swagger
|