Skip to content

Multipart formdata with file input gets wrapped in object when generated #705

@martkaa

Description

@martkaa

This is a multipart form data with file input. I am trying to post images to a given trip id. I think there is an issue with how the multipart form data endpoint is generated:

What swagger-typescript-api generates:

tripImageCreate: (
            id: string,
            data: {
                tripImageFiles: File[]
            },
            params: RequestParams = {}
        ) =>
            this.request<TripModel, string>({
                path: `/api/trip/${id}/image`,
                method: 'POST',
                body: data,
                type: ContentType.FormData,
                format: 'json',
                ...params,
            }),

How it should be generated (this works):

 tripImageCreate: (
            id: string,
            data: File[],
            params: RequestParams = {}
        ) =>
            this.request<TripModel, string>({
                path: `/api/trip/${id}/image`,
                method: 'POST',
                body: data,
                type: ContentType.FormData,
                format: 'json',
                ...params,
            }),

This is the swagger.json for the endpoint that works fine when i post image files in the swagger gui.

"/api/trip/{id}/image": {
      "post": {
        "tags": [
        XX
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "style": "simple",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "required": [
                  "tripImageFiles"
                ],
                "type": "object",
                "properties": {
                  "tripImageFiles": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "binary"
                    }
                  }
                }
              },
              "encoding": {
                "tripImageFiles": {
                  "style": "form"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TripModel"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions