From 40bd720eb4b6c62c67a330190eaed985e63eefae Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Tue, 28 Nov 2017 22:19:53 -0600 Subject: [PATCH] Correctly validate OAS3 parameters that lack a `schema` --- src/core/utils.js | 7 +++++-- test/core/utils.js | 7 ++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 70dd3cfe..5f86f6d4 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -473,6 +473,9 @@ export const validateParam = (param, isXml, isOAS3 = false) => { let required = param.get("required") let paramDetails = isOAS3 ? param.get("schema") : param + + if(!paramDetails) return errors + let maximum = paramDetails.get("maximum") let minimum = paramDetails.get("minimum") let type = paramDetails.get("type") @@ -480,7 +483,7 @@ export const validateParam = (param, isXml, isOAS3 = false) => { let maxLength = paramDetails.get("maxLength") let minLength = paramDetails.get("minLength") let pattern = paramDetails.get("pattern") - + /* If the parameter is required OR the parameter has a value (meaning optional, but filled in) @@ -506,7 +509,7 @@ export const validateParam = (param, isXml, isOAS3 = false) => { let err = validatePattern(value, pattern) if (err) errors.push(err) } - + if (maxLength || maxLength === 0) { let err = validateMaxLength(value, maxLength) if (err) errors.push(err) diff --git a/test/core/utils.js b/test/core/utils.js index 73861845..5248af1c 100644 --- a/test/core/utils.js +++ b/test/core/utils.js @@ -321,14 +321,11 @@ describe("utils", function() { } it("should check the isOAS3 flag when validating parameters", function() { - // This should "skip" validation because there is no `schema.type` property + // This should "skip" validation because there is no `schema` property // and we are telling `validateParam` this is an OAS3 spec param = fromJS({ value: "", - required: true, - schema: { - notTheTypeProperty: "string" - } + required: true }) result = validateParam( param, false, true ) expect( result ).toEqual( [] )