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:
ishuen
2022-10-26 02:01:07 +08:00
committed by GitHub
parent 99ef4b9945
commit 2a967e9b25
3 changed files with 36 additions and 4 deletions

View File

@@ -85,7 +85,7 @@ export class JsonSchema_string extends Component {
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 }
disabled={disabled} disabled={disabled}
@@ -335,14 +335,14 @@ export class JsonSchema_boolean extends Component {
errors = errors.toJS ? errors.toJS() : [] errors = errors.toJS ? errors.toJS() : []
let enumValue = schema && schema.get ? schema.get("enum") : null let enumValue = schema && schema.get ? schema.get("enum") : null
let allowEmptyValue = !enumValue || !required let allowEmptyValue = !enumValue || !required
let booleanValue = !enumValue && fromJS(["true", "false"]) let booleanValue = !enumValue && ["true", "false"]
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) }
disabled={ disabled } disabled={ disabled }
allowedValues={ enumValue || booleanValue } allowedValues={ enumValue ? [...enumValue] : booleanValue }
allowEmptyValue={ allowEmptyValue } allowEmptyValue={ allowEmptyValue }
onChange={ this.onEnumChange }/>) onChange={ this.onEnumChange }/>)
} }

View File

@@ -86,7 +86,7 @@ export default function getParameterSchema(parameter, { isOAS3 } = {}) {
} }
return { return {
schema: parameter.get("schema", Im.Map()), schema: parameter.get("schema") ? parameter.get("schema", Im.Map()): Im.Map(),
parameterContentMediaType: null, parameterContentMediaType: null,
} }
} }

View File

@@ -49,6 +49,21 @@ describe("<ParameterRow/>", () => {
expect(wrapper.find(".parameter__type").text()).toEqual("string") 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", () => { it("Can render OAS3 parameter type with format", () => {
const param = fromJS({ const param = fromJS({
name: "petUuid", name: "petUuid",
@@ -83,6 +98,23 @@ describe("<ParameterRow/>", () => {
expect(wrapper.find(".parameter__type").length).toEqual(1) expect(wrapper.find(".parameter__type").length).toEqual(1)
expect(wrapper.find(".parameter__type").text()).toEqual("string") 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 () { describe("bug #5573: zero default and example values", function () {