OpenAPITools / OpenAPITools/openapi-generator
[BUG] [TYPESCRIPT] HttpFile param is Serialized+Strignifyed but it makes the TS client crashing
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
I'm supposed to upload a file (binary) with a PUT method, but the swagger-codegen generate a wrong TS function for my PUT function :

Here it should not Serialize nor Stringify my File, because it create this error on the client's side :

Instead, it should pass the dataSourceRequestData directly to the setBody()
openapi-generator version
latest, as of today on June 21, 2021
OpenAPI declaration file content or url
The .yml part of the route that produces this problematic code is :
/datasources/{dataSourceId}/data:
put:
consumes:
- 'application/octet-stream'
- 'text/csv'
- 'text/plain'
tags:
- 'api-metadata'
summary: 'Add data to a datasource.'
operationId: 'putDataSourceData'
parameters:
- in: 'path'
name: 'dataSourceId'
required: true
type: 'string'
pattern: '^[\w:-]+$'
description: 'Data source identifier.'
- in: 'body'
name: 'dataSourceRequestData'
description: 'Datasource data'
required: true
schema:
type: string
format: binary
Generation Details
The generation command is
docker run --rm -u "$(USER_GROUP)" -v "$(PWD)":/src openapitools/openapi-generator-cli:latest \
-i /src/api/flattened.yml \
-g typescript \
-o /src/build/package/ts-client
Steps to reproduce
Run the above command with the above .yml
Related issues/PRs
No issue/PR related
Suggest a fix
I have actually no idea what could be the problem. Maybe there is a configuration I missed, but I more think this case should be automatically handled.
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 flattened.yml and regenerate the client using the provided Docker command, then inspect the generated TypeScript PUT method under build/package/ts-client. Trace how the binary body schema is handled and verify that the generated client passes the file data directly to setBody() without serialization or stringification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, 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