Skip to content

Commit 2a967e9

Browse files
ishuentim-lai
andauthored
fix(parameters): allowedValues for enum and boolean types (#8231)
* Change parameter with empty map * Change allowValues data type Co-authored-by: Tim Lai <[email protected]>
1 parent 99ef4b9 commit 2a967e9

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

src/core/json-schema-components.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export class JsonSchema_string extends Component {
8585
const Select = getComponent("Select")
8686
return (<Select className={ errors.length ? "invalid" : ""}
8787
title={ errors.length ? errors : ""}
88-
allowedValues={ enumValue }
88+
allowedValues={ [...enumValue] }
8989
value={ value }
9090
allowEmptyValue={ !required }
9191
disabled={disabled}
@@ -335,14 +335,14 @@ export class JsonSchema_boolean extends Component {
335335
errors = errors.toJS ? errors.toJS() : []
336336
let enumValue = schema && schema.get ? schema.get("enum") : null
337337
let allowEmptyValue = !enumValue || !required
338-
let booleanValue = !enumValue && fromJS(["true", "false"])
338+
let booleanValue = !enumValue && ["true", "false"]
339339
const Select = getComponent("Select")
340340

341341
return (<Select className={ errors.length ? "invalid" : ""}
342342
title={ errors.length ? errors : ""}
343343
value={ String(value) }
344344
disabled={ disabled }
345-
allowedValues={ enumValue || booleanValue }
345+
allowedValues={ enumValue ? [...enumValue] : booleanValue }
346346
allowEmptyValue={ allowEmptyValue }
347347
onChange={ this.onEnumChange }/>)
348348
}

src/helpers/get-parameter-schema.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export default function getParameterSchema(parameter, { isOAS3 } = {}) {
8686
}
8787

8888
return {
89-
schema: parameter.get("schema", Im.Map()),
89+
schema: parameter.get("schema") ? parameter.get("schema", Im.Map()): Im.Map(),
9090
parameterContentMediaType: null,
9191
}
9292
}

test/unit/components/parameter-row.jsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ describe("<ParameterRow/>", () => {
4949
expect(wrapper.find(".parameter__type").text()).toEqual("string")
5050
})
5151

52+
it("Can render Swagger 2 parameter type boolean without format", () => {
53+
const param = fromJS({
54+
name: "hasId",
55+
in: "path",
56+
description: "boolean value to indicate if the pet has an id",
57+
type: "boolean"
58+
})
59+
60+
const props = createProps({ param, isOAS3: false })
61+
const wrapper = render(<ParameterRow {...props}/>)
62+
63+
expect(wrapper.find(".parameter__type").length).toEqual(1)
64+
expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
65+
})
66+
5267
it("Can render OAS3 parameter type with format", () => {
5368
const param = fromJS({
5469
name: "petUuid",
@@ -83,6 +98,23 @@ describe("<ParameterRow/>", () => {
8398
expect(wrapper.find(".parameter__type").length).toEqual(1)
8499
expect(wrapper.find(".parameter__type").text()).toEqual("string")
85100
})
101+
102+
it("Can render OAS3 parameter type boolean without format", () => {
103+
const param = fromJS({
104+
name: "hasId",
105+
in: "path",
106+
description: "boolean value to indicate if the pet has an id",
107+
schema: {
108+
type: "boolean"
109+
}
110+
})
111+
112+
const props = createProps({ param, isOAS3: true })
113+
const wrapper = render(<ParameterRow {...props}/>)
114+
115+
expect(wrapper.find(".parameter__type").length).toEqual(1)
116+
expect(wrapper.find(".parameter__type").text()).toEqual("boolean")
117+
})
86118
})
87119

88120
describe("bug #5573: zero default and example values", function () {

0 commit comments

Comments
 (0)