Skip to content

Commit

Permalink
fix(parameters): allowedValues for enum and boolean types (#8231)
Browse files Browse the repository at this point in the history
* Change parameter with empty map

* Change allowValues data type

Co-authored-by: Tim Lai <timothy.lai@smartbear.com>
  • Loading branch information
ishuen and tim-lai committed Oct 25, 2022
1 parent 99ef4b9 commit 2a967e9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/core/json-schema-components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 }/>)
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/get-parameter-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
32 changes: 32 additions & 0 deletions test/unit/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 2a967e9

Please sign in to comment.