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
21.24k stars 6.43k forks source link

[BUG][typescript-axios] Enum parameter with default value is processed incorrectly since 7.1.0 #17335

Open Naktibalda opened 9 months ago

Naktibalda commented 9 months ago

Bug Report Checklist

Description

Upgrade to 7.1.0 broke handling of enum parameter with default value - instead of passing as primitive value, it is iterated as object now and generates funny URL with query string ?0=d&1=e&2=s&3=c

    allOf:
        - $ref: "#/components/schemas/SortOrderEnum"
        - default: desc
openapi-generator version

7.1.0

OpenAPI declaration file content or url
- schema:
    $ref: "#/components/schemas/SortOrderEnum"
    required: false
    name: score
    in: query
- schema:
    allOf:
        - $ref: "#/components/schemas/SortOrderEnum"
        - default: desc
    required: false
    name: createdAt
    in: query

Generates this code:

if (score !== undefined) {
    localVarQueryParameter['score'] = score;
}

if (createdAt !== undefined) {
    for (const [key, value] of Object.entries(createdAt)) {
        localVarQueryParameter[key] = value;
    }
}

Previous (correct) code:

if (score !== undefined) {
    localVarQueryParameter['score'] = score;
}

if (createdAt !== undefined) {
    localVarQueryParameter['createdAt'] = createdAt;
}
Generation Details
npx openapi-generator-cli generate --generator-key xxx

openapitools.json

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.1.0",
    "generators": {
      "xxx": {
        "generatorName": "typescript-axios",
        "inputSpec": "https://xxx/api/swagger/specification.yaml",
        "output": "generated/api/xxx",
        "generateAliasAsModel": true
      }
    }
  }
}
Related issues/PRs

Caused by #16898

Naktibalda commented 9 months ago

as a workaround we removed default values from enum parameters in our parameter schema.

macjohnny commented 9 months ago

@Naktibalda thanks, do you want to implement a fix?