Gi60s / openapi-enforcer

Apache License 2.0
94 stars 22 forks source link

Using readOnly or writeOnly generate exception upon validation #109

Closed rafael-org closed 3 years ago

rafael-org commented 3 years ago

Since version 1.12.6 I get error messages like:

     TypeError: Cannot read property 'writeOnly' of undefined
      at schema.required.schema.required.filter.name (node_modules/openapi-enforcer/src/schema/validate.js:153:67)
     TypeError: Cannot read property 'readOnly' of undefined
      at schema.required.schema.required.filter.name (node_modules/openapi-enforcer/src/schema/validate.js:152:68)

I am able to make it work by changing:

if (options.readWriteMode === 'write' && !prop.readOnly) return true
if (options.readWriteMode === 'read' && !prop.writeOnly) return true

To something like:

if (options.readWriteMode === 'write' && prop && !prop.readOnly) return true
if (options.readWriteMode === 'read' && prop && !prop.writeOnly) return true
Gi60s commented 3 years ago

Thanks for the fix. I've published this with version 1.13.2.