swagger-api / swagger-api/swagger-codegen

[Java] Extra comma in arguments when generating Retrofit2 api

Open
#8,517 0 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 I tries to generate apis using Retrofit2 I got uncompilable code because of extra commas

// skipped

public interface UserApi {
  
  /**
   * Get information about user
   * An application should invoke this method just after the open session step to know the user's account description.  A server application which is interested by retrieving data of the user using this method must invoke it only when it is necessary and then cache the result. 
   * @param alcUserId Identifier of the Session (required)
   * @param loginName Login name of the user to retrieve the account description. (required)
   * @return Call<User>
   */

  @GET("users/{loginName}")
  Call<User> getUserInfo(
     ,@retrofit2.http.Path("loginName") String loginName
  );

}

Note comma before @retrofit2.http.Path("loginName") String loginName.

Swagger-codegen version

3.0.0-SNAPSHOT

Swagger declaration file content or url

Yaml file is here:
https://gist.github.com/Klemsus/f58803b8c94832705dec4b3895f27d49

Command line used for generation
java -jar swagger-codegen-cli.jar generate -l java -o rest -i userapi.yml -Dlibrary=retrofit2
Steps to reproduce
  1. Generate API
  2. Open in IDE - it shows an error
Suggest a fix/enhancement

The problem is in cookie type argument that parsed into empty argument (and this is correct behavior, I don't want this as argument), but comma still appears.

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

Reproduce the issue with the linked YAML and the shown swagger-codegen command using the Retrofit2 library, then inspect how the Java API method arguments are rendered when the cookie type argument is empty. Done means the generated UserApi.java has no leading comma before the loginName parameter and compiles successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.