diff --git a/src/plugins/validate-semantic/validators/2and3/schemas.js b/src/plugins/validate-semantic/validators/2and3/schemas.js index 85a4cd4de16..85bf41658dc 100644 --- a/src/plugins/validate-semantic/validators/2and3/schemas.js +++ b/src/plugins/validate-semantic/validators/2and3/schemas.js @@ -23,6 +23,8 @@ export const validate2And3TypeArrayRequiresItems = () => (system) => { }) } + + export const validate2And3TypesInDefaultValuesMatchesWithEnum = () => (system) => { return system.validateSelectors .allSchemas() @@ -30,11 +32,15 @@ export const validate2And3TypesInDefaultValuesMatchesWithEnum = () => (system) = return nodes.reduce((acc, node) => { const schemaObj = node.node const { type } = schemaObj || {} + const isNullable = !!schemaObj.nullable const enumeration = schemaObj.enum if (enumeration !== null && typeof enumeration !== "undefined") { var enumIndex = 0 enumeration.forEach((element, index) => { var isValidFormat = true + if (element === null && isNullable) { + return + } if (type === "array" && (!Array.isArray(element) || element === null)) { isValidFormat = false enumIndex = index @@ -55,9 +61,10 @@ export const validate2And3TypesInDefaultValuesMatchesWithEnum = () => (system) = level: "warning", }) } + }) } return acc }, []) }) -} \ No newline at end of file +} diff --git a/test/unit/plugins/validate-semantic/2and3/schemas.js b/test/unit/plugins/validate-semantic/2and3/schemas.js index 3aa76a32fa2..df9c64cdd4b 100644 --- a/test/unit/plugins/validate-semantic/2and3/schemas.js +++ b/test/unit/plugins/validate-semantic/2and3/schemas.js @@ -514,4 +514,33 @@ describe(`values in Enum must be instance of the defined type`, () => { expect(allErrors.length).toEqual(0) }) }) + + it("should not return an error for a null value in a enum object when nullable is true type in OpenApi 3", () => { + const spec = { + openapi: "3.0.0", + "paths": { + "/pets": { + "get": { + "parameters": [ + { + name: "objectSample", + in: "query", + schema: { + type: "object", + nullable: true, + enum: [null] + } + }, + ] + } + } + } + } + + return validateHelper(spec) + .then(system => { + const allErrors = system.errSelectors.allErrors().toJS() + expect(allErrors.length).toEqual(0) + }) + }) }) \ No newline at end of file