fix(validateParam): validate JSON parameter values + support Parameter.content (#5657)

* improve(getParameterSchema): ParameterSchemaDescriptor pattern

* chore: update usage of `getParameterSchema`

* consider `Parameter.content` media type when validating JSON values
This commit is contained in:
kyle
2019-10-11 11:20:23 -07:00
committed by GitHub
parent 71a17f801e
commit 75a0e5d5dc
5 changed files with 190 additions and 51 deletions

View File

@@ -414,15 +414,15 @@ describe("utils", function() {
})
assertValidateOas3Param(param, value, [])
// // invalid object-as-string
// param = {
// required: true,
// schema: {
// type: "object"
// }
// }
// value = "{{}"
// assertValidateOas3Param(param, value, ["Parameter string value must be valid JSON"])
// invalid object-as-string
param = {
required: true,
schema: {
type: "object"
}
}
value = "{{}"
assertValidateOas3Param(param, value, ["Parameter string value must be valid JSON"])
// missing when required
param = {
@@ -458,14 +458,14 @@ describe("utils", function() {
})
assertValidateOas3Param(param, value, [])
// // invalid object-as-string
// param = {
// schema: {
// type: "object"
// }
// }
// value = "{{}"
// assertValidateOas3Param(param, value, ["Parameter string value must be valid JSON"])
// invalid object-as-string
param = {
schema: {
type: "object"
}
}
value = "{{}"
assertValidateOas3Param(param, value, ["Parameter string value must be valid JSON"])
// missing when not required
param = {
@@ -505,6 +505,108 @@ describe("utils", function() {
assertValidateParam(param, value, [])
})
it("handles OAS3 `Parameter.content`", function() {
// invalid string
param = {
content: {
"text/plain": {
schema: {
required: true,
type: "string"
}
}
}
}
value = ""
assertValidateOas3Param(param, value, ["Required field is not provided"])
// valid string
param = {
content: {
"text/plain": {
schema: {
required: true,
type: "string"
}
}
}
}
value = "test string"
assertValidateOas3Param(param, value, [])
// invalid (empty) JSON string
param = {
content: {
"application/json": {
schema: {
required: true,
type: "object"
}
}
}
}
value = ""
assertValidateOas3Param(param, value, ["Required field is not provided"])
// invalid (malformed) JSON string
param = {
content: {
"application/json": {
schema: {
required: true,
type: "object"
}
}
}
}
value = "{{}"
assertValidateOas3Param(param, value, ["Parameter string value must be valid JSON"])
// valid (empty object) JSON string
param = {
content: {
"application/json": {
schema: {
required: true,
type: "object"
}
}
}
}
value = "{}"
assertValidateOas3Param(param, value, [])
// valid (empty object) JSON object
param = {
content: {
"application/json": {
schema: {
required: true,
type: "object"
}
}
}
}
value = {}
assertValidateOas3Param(param, value, [])
// should skip JSON validation for non-JSON media types
param = {
content: {
"application/definitely-not-json": {
schema: {
required: true,
type: "object"
}
}
}
}
value = "{{}"
assertValidateOas3Param(param, value, [])
})
it("validates required strings with min and max length", function() {
// invalid string with max length
param = {