From a1deadc5b1bb0330052dc9f9cfed65aee9c88f10 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 27 Jul 2018 00:24:32 -0700 Subject: [PATCH 1/3] add failing tests --- test/e2e/scenarios/bugs/4756.js | 43 +++++++++++++++++++++++++++ test/e2e/specs/bugs/4756.yaml | 51 +++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 test/e2e/scenarios/bugs/4756.js create mode 100644 test/e2e/specs/bugs/4756.yaml 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 From 47b7bea134394e1b5bbd1c87987f93089ea02cd8 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 27 Jul 2018 00:26:57 -0700 Subject: [PATCH 2/3] coerce initial values to string --- src/core/components/parameter-row.jsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index fe171f6acca..93df44a6732 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -2,6 +2,7 @@ import React, { Component } from "react" import { Map } from "immutable" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" +import toString from "lodash/toString" import win from "core/window" import { getExtensions, getCommonExtensions } from "core/utils" @@ -53,7 +54,7 @@ export default class ParameterRow extends Component { } if ( value !== undefined && value !== paramValue ) { - this.onChangeWrapper(value) + this.onChangeWrapper(toString(value)) } this.setDefaultValue() @@ -88,7 +89,7 @@ export default class ParameterRow extends Component { || paramWithMeta.getIn(["schema", "default"]) } if(newValue !== undefined) { - this.onChangeWrapper(newValue) + this.onChangeWrapper(toString(newValue)) } } } From fa0cb9f4408dd8b8c188bfb774e6e72ca2c113e7 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Fri, 27 Jul 2018 01:11:23 -0700 Subject: [PATCH 3/3] only convert numbers to strings when setting parameter values --- src/core/components/parameter-row.jsx | 7 +++---- src/core/utils.js | 8 ++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/components/parameter-row.jsx b/src/core/components/parameter-row.jsx index 93df44a6732..a756a4ce30e 100644 --- a/src/core/components/parameter-row.jsx +++ b/src/core/components/parameter-row.jsx @@ -2,9 +2,8 @@ import React, { Component } from "react" import { Map } from "immutable" import PropTypes from "prop-types" import ImPropTypes from "react-immutable-proptypes" -import toString from "lodash/toString" 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 = { @@ -54,7 +53,7 @@ export default class ParameterRow extends Component { } if ( value !== undefined && value !== paramValue ) { - this.onChangeWrapper(toString(value)) + this.onChangeWrapper(numberToString(value)) } this.setDefaultValue() @@ -89,7 +88,7 @@ export default class ParameterRow extends Component { || paramWithMeta.getIn(["schema", "default"]) } if(newValue !== undefined) { - this.onChangeWrapper(toString(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