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.61k forks source link

[BUG][typescript-node] additionalProperties are ignored #14661

Open fetis opened 1 year ago

fetis commented 1 year ago

Bug Report Checklist

Description

additionalProperties for components from schema are completely ignored and missed in the output

openapi-generator version

6.3.0

OpenAPI declaration file content or URL

In #/components/schemas

      "PizzaDto": {
        "type": "object",
        "required": [
          "id",
          "name",
          "ingredients"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "ingredients": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id"
              ],
              "properties": {
                "id": {
                  "type": "string"
                }
              }
            }
          }
        },
        "additionalProperties": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
Generation Details

The schema above with default options produces

export class PizzaDto extends null<String, Array> {
    'id': string;
    'name': string;
    'ingredients': Array<PizzaDtoIngredientsInner>;
}

Please note that strange extends null and missed additional props

The expected output should be smth like this

export class PizzaDto  {
    'id': string;
    'name': string;
    'ingredients': Array<PizzaDtoIngredientsInner>;
    [key: string]: string[] | any
}
Steps to reproduce
  1. Run generation with the provided schema
  2. Check the model in pizzaDto.ts
Related issues/PRs

The correct generation was introduced in this PR https://github.com/OpenAPITools/openapi-generator/issues/4698 but it's broken now.

Suggest a fix

Check the previous implementation of borrow it from typescript-angular (it does it correctly)

jaydeep987 commented 10 months ago

any status on this issue ?

mvarchdev commented 8 months ago

Some status?

fetis commented 8 months ago

@jaydeep987 @mvarchdev I don't have any updates on this

cabp-ec commented 1 month ago

@jaydeep987 @mvarchdev SOLUTION: instead of passing parameters in the command line, use a config file (as mentioned here), then it works flawlessly =)

TL;TR: 2024, October 31st and this still happens. When you use --additional-properties it complains about every single param to be unexpected; when you use e.g. -packageName or --packageName it throws the same error. So, additional properties are indeed being ignored or purposefully not allowed for specific generators (I'm using PHP); which is a bit cumbersome because we have 4 different API Clients to build, every one has the same package name and namespaces, then we have to manually change each one.