OpenAPITools / OpenAPITools/openapi-generator
[BUG] [typescript-axios] Upload file with multipart misses to add boundary with node
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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using typescript-axios in a node environment, it's not able to upload a image because axios does not automatically add the boundary to the header, ref see here.
openapi-generator version
2.1.6
OpenAPI declaration file content or url
openapi: 3.0.1
info:
title: Bug API
version: 1.0.0
tags:
- name: image
description: Upload a image
paths:
/image:
put:
tags:
- image
summary: Update current map image
operationId: setImage
requestBody:
content:
multipart/form-data:
schema:
properties:
file:
type: string
format: binary
description: The file to upload
responses:
200:
description: Image successful uploaded
Generation Details
npx @openapitools/openapi-generator-cli generate -i bug-spec.yaml -g typescript-axios --additional-properties supportsES6=true -o generated
Steps to reproduce
Execute the command above and take a look at ImageApiAxiosParamCreator:54.
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
Related issues/PRs
Suggest a fix
I already have an idea how it could be fixed, but I have to say that I only have beginner experience, so please check if it makes sense.
if (typeof((localVarFormParams as any).getHeaders) === 'function') {
const headers = (localVarFormParams as any).getHeaders();
for (const [key, value] of Object.entries(headers)) {
localVarHeaderParameter[key] = value;
}
} else {
localVarHeaderParameter['Content-Type'] = 'multipart/form-data';
}
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
Reproduce the issue with the provided OpenAPI declaration and typescript-axios generation command, then inspect ImageApiAxiosParamCreator:54 in the generated output. Verify the Node multipart upload sends the boundary in its Content-Type header; the issue is done when the generated client uploads the image successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nodejs, typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100