Bug
When unusedComponents cleanup recurses and a component type becomes completely empty (all entries removed in a previous pass), the traversal crashes with:
TypeError: Cannot read properties of undefined (reading 'includes')
at openapi-format.js:759
The overlay file is not involved — the crash occurs with unusedComponents alone.
Root cause
Line 759 in openapi-format.js:
if (stripUnused.includes(this.path[1]) && unusedComp[this.path[1]].includes(this.key)) {
On the first recursion pass, unusedComp is built from component types present in the spec at that point. If a type (e.g. securitySchemes) is completely emptied during that pass, it is absent from unusedComp on the second pass. stripUnused still references it, so unusedComp[this.path[1]] is undefined rather than [].
Fix
if (stripUnused.includes(this.path[1]) && (unusedComp[this.path[1]] ?? []).includes(this.key)) {
Reproduction
Any spec where:
- A component type has only one entry (e.g. a single security scheme)
- That entry becomes unused after other components are removed
- The unusedComponents recursion runs a second pass after the type is fully emptied
Version
openapi-format 1.31.0
Bug
When unusedComponents cleanup recurses and a component type becomes completely empty (all entries removed in a previous pass), the traversal crashes with:
TypeError: Cannot read properties of undefined (reading 'includes')
at openapi-format.js:759
The overlay file is not involved — the crash occurs with unusedComponents alone.
Root cause
Line 759 in openapi-format.js:
On the first recursion pass, unusedComp is built from component types present in the spec at that point. If a type (e.g. securitySchemes) is completely emptied during that pass, it is absent from unusedComp on the second pass. stripUnused still references it, so unusedComp[this.path[1]] is undefined rather than [].
Fix
Reproduction
Any spec where:
Version
openapi-format 1.31.0