Skip to content

[BUG] OpenAPI Normalizer - Unnecessary allOf wrapping for oneOf/anyOf items with discriminator labels #22578

@lucy66hw

Description

@lucy66hw

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The OpenAPINormalizer wraps oneOf and anyOf items into allOf compositions when they have discriminator labels (e.g., title field).

openapi-generator version
OpenAPI declaration file content or url
Pet:
  oneOf:
    - title: dog  
      description: "A dog pet"
      $ref: '#/components/schemas/Dog'
    - title: cat  
      description: "A cat pet"
      $ref: '#/components/schemas/Cat'
    - title: bird  
      description: "A bird pet"
      $ref: '#/components/schemas/Bird'

Actual:

Pet:
  oneOf:
    - allOf:  
        - $ref: '#/components/schemas/Dog'
      title: dog
      description: "A dog pet"
    - allOf:  
        - $ref: '#/components/schemas/Cat'
      title: cat
      description: "A cat pet"
    - allOf:  
        - $ref: '#/components/schemas/Bird'
      title: bird
      description: "A bird pet"
  discriminator:
    propertyName: petType

expected. For oneOf/anyOf discriminator labels, we should leave them unchanged.

Pet:
  oneOf:
    - title: dog 
      description: "A dog pet"
      $ref: '#/components/schemas/Dog'
    - title: cat  
      description: "A cat pet"
      $ref: '#/components/schemas/Cat'
    - title: bird  
      description: "A bird pet"
      $ref: '#/components/schemas/Bird'
  discriminator:
    propertyName: petType
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Implement context-aware normalization. skip normalization for oneOf/anyOf items, but keep normalizing regular properties.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions