-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[BUG][typescript-angular] Query parameters with uniqueItems: true (Set) are not added to HTTP query params #23434
Description
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: stringGeneration Details
docker run --rm -v "${PWD}:/work" openapitools/openapi-generator-cli:v7.18.0 generate \
-i /work/openapi.yaml \
-g typescript-angular \
-o /work/generatedNo 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:
- Checkout
- ./reproduce.sh
Related issues/PRs
- [BUG][typescript-angular] Angular service doesn't convert uniqueItems to set #14055 — General
Setserialization issues in typescript-angular (covers request/response bodies too) - Typescript-Angular: Fix several query parameters serialization issues #22459 — PR that introduced the regression by refactoring query param serialization in 7.18.0
- [BUG][typescript-angular] 7.12.0 refactoring changes behaviour of http params #20998 — Previous query param serialization regression from 7.12.0 refactor
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: '|'});
}
}