fix: respect OAS3 parameter default values (#4561)

* add test cases

* refactor default setters into own function

* reach into `schema` for default value in OAS3

* remove exclusive test
This commit is contained in:
kyle
2018-05-16 00:27:14 -07:00
committed by GitHub
parent 55fdeeb810
commit c8480a827a
2 changed files with 91 additions and 17 deletions

View File

@@ -0,0 +1,67 @@
/* eslint-env mocha */
import React from "react"
import { List, fromJS } from "immutable"
import expect, { createSpy } from "expect"
import { render } from "enzyme"
import ParameterRow from "components/parameter-row"
describe("bug #4557: default parameter values", function(){
it("should apply a Swagger 2.0 default value", function(){
const paramValue = fromJS({
description: "a pet",
type: "string",
default: "MyDefaultValue"
})
let props = {
getComponent: ()=> "div",
specSelectors: {
security(){},
parameterWithMeta(){ return paramValue },
isOAS3(){ return false }
},
operation: {get: ()=>{}},
onChange: createSpy(),
param: paramValue,
onChangeConsumes: () => {},
pathMethod: [],
getConfigs: () => { return {} },
specPath: List([])
}
render(<ParameterRow {...props}/>)
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue")
})
it("should apply an OpenAPI 3.0 default value", function(){
const paramValue = fromJS({
description: "a pet",
schema: {
type: "string",
default: "MyDefaultValue"
}
})
let props = {
getComponent: ()=> "div",
specSelectors: {
security(){},
parameterWithMeta(){ return paramValue },
isOAS3(){ return true }
},
operation: {get: ()=>{}},
onChange: createSpy(),
param: paramValue,
onChangeConsumes: () => {},
pathMethod: [],
getConfigs: () => { return {} },
specPath: List([])
}
render(<ParameterRow {...props}/>)
expect(props.onChange).toHaveBeenCalledWith(paramValue, "MyDefaultValue")
})
})