-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[BUG][typescript-angular] Angular service doesn't convert uniqueItems to set #14055
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This bug also occurs in request payloads. If the swagger specification includes an array with unique items as request payload, it is passed as an empty object instead of the array that is expected.
Results into the following Model:
Which is fine, but the payload that is send is an empty object. Maybe due to the fact that JSON.stringify(new Set([1])) returns '{}'? |
We also encounter this issue. As we don't want to use hacky casts like It would be nice if there was one of these options:
|
I'm affected by this as well. full disclosure, I got the workaround from stackoverflow: |
Bug Report Checklist
Description
Running into a typing issue when using
uniqueItems
and an Angular service.When I have a schema that contains an array property with
uniqueItems
set to true, the generated typescript model is typed to aSet
.Schema
Generated Model
However, the corresponding generated Angular service does not do anything to convert the array that comes back from the API to a Set, so the result is a value that is typed to a set but actually contains an array. This breaks any consuming code that is using the correct type.
Return from the Angular Service
Example where this would break
We are currently converting the response to unknown and then to our own model to get around this issue.
openapi-generator version
6.2.1
OpenAPI declaration file content or url
https://github.com/jdgarvey/openapi-unique-items-bug/blob/main/spec.yml
Generation Details
npx openapi-generator-cli generate -g typescript-angular -i spec.yml -o output
Steps to reproduce
Reproduction repository: https://github.com/jdgarvey/openapi-unique-items-bug
You can view the spec there, then run
npx openapi-generator-cli generate -g typescript-angular -i spec.yml -o output
to update output if you want.Related issues/PRs
#11746
Suggest a fix
As far as I can tell, we would need to recursively traverse the httpClient response JSON and somehow convert arrays to sets if that corresponding property has uniqueItems: true.
The text was updated successfully, but these errors were encountered: