feature: OAS3 object parameter support (#4563)

* render suitable interface for `type: object` parameters

* validate OAS3 object parameters correctly

* display parameter validation errors

* remove irrelevant css classes

* rm comment

* fix failing tests

* add validateParam tests

* add enzyme tests for object parameter rendering

* run actual tests first
This commit is contained in:
kyle
2018-05-16 22:48:44 -07:00
committed by GitHub
parent c8480a827a
commit c1007a287b
6 changed files with 209 additions and 9 deletions

View File

@@ -350,6 +350,12 @@ describe("utils", function() {
expect( result ).toEqual( expectedError )
}
const assertValidateOas3Param = (param, expectedError) => {
// for cases where you _only_ want to try OAS3
result = validateParam( fromJS(param), false, true )
expect( result ).toEqual( expectedError )
}
it("should check the isOAS3 flag when validating parameters", function() {
// This should "skip" validation because there is no `schema` property
// and we are telling `validateParam` this is an OAS3 spec
@@ -361,6 +367,92 @@ describe("utils", function() {
expect( result ).toEqual( [] )
})
it("validates required OAS3 objects", function() {
// valid object
param = {
required: true,
schema: {
type: "object"
},
value: {
abc: 123
}
}
assertValidateOas3Param(param, [])
// valid object-as-string
param = {
required: true,
schema: {
type: "object"
},
value: JSON.stringify({
abc: 123
})
}
assertValidateOas3Param(param, [])
// invalid object-as-string
param = {
required: true,
schema: {
type: "object"
},
value: "{{}"
}
assertValidateOas3Param(param, ["Parameter string value must be valid JSON"])
// missing when required
param = {
required: true,
schema: {
type: "object"
},
}
assertValidateOas3Param(param, ["Required field is not provided"])
})
it("validates optional OAS3 objects", function() {
// valid object
param = {
schema: {
type: "object"
},
value: {
abc: 123
}
}
assertValidateOas3Param(param, [])
// valid object-as-string
param = {
schema: {
type: "object"
},
value: JSON.stringify({
abc: 123
})
}
assertValidateOas3Param(param, [])
// invalid object-as-string
param = {
schema: {
type: "object"
},
value: "{{}"
}
assertValidateOas3Param(param, ["Parameter string value must be valid JSON"])
// missing when not required
param = {
schema: {
type: "object"
},
}
assertValidateOas3Param(param, [])
})
it("validates required strings", function() {
// invalid string
param = {
@@ -962,7 +1054,7 @@ describe("utils", function() {
expect(result).toEqual(Map([[ "minimum", "b"]]))
})
})
describe("deeplyStripKey", function() {
it("should filter out a specified key", function() {
const input = {
@@ -1065,8 +1157,7 @@ describe("utils", function() {
})
it("should sanitize a `data:` url", function() {
const res = sanitizeUrl(`data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGV
sbG8iKTs8L3NjcmlwdD4=`)
const res = sanitizeUrl(`data:text/html;base64,PHNjcmlwdD5hbGVydCgiSGVsbG8iKTs8L3NjcmlwdD4=`)
expect(res).toEqual("about:blank")
})