ferdikoomen / openapi-typescript-codegen

NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
MIT License
2.91k stars 519 forks source link

getFormData causes issue in submitting files #1989

Open tidaldp opened 8 months ago

tidaldp commented 8 months ago

https://github.com/ferdikoomen/openapi-typescript-codegen/blob/e2d6be10f0ffd59c9ae5dd9d76ccf2d57acd97aa/src/templates/core/functions/getFormData.hbs#L2

We're using openapi-typescript-codegen on a project and one of our PUT endpoints has the following requestBody spec:

"requestBody": {
    "content": {
        "multipart/form-data": {
            "schema": {
                "required": [
                    "file"
                ],
                "type": "object",
                "properties": {
                    "file": {
                        "type": "string",
                        "format": "binary"
                    }
                }
            }
        }
    }
},

We use axios and generate a formData object to pass a file on the request like so:

import FormData from 'form-data';

const formData = new FormData();
formData.append('file', <file buffer>, <file name>);

The getFormData code intercepts this and creates a new formData object that axios attempts to use, but it throws an error trying to read the name of the file. Over-riding this code to simply return options.formData resolves this. It's not really clear why getFormData is manipulating the inbound formData object in the first place, is this necessary?

jordanshatford commented 6 months ago

Check out our fork of this repository @hey-api/openapi-ts. We have fixed this issue in v0.32.1. If you run into any further issues, open an issue in our repository. Thanks.