Skip to content

deeply nested oneOf gets lost when merging allOf #1905

Closed

Description

@matgr1

for the following schema:

{
  "allOf": [
    {
      "allOf": [
        {
          "oneOf": [
            { "properties": { "a_foo_one_of_0": { "type": "string" } } },
            { "properties": { "a_foo_one_of_1": { "type": "string" } } }
          ]
        }
      ]
    },
    { "properties": { "a_foo": { "type": "string" } } }
  ]
}

this gets generated:

// Foo defines model for Foo.
type Foo struct {
	AFoo *string `json:"a_foo,omitempty"`
}

when it should generate (helper functions omitted for brevity):

// Foo defines model for Foo.
type Foo struct {
	AFoo  *string `json:"a_foo,omitempty"`
	union json.RawMessage
}

// Foo0 defines model for .
type Foo0 struct {
	AFooOneOf0 *string `json:"a_foo_one_of_0,omitempty"`
}

// Foo1 defines model for .
type Foo1 struct {
	AFooOneOf1 *string `json:"a_foo_one_of_1,omitempty"`
}

note that above has been fixed (and unit test added) in #1904

Activity

  1. added a commit that references this issue on Feb 14, 2025
    ca3d45b
  2. campbellr commented on Jun 3, 2026

    @campbellr

    I've just hit the same issue while trying to upgrade from an older oapi-codegen version. I really want to turn off old-merge-schemas: true compatibility mode, but i have some schemas that have nested oneOf and anyOf, both of which get dropped.

  3. added a commit that references this issue on Jul 16, 2026
    823a7a7
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