diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index fe171f6acca..a756a4ce30e 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -3,7 +3,7 @@ import { Map } from "immutable" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" import win from "core/window" -import { getExtensions, getCommonExtensions } from "core/utils" +import { getExtensions, getCommonExtensions, numberToString } from "core/utils" export default class ParameterRow extends Component { static propTypes = { @@ -53,7 +53,7 @@ export default class ParameterRow extends Component { } if ( value !== undefined && value !== paramValue ) { - this.onChangeWrapper(value) + this.onChangeWrapper(numberToString(value)) } this.setDefaultValue() @@ -88,7 +88,7 @@ export default class ParameterRow extends Component { || paramWithMeta.getIn(["schema", "default"]) } if(newValue !== undefined) { - this.onChangeWrapper(newValue) + this.onChangeWrapper(numberToString(newValue)) } } } diff --git a/src/core/utils.js b/src/core/utils.js index 248ef59406a..3323a87dda5 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -780,4 +780,12 @@ export function stringify(thing) { } return thing.toString() +} + +export function numberToString(thing) { + if(typeof thing === "number") { + return thing.toString() + } + + return thing } \ No newline at end of file diff --git a/test/e2e/scenarios/bugs/4756.js b/test/e2e/scenarios/bugs/4756.js new file mode 100644 index 00000000000..fca8e870326 --- /dev/null +++ b/test/e2e/scenarios/bugs/4756.js @@ -0,0 +1,43 @@ +describe("bug #4756: enum initial values", function () { + let mainPage + beforeEach(function (client, done) { + mainPage = client + .url("localhost:3230") + .page.main() + + client.waitForElementVisible(".download-url-input:not([disabled])", 5000) + .pause(2000) + .clearValue(".download-url-input") + .setValue(".download-url-input", "http://localhost:3230/test-specs/bugs/4756.yaml") + .click("button.download-url-button") + .pause(1000) + + done() + }) + + afterEach(function (client, done) { + done() + }) + + it("sets a required initial value based the first enum value", function (client) { + client.waitForElementVisible(".opblock-tag-section", 10000) + .click("#operations-default-post_zero") + .waitForElementVisible(".opblock.is-open", 5000) + .click("button.btn.try-out__btn") + .click("button.btn.execute") + .waitForElementVisible(".request-url", 2000) + .assert.containsText(".request-url > pre", "http://www.example.com/test/API/zero?one=0") + client.end() + }) + + it("sets a required initial value based on a default value", function (client) { + client.waitForElementVisible(".opblock-tag-section", 10000) + .click("#operations-default-post_one") + .waitForElementVisible(".opblock.is-open", 5000) + .click("button.btn.try-out__btn") + .click("button.btn.execute") + .waitForElementVisible(".request-url", 2000) + .assert.containsText(".request-url > pre", "http://www.example.com/test/API/one?one=1") + client.end() + }) +}) diff --git a/test/e2e/specs/bugs/4756.yaml b/test/e2e/specs/bugs/4756.yaml new file mode 100644 index 00000000000..b1c142ea7b5 --- /dev/null +++ b/test/e2e/specs/bugs/4756.yaml @@ -0,0 +1,51 @@ +swagger: '2.0' +info: + title: test doc + description: 'test doc ' + license: + name: Copyright @2018 + version: 1.0.0 +host: www.example.com +basePath: /test/API +tags: + - name: devices + description: devices +schemes: + - http + - https +consumes: + - application/x-www-form-urlencoded +produces: + - application/json +paths: + /zero: + post: + parameters: + - in: query + name: one + type: string + required: true + enum: + - 0 + - 1 + responses: + 200: + description: 'response' + examples: + application/json: {"error":0} + /one: + post: + parameters: + - in: query + name: one + type: string + required: true + default: 1 + enum: + - 0 + - 1 + responses: + 200: + description: 'response' + examples: + application/json: {"error":0} \ No newline at end of file