swagger-api / swagger-api/swagger-codegen

[erlang-client] Extra commas in generated lists

Open
#8,582 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When an API method has a mix of required and optional parameters the generated code will include spurious commas.

Optional:
 * offset
 * limit
 * sort
 * order
 * format
 * fields

Required:
 * timezone

Generated code snippet

    QS = lists:flatten([{<<"timezone">>, Timezone}])++[{X, maps:get(X, _Optional)} || X <- [, 'offset', 'limit', 'sort', 'order', 'format', 'fields'], maps:is_key(X, _Optional)],

Note, if I change the order of the fields in the swagger json/yaml (define the required field after the optional fields), the comma will appear in the 'required' section instead

Swagger-codegen version

2.3.1

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i /tmp/swagger.json -l erlang-client --additional-properties packageName=test

Suggest a fix/enhancement

This appears to be because the params are handled as a single array, and the {{^first}}, {{/-first}} method for injecting the commas does not work inside a filtered list (required/not required)

(at least according to https://github.com/samskivert/jmustache#-first-and--last)

Maybe splitting the params out into two separate arrays of required and optional would help

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

Start at the erlang-client generator invoked through swagger-codegen-cli.jar and trace how required and optional parameters are rendered in the generated query-string list. Reproduce the issue with an API method containing both parameter types, then verify that generated Erlang code contains no spurious commas.

Written by the indexing model from the issue text.

Assessment

Tech stack
erlang
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.