Skip to content

fix: allOf that narrows an enum, and one-option oneOf with inline models - #1499

Draft
pomykalakyle wants to merge 2 commits into
openapi-generators:mainfrom
pomykalakyle:fix/value-allof-and-duplicate-models-main
Draft

pomykalakyle wants to merge 2 commits into
openapi-generators:mainfrom
pomykalakyle:fix/value-allof-and-duplicate-models-main

Conversation

@pomykalakyle

Copy link
Copy Markdown

Fixes #1498 and #1375.

Two schema shapes that currently fail to generate:

  1. An allOf where every part is a value, like a $ref to an enum plus enum: [AWS]. It used to be built as a model and failed with "Cannot take allOf a non-object". Now its parts are merged with merge_properties.
  2. A one-option oneOf pointing at an object with inline models. The single-$ref shortcut queues that object twice, so its inline models were built twice and the second one failed as a duplicate. Now, when the exact same schema is built again under the same name, the existing class is reused.

To be upfront: an AI agent (Claude) wrote this while I was debugging our own spec. I've checked that it fixes our spec (about 220 endpoints) and the small examples in the linked issues. The existing tests give the same results with and without the change on my machine. There are no new tests yet, so this can't merge as is. It's a draft to show the approach.

A oneOf with a single $ref queues the referenced model for processing a second
time, so its inline models are built twice and the second build fails as a
duplicate class name. Reuse the existing class when the same schema is built
again under the same name.
An allOf whose parts are all values, such as a reference to an enum plus
`enum: [ONE_VALUE]`, was built as a model and failed with "Cannot take allOf a
non-object". Merge its parts with merge_properties, as allOf already does for
model properties.
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.

allOf that narrows an enum fails with "Cannot take allOf a non-object"

1 participant