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
20.81k stars 6.33k forks source link

[BUG][typescript-axios] Using the allOf description with a combination of $ref and an object results in a wrong typing #9162

Open olivierbeaulieu opened 3 years ago

olivierbeaulieu commented 3 years ago

Bug Report Checklist

Description

Using the typescript-axios generator fails to properly generate the client when using allOf with a combination of a $ref and an object.

openapi-generator version

5.1.0

OpenAPI declaration file content or url

swagger.yml:

openapi: 3.0.2
info:
  title: hello
  version: 1.0.0
components:
  schemas:
    SomeSchema:
      type: object
      properties:
        some_prop:
          type: integer
paths:
  /foobar:
    get:
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SomeSchema'
                  - type: object
                    properties:
                      foobar: 
                        type: string
Generation Details
openapi-generator-cli generate -i http://localhost:8000/swagger.yml -g typescript-axios -o foo
Steps to reproduce

1) Run the above script 2) Look at the generated api.ts 3) Notice that foobarGet returns AxiosPromise<SomeSchema & object>

I would expect the return type to be AxiosPromise<SomeSchema & { foobar?: string }>

auto-labeler[bot] commented 3 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

garvit14 commented 2 years ago

I am facing the same issue, @olivierbeaulieu were you able to find any fix or workaround for this issue?

olivierbeaulieu commented 2 years ago

We just avoided allOfs :(

btg5679 commented 2 years ago

Also Facing this issue

Mettbrot commented 3 months ago

Probably the same as https://github.com/OpenAPITools/openapi-generator/issues/16150

imyixiao commented 3 months ago

we are using version 7.4 for python, has a similar issue

// spec
  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

the cat class should be

    # 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" }

but we get:

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"]