swagger-api / swagger-api/swagger-codegen
[ELIXIR] Bad generate client method with parameter type file
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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