未验证 提交 bbbd1b93 编写于 作者: K kyle 提交者: GitHub

fix: OAS3 array item value input (#4729)

* fix: OAS3 array item value input
* linter fixes
上级 e70a054b
......@@ -27,20 +27,24 @@ export default class ParameterRow extends Component {
}
componentWillReceiveProps(props) {
let { specSelectors, pathMethod, param } = props
let { specSelectors, pathMethod, rawParam } = props
let { isOAS3 } = specSelectors
let example = param.get("example")
let parameter = specSelectors.parameterWithMetaByIdentity(pathMethod, param) || param
let example = rawParam.get("example")
let parameterWithMeta = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam)
// fallback, if the meta lookup fails
parameterWithMeta = parameterWithMeta.isEmpty() ? rawParam : parameterWithMeta
let enumValue
if(isOAS3()) {
let schema = param.get("schema") || Map()
let schema = rawParam.get("schema") || Map()
enumValue = schema.get("enum")
} else {
enumValue = parameter ? parameter.get("enum") : undefined
enumValue = parameterWithMeta ? parameterWithMeta.get("enum") : undefined
}
let paramValue = parameter ? parameter.get("value") : undefined
let paramValue = parameterWithMeta ? parameterWithMeta.get("value") : undefined
let value
......@@ -48,7 +52,7 @@ export default class ParameterRow extends Component {
value = paramValue
} else if ( example !== undefined ) {
value = example
} else if ( param.get("required") && enumValue && enumValue.size ) {
} else if ( rawParam.get("required") && enumValue && enumValue.size ) {
value = enumValue.first()
}
......@@ -63,20 +67,20 @@ export default class ParameterRow extends Component {
}
setDefaultValue = () => {
let { specSelectors, pathMethod, param } = this.props
let { specSelectors, pathMethod, rawParam } = this.props
if (param.get("value") !== undefined) {
if (rawParam.get("value") !== undefined) {
return
}
let schema = specSelectors.isOAS3() ? param.get("schema", Map({})) : param
let schema = specSelectors.isOAS3() ? rawParam.get("schema", Map({})) : rawParam
let defaultValue = schema.get("default")
let xExampleValue = param.get("x-example") // Swagger 2 only
let parameter = specSelectors.parameterWithMetaByIdentity(pathMethod, param)
let xExampleValue = rawParam.get("x-example") // Swagger 2 only
let parameter = specSelectors.parameterWithMetaByIdentity(pathMethod, rawParam)
let value = parameter ? parameter.get("value") : ""
if( param.get("in") !== "body" ) {
if( rawParam.get("in") !== "body" ) {
if ( xExampleValue !== undefined && value === undefined && specSelectors.isSwagger2() ) {
this.onChangeWrapper(xExampleValue)
} else if ( defaultValue !== undefined && value === undefined ) {
......
describe("bug: unable to change array input", function () {
let mainPage
beforeEach(function (client, done) {
mainPage = client
.url("localhost:3230")
.page.main()
client.waitForElementVisible(".download-url-input:not([disabled])", 5000)
.clearValue(".download-url-input")
.setValue(".download-url-input", "/test-specs/bugs/frozen-array-input.yaml")
.click("button.download-url-button")
done()
})
afterEach(function (client, done) {
done()
})
it("consistently displays a model's name regardless of expansion state", function (client) {
client.waitForElementVisible(".opblock-summary-description", 10000)
.assert.containsText("span.opblock-summary-path > a > span", "/test")
.click("#operations-default-get_test")
.pause(500)
.click("button.btn.try-out__btn")
.elements("css selector", ".json-schema-form-item", function (result) {
this.assert.equal(result.value.length, 2, "initial number of array item inputs")
})
.click(".json-schema-form-item-add")
.elements("css selector", ".json-schema-form-item", function (result) {
this.assert.equal(result.value.length, 3, "number of array item inputs after clicking add")
})
.click(".json-schema-form-item-remove")
.click(".json-schema-form-item-remove")
.click(".json-schema-form-item-remove")
.elements("css selector", ".json-schema-form-item", function (result) {
this.assert.equal(result.value.length, 0, "number of array item inputs after removing all items")
})
.click(".json-schema-form-item-add")
.setValue(".json-schema-form-item input", "myValue123")
.click("button.execute")
.pause(100)
.assert.containsText(".request-url pre", "http://localhost:3230/test?fields=myValue123")
client.end()
})
})
openapi: '3.0.0'
info:
description: >-
Repro API
title: Repro API
version: '1.0'
paths:
/test:
get:
summary: Test get
parameters:
- name: fields
in: query
required: false
explode: false
schema:
type: array
items:
type: string
style: form
example:
- friends
- family
responses:
200:
description: Success!
content:
application/json:
schema:
type: object
properties:
id:
type: integer
name:
type: string
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册