OpenAPITools / OpenAPITools/openapi-generator

[BUG][Python] generate wrong allof class when the it has oneof nested inside

Open
#18,396 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • 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

when the allof class has nested oneof inside, the allof class will ignore oneof requirements and take in all the fields of the oneof classes

expected:

class Cat(BaseModel):
    """
    Kitty
    """
    # data type: Kitty1
    oneof_schema_1_validator: Optional[Kitty1] = None
    # data type: Kitty2
    oneof_schema_2_validator: Optional[Kitty2] = None
    actual_instance: Optional[Union[Kitty1, Kitty2]] = None
    one_of_schemas: Set[str] = { "Kitty1", "Kitty2" }
     color: Optional[StrictStr] = None

actual result

class Cat(BaseModel):
    """
    Cat
    """ # noqa: E501
    size: Optional[StrictInt] = None
    food: Optional[StrictInt] = None
    color: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["size", "food", "color"]
openapi-generator version

7.4

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  title: API
  description: api.
  version: 1.4.0

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Cat"
      responses:
        "200":
          description: Updated
components:
  schemas:
    Cat:
      type: object
      allOf:
        - $ref: "#/components/schemas/Kitty"
        - $ref: "#/components/schemas/Tiger"
    Kitty:
      type: object
      oneOf:
        - $ref: "#/components/schemas/Kitty1"
        - $ref: "#/components/schemas/Kitty2"
    Kitty1:
      type: object
      properties:
        size:
          type: integer
    Kitty2:
      type: object
      properties:
        food:
          type: integer
    Tiger:
      type: object
      properties:
        color:
          type: string
Generation Details

java -jar openapi-generator-cli-7.4.0.jar generate -i $spec_file -g python -o $output_folder --package-name $package_name

Steps to reproduce
Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/16150

Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the stated openapi-generator-cli 7.4.0 command with the YAML declaration and inspect the generated Python Cat model. Compare its allOf/oneOf handling with the expected validators and actual flattened fields, then review related issue 16150. Done means nested oneOf requirements are preserved while Tiger's color field remains included.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, python
Domain
api, backend-api-design, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.