Skip to content

fix: #1905 handle oneOf in nested allOf schemas - #1904

Closed
matgr1 wants to merge 5 commits into
oapi-codegen:mainfrom
matgr1:fix-one-of-nesting
Closed

matgr1 wants to merge 5 commits into
oapi-codegen:mainfrom
matgr1:fix-one-of-nesting

Conversation

@matgr1

@matgr1 matgr1 commented Feb 14, 2025 •

Copy link
Copy Markdown

the main purpose of this PR is to fix the situation where oneOf gets lost in deeply nested allOf schemas, for example:

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

see added comments in merge_schemas.go for explanation

other fixes/improvements:

  • includes anyOf as well as oneOf during schema merge
  • improves duplicate typename log message (includes path and detailed diff)
  • removes unused parameter in mergeOpenapiSchemas

@matgr1
matgr1 requested a review from a team as a code owner February 14, 2025 18:13
@matgr1
matgr1 marked this pull request as draft February 14, 2025 18:13
@matgr1
matgr1 force-pushed the fix-one-of-nesting branch from 18f41f2 to 040c7aa Compare February 14, 2025 18:52
@matgr1
matgr1 force-pushed the fix-one-of-nesting branch from 040c7aa to eb82ae9 Compare February 14, 2025 19:02
@matgr1 matgr1 changed the title fix: fully flatten allOf; handle oneOf/anyOf more correctly fix: #1905 fully flatten allOf; handle oneOf/anyOf more correctly Feb 14, 2025
@matgr1 matgr1 changed the title fix: #1905 fully flatten allOf; handle oneOf/anyOf more correctly fix: #1905 handle oneOf in nested allOf schemas Feb 14, 2025
@matgr1
matgr1 marked this pull request as ready for review February 14, 2025 20:04
@mromaszewicz

Copy link
Copy Markdown
Member

Thank you for the fix and the detailed explanation, @matgr1, and apologies for the slow follow-up.

#1905 has since been fixed on main by #2471, which reworked how nested allOf/anyOf/oneOf schemas are merged so that a union inside a deeply nested allOf is no longer lost. The merging code this PR patches was replaced in the process, so it can no longer be applied as it is.

Since the issue is resolved, I am closing this PR. If you still have a schema where a nested oneOf or anyOf goes missing with a current release, please open an issue with the spec.


This message was drafted with AI assistance (Claude) and reviewed by a maintainer.

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.

2 participants