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

File upload with additional parameters not supported #57

Open
pmiddend opened this issue Jan 9, 2024 · 1 comment
Open

File upload with additional parameters not supported #57

pmiddend opened this issue Jan 9, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@pmiddend
Copy link

pmiddend commented Jan 9, 2024

I have an OpenAPI spec with the following request:

"/api/files": {
      "post": {
        "tags": [
          "files"
        ],
        "summary": "Create File",
        "operationId": "create_file_api_files_post",
        "requestBody": {
          "content": {
            "multipart/form-data": {
              "schema": {
                "$ref": "#/components/schemas/Body_create_file_api_files_post"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonCreateFileOutput"
                }
              }
            }
          },
          "422": {
            "description": "Validation Error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HTTPValidationError"
                }
              }
            }
          }
        }
      }

Where the body is defined as:

"Body_create_file_api_files_post": {
        "properties": {
          "file": {
            "type": "string",
            "format": "binary",
            "title": "File"
          },
          "description": {
            "type": "string",
            "title": "Description"
          }
        },
        "type": "object",
        "required": [
          "file",
          "description"
        ],
        "title": "Body_create_file_api_files_post"
      }

When I give that to elm-open-api it produces:

-- config.body is "{ body : Bytes.Bytes }"
createFileApiFilesPost config =
    Http.request
        { method = "POST"
        , headers = []
        , expect = Http.expectJson config.toMsg decodeJsonCreateFileOutput
        , body = Http.bytesBody "multipart/form-data" config.body
        , timeout = Nothing
        , tracker = Nothing
        , url = "/api/files"
        }
@wolfadex
Copy link
Owner

Looks like I need to implement https://package.elm-lang.org/packages/elm/http/latest/Http#multipartBody for Content-Type: multipart/form-data.

@wolfadex wolfadex added the bug Something isn't working label Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants