Skip to content

feat: make enum union/intersection generation more configurable #1633

Closed

Activity

  1. mromaszewicz commented on Sep 26, 2026

    @mromaszewicz
    Member

    This is now configurable on main, with the new schema-merging-behavior: v3 (#2572). A value must match every member of an allOf, so v3 keeps only the enum values the members have in common, and reports an error when they have none. The x-oapi-codegen-enum-merge: union extension asks for all the members' values instead, for a composition that adds values to an enum:

    ExtendedStatus:
      x-oapi-codegen-enum-merge: union
      allOf:
        - $ref: '#/components/schemas/Status'   # enum: [active, inactive]
        - enum: [archived]

    This generates active, inactive and archived. The extension goes on the schema with the allOf, or on a member's property that refines a property; docs/extensions.md has the details. v2 is unchanged: it always takes all the values, and ignores the extension.

    To try it, set this in your configuration:

    compatibility:
      schema-merging-behavior: v3

    There's no release with v3 yet, so you'll need the latest main, for example go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@main --config=config.yaml spec.yaml. docs/schema-merging.md describes how v3 differs from v2. v3 is an option for now, and we plan to make it the default once it has been tested for a while, so we're eager to hear your feedback: whether it works with your specs, and anything it generates that you didn't expect.


    This message was generated by AI.

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

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