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.58k stars 6.52k forks source link

[BUG][TypeScript-Angular] Multipart/form-data object with file gets sent as stringified JSON #15771

Open MatejMijoski opened 1 year ago

MatejMijoski commented 1 year ago

Bug Report Checklist

Description

I have a multipart/form-data endpoint which has a picture object with a file field (binary). The problem with this is that the picture objects gets stringified as a JSON object. Is there a work around for this? I'm using openapitools to generate the models and create the services in Angular, and I'm getting an error when I try to generate: Model FileUploadRequest not generated since it's marked as unused (due to form parameters) and 'skipFormModel' (global property) set to true (default)

openapi-generator version

I'm using the openapi-generator 6.2.1

OpenAPI declaration file content or url
"post": {
   "requestBody": {
     "content": {
       "multipart/form-data": {
         "schema": {
            "$ref": "#/components/schemas/UserRequest"
         }
       }
     },
     "required": true
  },

This is the schema for the request body:

"UserRequest": {
   "type": "object",
   "properties": {
      "picture": {
         "$ref": "#/components/schemas/FileUploadRequest"
   },

And this is the schema for the picture field.

"FileUploadRequest": {
   "type": "object",
   "description": "Serializer class for File uploads.",
   "properties": {
     "file": {
        "type": "string",
        "format": "binary",
        "writeOnly": true
     },
Generation Details

yarn openapi-generator generate -i ./swagger.json -g typescript-angular -c -c ./openapitools.config.json which raise Model FileUploadRequest not generated since it's marked as unused (due to form parameters) and 'skipFormModel' (global property) set to true (default)

Related issues/PRs

Could not find any.

goors commented 1 year ago

Same here.