Skip to content

[BUG][typescript-angular] Query parameters with uniqueItems: true (Set) are not added to HTTP query params #23434

@LeovR

Description

@LeovR

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

When using the typescript-angular generator with a query parameter defined as type: array with uniqueItems: true, the generator produces a method signature with Set<string>. In 7.17.0, the generated service code correctly iterated over the Set using .forEach() and added each element to the query parameters. In 7.18.0, the refactored code passes the entire Set object to addToHttpParams, which uses Array.isArray(value) to detect collections. Since Array.isArray(new Set()) returns false, the Set falls through to the object handling branch, and the query parameter values are never correctly serialized.

This is a regression introduced in 7.18.0 by PR #22459, which rewrote the query parameter serialization logic.

openapi-generator version

Broken: 7.18.0+
Last working: 7.17.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: Reproduction API
  version: 1.0.0
paths:
  /items:
    get:
      operationId: getItems
      summary: Get items filtered by tags
      parameters:
        - name: tags
          in: query
          required: false
          schema:
            type: array
            items:
              type: string
            uniqueItems: true
      responses:
        '200':
          description: A list of items
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                    name:
                      type: string
Generation Details
docker run --rm -v "${PWD}:/work" openapitools/openapi-generator-cli:v7.18.0 generate \
  -i /work/openapi.yaml \
  -g typescript-angular \
  -o /work/generated

No additional options or configuration required.

Steps to reproduce

Checkout the reproduction repo at:
https://github.com/LeovR/openapi-generator-typescript-angular-set

The repository includes a Karma + Jasmine test that calls getItems(new Set(['a', 'b'])) and asserts the query parameters are present. Run reproduce.sh to:

  1. Checkout
  2. ./reproduce.sh
Related issues/PRs
Suggest a fix

The addToHttpParams method in api.base.service.mustache needs to handle Set in addition to Array. A minimal fix would be to add a value instanceof Set check alongside Array.isArray(value):

} else if (Array.isArray(value) || value instanceof Set) {
    const arr = Array.isArray(value) ? value : Array.from(value);
    if (paramStyle === QueryParamStyle.Form) {
        return httpParams.set(key, arr, {explode: explode, delimiter: ','});
    } else if (paramStyle === QueryParamStyle.SpaceDelimited) {
        return httpParams.set(key, arr, {explode: explode, delimiter: ' '});
    } else {
        return httpParams.set(key, arr, {explode: explode, delimiter: '|'});
    }
}

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