Skip to content

TypeError: Cannot use 'in' operator on boolean schemas ("items": false) #75

@schickling

Description

@schickling

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.sh

The Problem

OpenAPI 3.1 adopted JSON Schema 2020-12, which allows boolean schemas. In array validation:

  • "items": false means no additional items beyond prefixItems are 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 different

Note: 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

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) { ... }

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions