OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.02k stars 6.6k forks source link

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

Open imyixiao opened 7 months ago

imyixiao commented 7 months ago

Bug Report Checklist

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
imyixiao commented 7 months ago

however if the allof only has one item, it will be fine.

   Cat:
      type: object
      allOf:
        - $ref: "#/components/schemas/Kitty"