Skip to content

Commit

Permalink
fix: 2.0 object parameter validation (#5583)
Browse files Browse the repository at this point in the history
  • Loading branch information
shockey authored Sep 2, 2019
1 parent 7b737f6 commit 4ebbc04
Showing 1 changed file with 15 additions and 22 deletions.
37 changes: 15 additions & 22 deletions src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ export const validatePattern = (val, rxPattern) => {

// validation of parameters before execute
export const validateParam = (param, value, { isOAS3 = false, bypassRequiredCheck = false } = {}) => {

let errors = []
let required = param.get("required")

Expand Down Expand Up @@ -527,31 +528,23 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec
let booleanCheck = type === "boolean" && (value || value === false)
let numberCheck = type === "number" && (value || value === 0)
let integerCheck = type === "integer" && (value || value === 0)

let oas3ObjectCheck = false

if(isOAS3 && type === "object") {
if(typeof value === "object" && value !== null) {
oas3ObjectCheck = true
} else if(typeof value === "string") {
oas3ObjectCheck = true
}
// Disabled because `validateParam` doesn't consider the MediaType of the
// `Parameter.content` hint correctly.
// } else if(typeof value === "string") {
// try {
// JSON.parse(value)
// oas3ObjectCheck = true
// } catch(e) {
// errors.push("Parameter string value must be valid JSON")
// return errors
// }
// }
}
let objectCheck = type === "object" && typeof value === "object" && value !== null
let objectStringCheck = type === "object" && typeof value === "string" && value

// if(type === "object" && typeof value === "string") {
// // Disabled because `validateParam` doesn't consider the MediaType of the
// // `Parameter.content` hint correctly.
// try {
// JSON.parse(value)
// } catch(e) {
// errors.push("Parameter string value must be valid JSON")
// return errors
// }
// }

const allChecks = [
stringCheck, arrayCheck, listCheck, fileCheck, booleanCheck,
numberCheck, integerCheck, oas3ObjectCheck
numberCheck, integerCheck, objectCheck, objectStringCheck,
]

const passedAnyCheck = allChecks.some(v => !!v)
Expand Down

0 comments on commit 4ebbc04

Please sign in to comment.