elm-open-api-cli
elm-open-api-cli copied to clipboard
File upload with additional parameters not supported
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"
}
Looks like I need to implement https://package.elm-lang.org/packages/elm/http/latest/Http#multipartBody for Content-Type: multipart/form-data.