swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
16.93k stars 6.03k forks source link

[TypeScript-Fetch] Invalid interface definition while setting additionalProperties as true #12388

Open NachiketaDhal opened 5 months ago

NachiketaDhal commented 5 months ago
Description

Compiling the following yaml into a TypeScript-Fetch client results in an interface with an incorrect type. Specifically when the additionalProperties is set to true.

Swagger-codegen version

SWAGGER_VERSION=3.0.55

Swagger declaration file content or url

Following is an example sample yaml file

  /api/v1/classes/{className}:
    post:
      operationId: op1
      tags:
        - tag1
      parameters:
        - name: className
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                prop1:
                  type: string
                prop2:
                  type: string
              additionalProperties: true

For an example let's say we have 2 interfaces

interface Interface1 {
    prop1: string,
    prop2: string,
}

interface Interface2 {
    [key: string]: any;
}

So in this case if I'm not passing additionalProperties flag the interface i.e. getting generated for requestBody is Interface1 else it is Interface2. But I'm looking for a combination that incorporates elements from both the interfaces.

Command line used for generation

java -jar ./swagger-codegen-cli.jar generate -i ./server/out/example.yaml -l typescript-axios -o ./server/out/api-client --additional-properties modelPropertyNaming=original enumPropertyNaming=original

Steps to reproduce

Compile a swagger API containing the definitions mentioned above into a typescript-fetch client.

Suggest a fix/enhancement

I'm looking for a combination that incorporates elements from both the interfaces.