Bug Report Checklist
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:
- Checkout
- ./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: '|'});
}
}
Bug Report Checklist
Description
When using the
typescript-angulargenerator with a query parameter defined astype: arraywithuniqueItems: true, the generator produces a method signature withSet<string>. In 7.17.0, the generated service code correctly iterated over theSetusing.forEach()and added each element to the query parameters. In 7.18.0, the refactored code passes the entireSetobject toaddToHttpParams, which usesArray.isArray(value)to detect collections. SinceArray.isArray(new Set())returnsfalse, theSetfalls 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
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/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. Runreproduce.shto:Related issues/PRs
Setserialization issues in typescript-angular (covers request/response bodies too)Suggest a fix
The
addToHttpParamsmethod inapi.base.service.mustacheneeds to handleSetin addition toArray. A minimal fix would be to add avalue instanceof Setcheck alongsideArray.isArray(value):