fix(parameters): allowedValues for enum and boolean types (#8231)
* Change parameter with empty map * Change allowValues data type Co-authored-by: Tim Lai <timothy.lai@smartbear.com>
This commit is contained in:
@@ -85,7 +85,7 @@ export class JsonSchema_string extends Component {
|
||||
const Select = getComponent("Select")
|
||||
return (<Select className={ errors.length ? "invalid" : ""}
|
||||
title={ errors.length ? errors : ""}
|
||||
allowedValues={ enumValue }
|
||||
allowedValues={ [...enumValue] }
|
||||
value={ value }
|
||||
allowEmptyValue={ !required }
|
||||
disabled={disabled}
|
||||
@@ -335,14 +335,14 @@ export class JsonSchema_boolean extends Component {
|
||||
errors = errors.toJS ? errors.toJS() : []
|
||||
let enumValue = schema && schema.get ? schema.get("enum") : null
|
||||
let allowEmptyValue = !enumValue || !required
|
||||
let booleanValue = !enumValue && fromJS(["true", "false"])
|
||||
let booleanValue = !enumValue && ["true", "false"]
|
||||
const Select = getComponent("Select")
|
||||
|
||||
return (<Select className={ errors.length ? "invalid" : ""}
|
||||
title={ errors.length ? errors : ""}
|
||||
value={ String(value) }
|
||||
disabled={ disabled }
|
||||
allowedValues={ enumValue || booleanValue }
|
||||
allowedValues={ enumValue ? [...enumValue] : booleanValue }
|
||||
allowEmptyValue={ allowEmptyValue }
|
||||
onChange={ this.onEnumChange }/>)
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ export default function getParameterSchema(parameter, { isOAS3 } = {}) {
|
||||
}
|
||||
|
||||
return {
|
||||
schema: parameter.get("schema", Im.Map()),
|
||||
schema: parameter.get("schema") ? parameter.get("schema", Im.Map()): Im.Map(),
|
||||
parameterContentMediaType: null,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,21 @@ describe("<ParameterRow/>", () => {
|
||||
expect(wrapper.find(".parameter__type").text()).toEqual("string")
|
||||
})
|
||||
|
||||
it("Can render Swagger 2 parameter type boolean without format", () => {
|
||||
const param = fromJS({
|
||||
name: "hasId",
|
||||
in: "path",
|
||||
description: "boolean value to indicate if the pet has an id",
|
||||
type: "boolean"
|
||||
})
|
||||
|
||||
const props = createProps({ param, isOAS3: false })
|
||||
const wrapper = render(<ParameterRow {...props}/>)
|
||||
|
||||
expect(wrapper.find(".parameter__type").length).toEqual(1)
|
||||
expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
|
||||
})
|
||||
|
||||
it("Can render OAS3 parameter type with format", () => {
|
||||
const param = fromJS({
|
||||
name: "petUuid",
|
||||
@@ -83,6 +98,23 @@ describe("<ParameterRow/>", () => {
|
||||
expect(wrapper.find(".parameter__type").length).toEqual(1)
|
||||
expect(wrapper.find(".parameter__type").text()).toEqual("string")
|
||||
})
|
||||
|
||||
it("Can render OAS3 parameter type boolean without format", () => {
|
||||
const param = fromJS({
|
||||
name: "hasId",
|
||||
in: "path",
|
||||
description: "boolean value to indicate if the pet has an id",
|
||||
schema: {
|
||||
type: "boolean"
|
||||
}
|
||||
})
|
||||
|
||||
const props = createProps({ param, isOAS3: true })
|
||||
const wrapper = render(<ParameterRow {...props}/>)
|
||||
|
||||
expect(wrapper.find(".parameter__type").length).toEqual(1)
|
||||
expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
|
||||
})
|
||||
})
|
||||
|
||||
describe("bug #5573: zero default and example values", function () {
|
||||
|
||||
Reference in New Issue
Block a user