OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When the request body is directly a set of strings (NOT wrapped in an object), the application crashes at runtime because the Set<string> is not converted to an Array first, thus it generates the JSON {}.
If the request body is wrapped in an object, then it works fine.
openapi-generator version
I am using the openapitools/openapi-generator-cli:latest Docker image.
I think the fix is partial, and does not support request bodies that are not wrapped in an object
Note that using the workaround --type-mappings='set=Array' as suggested in some related issues does NOT work, it results in a type-checking error.
The workaround I have to use for now is to wrap the request body in an object.
Then Array.from is used in the generated code.
But it adds an unnecessary layer in the model.
Bug Report Checklist
Description
When the request body is directly a set of strings (NOT wrapped in an object), the application crashes at runtime because the
Set<string>
is not converted to anArray
first, thus it generates the JSON{}
.If the request body is wrapped in an object, then it works fine.
openapi-generator version
I am using the
openapitools/openapi-generator-cli:latest
Docker image.OpenAPI declaration file content or url
The generated Typescript file is:
:warning: Notice
requestParameters['requestBody']
I think it should actually be something like (I'm no Typescript expert so maybe it should be slightly different):
Generation Details
Steps to reproduce
addPet({requestBody: new Set<string>(["a"])})
(it typechecks){}
instead of["a"]
Related issues/PRs
typescript-angular
, nottypescript-fetch
typescript-rxjs
Note that using the workaround
--type-mappings='set=Array'
as suggested in some related issues does NOT work, it results in a type-checking error.The workaround I have to use for now is to wrap the request body in an object. Then
Array.from
is used in the generated code. But it adds an unnecessary layer in the model.