thim81 / openapi-format

Format an OpenAPI document by ordering, formatting and filtering fields.
MIT License
77 stars 14 forks source link

Remove empty paths filter throws null error #96

Closed wsocha closed 6 months ago

wsocha commented 6 months ago

Hi! I tried to use the package to filter my openapi schema but I'm getting TypeError: Cannot read properties of null (reading 'includes') from this line in openapi-format.js.

if (this.parent && this.parent.key === 'paths' && !httpVerbs.some(i => this.keys.includes(i))) {

In my api specification I have a request body schema that has paths among its properties so when this line of code is hit, this.key is "type", this.parent.key is "paths" but this.keys is null and thats why the null exception. I guess you wanted this validation to be run only when traversing paths=endpoints, not some paths property. Some more strict check should be made to make sure it's only executed when it's on the "first-level" paths, e.g.:

this.parent.path.length === 1  && this.parent.path[0] === 'paths' // this.parent.path === ['paths']
thim81 commented 6 months ago

hi @wsocha

Thanks for reporting this issue. I have just released version 1.15.2, which contains a fix for this error.

wsocha commented 6 months ago

Hi @thim81, thank you very much for the fix and the release.