Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: object parameter validation #5583

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object values are commonly JSON/XML strings, which we need to accommodate for.


// 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