Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
martkaa opened this issue Apr 26, 2024 · 0 comments
Open

Comments

@martkaa
Copy link

martkaa commented Apr 26, 2024

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"
                }
              }
            }
          }
        }
      }
    },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant