-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Description
The generator crashes when processing valid OpenAPI 3.1 specifications that use the JSON Schema boolean form "items": false for tuple validation.
Error
TypeError: Cannot use 'in' operator to search for 'type' in false
at cleanupSchema (/.../@tim-smart/openapi-gen/main.js:34827:16)
Minimal Reproduction
I've created a minimal reproduction repository: https://github.com/schickling-repros/openapi-gen-boolean-schema-bug
# Quick test
git clone https://github.com/schickling-repros/openapi-gen-boolean-schema-bug.git
cd openapi-gen-boolean-schema-bug
./reproduce.shThe Problem
OpenAPI 3.1 adopted JSON Schema 2020-12, which allows boolean schemas. In array validation:
"items": falsemeans no additional items beyondprefixItemsare allowed (strict tuple)- This is the correct way to define tuples in OpenAPI 3.1
Example schema that causes the crash:
{
"type": "array",
"items": {
"type": "array",
"items": false, // <-- Valid in OpenAPI 3.1, causes crash
"prefixItems": [
{ "type": "integer" },
{ "type": "number" }
]
}
}Current Workaround
Replace "items": false with "items": {}:
"items": {} // Works but semantically differentNote: This changes the semantics - {} allows additional items of any type, while false strictly forbids them.
Expected Behavior
The generator should handle boolean schemas correctly and generate proper TypeScript tuple types like [number, number].
Affected Projects
- S2 StreamStore OpenAPI spec: https://github.com/s2-streamstore/s2-protos/blob/main/s2/v1/openapi.json
- Any OpenAPI 3.1 spec using strict tuple validation
Suggested Fix
In the cleanupSchema function, check if the value is a boolean before using the in operator:
// Before
if ("type" in schema.items) { ... }
// After
if (typeof schema.items === "object" && schema.items !== null && "type" in schema.items) { ... }