Skip to content

Conversation

@schickling
Copy link

Summary

This PR fixes a bug where the generator crashes on valid OpenAPI 3.1 specifications that use boolean schemas ("items": false or "items": true).

Fixes #75

Problem

OpenAPI 3.1 adopted JSON Schema 2020-12, which allows boolean schemas. When defining strict tuples:

  • "items": false means no additional items beyond prefixItems are allowed
  • "items": true means any additional items are allowed

The generator was crashing with:

TypeError: Cannot use 'in' operator to search for 'type' in false

Solution

Added proper handling for boolean schemas throughout the codebase:

  1. Type guards in cleanupSchema() - Check if schema is boolean/object before property access
  2. Early returns in addRefs() - Skip processing for non-object schemas
  3. Boolean handling in toSource() - Convert true to Unknown, false returns none
  4. Updated itemsSchema() - Handle boolean values for items
  5. Added onUnknown() transformer - Generate proper types for true schemas

Testing

Test Fixtures Added

Created test-fixtures/boolean-schema-test.json with test cases for:

  • Strict tuples with "items": false
  • Open tuples with "items": true
  • Nested arrays with boolean schemas
  • Mixed schemas combining boolean and object schemas

Minimal Reproduction

Repository with minimal repro: https://github.com/schickling-repros/openapi-gen-boolean-schema-bug

Before fix:

npx @tim-smart/openapi-gen -s minimal-repro.json -n TestClient
# TypeError: Cannot use 'in' operator to search for 'type' in false

After fix:

npx @tim-smart/openapi-gen -s minimal-repro.json -n TestClient
# ✅ Successfully generates client code

OpenAPI 3.1 adopted JSON Schema 2020-12, which allows boolean schemas.
This fix properly handles `"items": false` (no additional items) and
`"items": true` (any additional items) in array/tuple validation.

Changes:
- Add type guards in cleanupSchema() to handle boolean values
- Add early returns in addRefs() for non-object schemas
- Add guards in toSource() to handle boolean schemas
- Implement onUnknown() transformer method for true schemas
- Update itemsSchema() to handle boolean values
- Add test fixtures for boolean schema validation

Fixes tim-smart#75

Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
@schickling schickling marked this pull request as ready for review September 14, 2025 16:09
@skoshx
Copy link

skoshx commented Oct 16, 2025

Friendly bump :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants