swagger-api / swagger-api/swagger-codegen

[Java] [Retrofit2] Generator do not tolerate Enums as body parameters

Open
#7,461 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

While Retrofit2 allows @retrofit2.http.Body List<Enum> bodies, the generator creates @retrofit2.http.Body List<String>.

Swagger-codegen version

2.3

Swagger declaration file content or url
/users/{userId}/roles:
    put:
      operationId: updateUserRoles
      parameters:
        - name: userId
          in: path
          required: true
          type: string
        - in: body
          name: roles
          schema:
            type: array
            minItems: 0
            items:
              type: string
              enum: [SUPERUSER, TUTOR, STUDENT]
      responses:
        200:
          description: User roles have been updated

Generated retrofit2 + rx2 client code:

  @PUT("users/{userId}/roles")
  Completable updateUserRoles(
    @Path("userId") String userId, @Body List<String> roles
  );

Should be

  @PUT("users/{userId}/roles")
  Completable updateUserRoles(
    @Path("userId") String userId, @Body List<RolesEnum> roles
  );

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 by reproducing the Retrofit2 + Rx2 client generation with the Swagger declaration in this issue, then trace the generator templates or entry points that produce the updateUserRoles signature. Done means an enum type such as RolesEnum is retained for the array body parameter instead of String.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
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.