Skip to content

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

Open

Description

@pomykalakyle

If a property narrows an enum with allOf (a $ref to the enum plus a shorter enum list), the generator drops the model, along with every model that references it.

components:
  schemas:
    CloudProvider:
      type: string
      enum: [AWS, AZURE]
    Region:
      type: object
      required: [provider]
      properties:
        provider:
          allOf:
            - $ref: '#/components/schemas/CloudProvider'
            - enum: [AWS]

On 0.29.1 this gives Cannot take allOf a non-object and Region is dropped. In our spec, a handful of these ended up dropping models used by 20 endpoints.

I'd expect provider to come out as CloudProvider, ideally limited to AWS. merge_properties already merges two enums like this when they come from an object-level allOf. It just never gets called when the allOf sits on the property itself, because that case goes straight to ModelProperty.build.

I opened a possible fix in #1499. Same caveat as there: an AI agent wrote it and it has no tests yet.

Activity

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