Skip to content

codegen: Support for allOf intersections #619

@yogyam

Description

@yogyam

Description

Hey! I've been testing the new codegen feature (great work on this, btw!) and ran into an internal error when using allOf with multiple schemas to create intersection types.

Environment

  • CLI Version: 14.1.0
  • OS: macOS 15.5
  • Build: From source using make
  • Target: TypeScript

Minimal Reproduction Schema

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "allOf": [
    {
      "properties": {
        "name": { "type": "string" }
      }
    },
    {
      "properties": {
        "age": { "type": "integer" }
      }
    }
  ]
}

Command

jsonschema codegen schema.json --target typescript --name Person

Expected Behavior

Should generate a TypeScript interface combining both schemas:

{
  "error": "Rule condition holds after application: unnecessary_allof_wrapper"
}

The unnecessary_allof_wrapper optimization rule appears to be triggering incorrectly when allOf contains multiple schemas. The rule is designed to unwrap single-element allOf wrappers (e.g., { "allOf": [X] } → X), but the post-condition check seems to fail when processing actual intersection types.

Offer to Help

I'd be happy to work on a PR for this if you can point me in the right direction! I've already built the project locally and have test cases ready. Let me know if there's a specific approach you'd prefer for handling allOf intersections in the TypeScript codegen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions