Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/components/parameter-row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -53,7 +53,7 @@ export default class ParameterRow extends Component {
}

if ( value !== undefined && value !== paramValue ) {
this.onChangeWrapper(value)
this.onChangeWrapper(numberToString(value))
}

this.setDefaultValue()
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class ParameterRow extends Component {
|| paramWithMeta.getIn(["schema", "default"])
}
if(newValue !== undefined) {
this.onChangeWrapper(newValue)
this.onChangeWrapper(numberToString(newValue))
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -780,4 +780,12 @@ export function stringify(thing) {
}

return thing.toString()
}

export function numberToString(thing) {
if(typeof thing === "number") {
return thing.toString()
}

return thing
}
43 changes: 43 additions & 0 deletions test/e2e/scenarios/bugs/4756.js
Original file line number Diff line number Diff line change
@@ -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()
})
})
51 changes: 51 additions & 0 deletions test/e2e/specs/bugs/4756.yaml
Original file line number Diff line number Diff line change
@@ -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}