OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.48k stars 6.5k forks source link

[BUG][Typescript][Axios/Fetch] Wrong generated code for array of items using FormData (multipart/form-data) #18853

Closed jeandonaldroselin closed 3 months ago

jeandonaldroselin commented 4 months ago

Bug Report Checklist

Description

I use open api spec 3 to define api to define two attributes :


I use a Typescript Axios in one project and Typescript Fetch in another project,

Theses projects are consuming almost the same (PHP) API endpoints.

But the typescript-axios and typescript-fetch generators generates a code that does not build properly theses array attributes.

This is the generated code :

# For typescript axios
formParams.append('mediasToAdd', element as any);
formParams.append('mediasToDelete', element as any);
# For typescript fetch
localVarFormParams.append('mediasToAdd', element);
localVarFormParams.append('mediasToDelete', element);

This parameters is not considered as array when submitting to a PHP API.

But it should be :

# For typescript axios
formParams.append('mediasToAdd[]', element as any);
formParams.append('mediasToDelete[]', element as any);
# For typescript fetch
localVarFormParams.append('mediasToAdd[]', element);
localVarFormParams.append('mediasToDelete[]', element);

the consequence is that on API side theses values are received as simple attributes instead as arrays.


Following the previous screenshot the API will receive :

openapi-generator version

I use exactly @openapitools/openapi-generator-cli@1.0.18-5.0.0-beta2

OpenAPI declaration file content or url

Capture d’écran 2024-04-24 à 17 54 45

Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

The problem is located in theses files =>