swagger-api / swagger-api/swagger-codegen

[ELIXIR] Bad generate client method with parameter type file

Open
#4,957 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Elixir help wanted Issue: Bug
Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

I generated client API for ELIXIR use swagger-codegen-cli-2.2.2.jar after that I saw code method and I think is some bug when we have in swagger.json parameter (in) type file. Inside the code that parameter dosen't have any transformation, it's treated like normal string. I set header content-type:multipart/form-data in request but this nothing change.

Swagger-codegen version

swagger-codegen-cli-2.2.2.jar

Swagger declaration file content or url
.....
"/{relObjId}": {
"post": {
"operationId": "add",
"summary": "add Image into system",
"tags": [
"image"
],
"consumes": [
"multipart/form-data"
],
"produces": [
"application/json"
],
"parameters": [
{
"name": "relObjId",
"in": "path",
"description": "object ID",
"required": true,
"type": "string"
},
{
"name": "file",
"in": "formData",
"description": "image file",
"required": true,
"type": "file"
},
{
"name": "format",
"in": "formData",
"description": "target format \"jpg\" (default) or \"png\"",
"type": "string"
},
{
"name": "description",
"in": "formData",
"description": "image description",
"type": "string",
"maxLength": 200
},
{
"name": "author",
"in": "formData",
"description": "image author",
"type": "string"
},
{
"name": "number",
"in": "formData",
"description": "image number",
"type": "integer"
},
{
"name": "additionalData",
"in": "formData",
"description": "addititional data as json",
"type": "string"
}
]
.....
Command line used for generation

java -jar swagger-codegen-cli-2.2.2.jar generate -i swagger.json -l elixir -o client_elixir

below generated method with second parameter type file

def add(rel_obj_id, file, format, description, author, number, additional_data) do
    method = [method: :post]
    url = [url: "/#{rel_obj_id}"]
    query_params = []
    header_params = []
    body_params = []
    form_params = [body: Enum.map_join([{:"file", file}, {:"format", format}, {:"description", description}, {:"author", author}, {:"number", number}, {:"additionalData", additional_data}], "&", &("#{elem(&1, 0)}=#{elem(&1, 1)}"))]
    params = query_params ++ header_params ++ body_params ++ form_params
    opts = []
    options = method ++ url ++ params ++ opts

    request(options)
  end

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied swagger-codegen-cli-2.2.2.jar command with the example Swagger declaration and inspect the generated Elixir add/7 method. Trace the Elixir generator path for the formData parameter whose type is file; done means the generated client handles it as multipart file data rather than a normal string or form-encoded value.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.