acacode / swagger-typescript-api

Generate the API Client for Fetch or Axios from an OpenAPI Specification
MIT License
3.27k stars 354 forks source link

typescript reports errors with FormData since 13.0.10 #814

Closed jeremyriverain closed 2 months ago

jeremyriverain commented 3 months ago

I'm experiencing TypeScript errors that come from the generated http-client.ts.

Here are the errors:

Capture d’écran du 2024-07-01 12-26-26

My build passes with version 13.0.10 of swagger-typescript-api but not with version 13.0.11.

By comparing the 2 generated files, here are the differences I obtain:

Capture d’écran du 2024-07-01 12-23-06

The file on the left is the one generated by swagger-typescript-api version 13.0.11. It has TypeScript errors.

The file on the right does not have TypeScript error.

My project uses version 5.2 of typescript.

I think the bug is introduced by this commit: https://github.com/acacode/swagger-typescript-api/commit/0d80f8e6ea5a2420745841f8b9eb95faae0b4ffc

smorimoto commented 3 months ago

Provide specific reproducible example.

am-burban commented 3 months ago

Hey, I'm wondering what the intention of this change is. If I need to pass in an instance of FormData as the request body, why do I need the formatter then? It just recreates the FormData instance again (and possibly loses information, because it e.g. does not support he third parameter of FormData.prototype.append). For me the main use case of this formatter was, that I can pass in a plain object, that is transformed to a FormData instance. This is broken (by-design?) now, but imho shouldn't have happened in a patch release.

philippone commented 3 months ago

Hello @jeremyriverain ,

I guess you have to add "dom.iterable" into your tsconfig:

"compilerOptions": { "lib": ["esNext", "dom", "dom.iterable"],

svarion1 commented 3 months ago

Hi I second this bug. After the update the autogenerated code is generating in the http-client new code with Array.from instead of Object.keys. This then brings the same error as Jeremy.

I had already in my compilerOptions the "dom.iterable"

payammeyer commented 2 months ago

Same issue occurs with 13.0.12.

motionrus commented 2 months ago

I renamed the file from http-client.ts to api.d.ts and the error disappeared

AlexanderShabalinMaersk commented 2 months ago

I am wondering - will it just stay as it is? It is a breaking change in a patch version, right?

smorimoto commented 2 months ago

I don't think it was a breaking change, it was really just a fix. If someone could share a minimal reproduction example, I will take a look at it and provide some pointers.

benvd commented 2 months ago

I've created a reproducible example here: benvd/swagger-typescript-api-814.

smorimoto commented 2 months ago

@benvd Indeed! It was definitely a bug! I will revert the PR and release it as 13.0.16.

smorimoto commented 2 months ago

https://github.com/acacode/swagger-typescript-api/releases/tag/13.0.16