Skip to content

[BUG][TYPESCRIPT-AXIOS] Fields with uniqueItems: true generate Set<T>, but Set is serialized incorrectly (empty object) #21663

@MaestroNek

Description

@MaestroNek
Description

When using the typescript-axios generator, properties with uniqueItems: true in the OpenAPI spec are generated as Set<T> in the TypeScript models.

However, Set values are not serialized correctly when sent to the server. In serializeDataIfNeeded, the Set is passed to JSON.stringify, which results in {} — an empty object — instead of a JSON array.

This leads to incorrect request payloads and breaks API communication.

openapi-generator version

Tested with version 7.14.0

OpenAPI declaration file content or url
  components:
    schemas:
      ExampleModel:
        type: object
        properties:
          tags:
            type: array
            items:
              type: string
            uniqueItems: true
Generation Details
openapi-generator-cli generate -i ./openapi.yaml -g typescript-axios -o ./generated

Generated model:

tags?: Set<string>;
Steps to reproduce
  1. Use the OpenAPI schema above

  2. Generate the typescript-axios client

  3. Call any endpoint with tags: new Set(['a', 'b'])

  4. Observe the actual payload sent over the network

Expected result:

{ "tags": ["a", "b"] }

Actual result:

{ "tags": {} }
Related issues/PRs

Couldn't find related open issues specific to this problem.

Suggest a fix
  1. Serialize Set as Array inside serializeDataIfNeeded or related functions
  2. Or generate Array instead of Set by default for uniqueItems: true, or at least provide a config flag to do so

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions