You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When typescript-fetch generates the TypeScript for ExampleModel, multiple things happen at the same time:
The uniqueStringSet property is correctly declared as type Set<string>.
The ExampleModelFromJSONTyped function is incorrectly generated. In this function, the uniqueStringSet property is just assigned the value of json['uniqueStringsSet'] (which is an array), instead of first setting it to new Set(json['uniqueStringsSet']).
The end result is the following:
The client thinks the property is of type Set<string> (correct).
The actual type is Array (incorrect).
If you try to access a property such as size on the value, the result will be undefined (as that doesn't exist on an array), which is a runtime bug.
If you try to access an array property such as length, the TypeScript compiler will complain, as it expects you to use size instead (length doesn't exist on Set), which is a compile-time bug.
There doesn't appear to be a workaround for this, except for manually setting the value of uniqueStringSet after the ExampleModel object has been created. This suggested workaround doesn't work for typescript-fetch.
openapi-generator version
7.8.0, although the bug appears to be in previous versions too.
OpenAPI declaration file content or url
N/A, please see example above.
Generation Details
You can reproduce this with the default client generation settings. For example, I run this command to generate my client:
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i [MY OpenAPI SPEC URI HERE] \
-g typescript-fetch \
-o /local/generated
Steps to reproduce
Generate a typescript-fetch client from an OpenAPI spec containing the above structure.
For my own API spec, I declared the following class in my C# .NET API:
This looks like a similar issue for typescript-rxjs, but it was opened 2 and a half years ago and not resolved. The provided workaround doesn't seem to work for typescript-fetch (explained here):
Essentially the bug seems to be caused by isPrimitiveType being true for an array when it contains primitive types. This therefore means the templating is bypassed for the new Set() logic.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
Take the following snippet from an OpenAPI spec:
When
typescript-fetch
generates the TypeScript forExampleModel
, multiple things happen at the same time:uniqueStringSet
property is correctly declared as typeSet<string>
.ExampleModelFromJSONTyped
function is incorrectly generated. In this function, theuniqueStringSet
property is just assigned the value ofjson['uniqueStringsSet']
(which is an array), instead of first setting it tonew Set(json['uniqueStringsSet'])
.The end result is the following:
Set<string>
(correct).Array
(incorrect).size
on the value, the result will beundefined
(as that doesn't exist on an array), which is a runtime bug.length
, the TypeScript compiler will complain, as it expects you to usesize
instead (length
doesn't exist onSet
), which is a compile-time bug.There doesn't appear to be a workaround for this, except for manually setting the value of
uniqueStringSet
after theExampleModel
object has been created. This suggested workaround doesn't work fortypescript-fetch
.openapi-generator version
7.8.0
, although the bug appears to be in previous versions too.OpenAPI declaration file content or url
N/A, please see example above.
Generation Details
You can reproduce this with the default client generation settings. For example, I run this command to generate my client:
Steps to reproduce
Generate a
typescript-fetch
client from an OpenAPI spec containing the above structure.For my own API spec, I declared the following class in my C# .NET API:
Related issues/PRs
This looks like a similar issue for
typescript-rxjs
, but it was opened 2 and a half years ago and not resolved. The provided workaround doesn't seem to work fortypescript-fetch
(explained here):Not 100% sure if these other issues are related, but they might be:
Set
fails at runtime #18986Suggest a fix
Draft PR here (WIP): #19521
Essentially the bug seems to be caused by
isPrimitiveType
beingtrue
for an array when it contains primitive types. This therefore means the templating is bypassed for thenew Set()
logic.The text was updated successfully, but these errors were encountered: