OpenAPITools / OpenAPITools/openapi-generator
[BUG] TypeScript Fetch client doesn't support multipart/form-data body
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
Generated TypeScript code doesn't properly handle FormData, the definition below generates:
if (file !== undefined) {
localVarFormParams.set('file', file as any);
}
localVarHeaderParameter['Content-Type'] = 'application/x-www-form-urlencoded';
When it should generate
const formData = new FormData();
formData.append("file", file);
localVarFormParams.body = formData;
localVarHeaderParameter['Content-Type'] = 'multiparm/form-data';
openapi-generator version
3.3.4
"/api/Documents": {
"post": {
"tags": [
"Documents"
],
"operationId": "Upload",
"consumes": [
"multipart/form-data"
],
"produces": [
],
"parameters": [
{
"name": "file",
"in": "formData",
"required": false,
"type": "file"
}
],
"responses": {
"200": {
"description": "Success"
}
}
}
(for JSON code), so it becomes more readable. If it is longer than about ten lines,
please create a Gist (https://gist.github.com) or upload it somewhere else and
link it here.
-->
Command line used for generation
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:v3.3.4 generate
-i "http://host.docker.internal/swagger/v1/swagger.json"
-g typescript-fetch
--type-mappings Date=string
-o /local/src/swagger
Steps to reproduce
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the typescript-fetch generator and reproduce the issue using the supplied OpenAPI snippet and v3.3.4 Docker command. Compare the generated FormData handling and Content-Type with the expected multipart behavior; done means the generated client sends the file as multipart/form-data rather than application/x-www-form-urlencoded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100