openapi-generator: [BUG][typescript-fetch] Generating incorrect types
When using openapi-generator to generate a typescript-fetch API from this specification:
openapi-generator generate -i https://api.demo.kaizenep.com/swagger.json -g typescript-fetch -o kaizen-api
The generated code has incorrect types where “List” is referenced. For example line 182 and 219 of output apis/EventsApi.ts
async postEventSearchRaw(requestParameters: PostEventSearchRequest): Promise<runtime.ApiResponse<Array>> {
async postEventSearch(requestParameters: PostEventSearchRequest): Promise<Array> {
This should be:
async postEventSearchRaw(requestParameters: PostEventSearchRequest): Promise<runtime.ApiResponse<List>> {
async postEventSearch(requestParameters: PostEventSearchRequest): Promise<List> {
this is using openapi-generator 4.0.3
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 10
- Comments: 23 (12 by maintainers)
@Bakkiyaraj A general workaround is to replace
GlobalFetch['fetch']withWindowOrWorkerGlobalScope['fetch']. The correct code is generated if you use the--additional-properties=typescriptThreePlus=trueflag during generation@janniclas I’m confused: shouldn’t TS3+ be the default?
An option to generate code for typescript 3+ was introduced, which should fix that
So if I comment out that line, it generates the correct types.
However I still have to make a manual change to get it to compile without error, that I might as well mention here, I have to replace GlobalFetch with WindowOrWorkerGlobalScope in src/runtime.ts
Have just discovered this is an Error in production mode, it’s a warning only for development compilation, so it is important to me to get this resolved.
So I am back to hand editing the
ArraytoListto get this to work.Related: https://github.com/OpenAPITools/openapi-generator/issues/9973