swagger-api / swagger-api/swagger-codegen

[Java] Generation of Feign Client leads to incorrect Parameter Mapping when using snake_case parameters

Open
#8,268 3 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

with a snake_case Parameter, it seems that the generated Api files contains wrong Annotations to map the parameter.

  @RequestLine("GET /api/subscriptions/{subscription_id}")
  @Headers({
    "Content-Type: application/json",
    "Accept: application/json",
  })
  SubscriptionDetails getSubscription(@Param("subscriptionId") String subscriptionId);

as you can see, the @Param also contains the camelized version of the parameter, which leads to a wrong mapping (it seems that at runtime the parameter is seen as a form parameter, instead of a path parameter, as it doesnt fit the request line declaration).

is there some way to workaround this? I have read about a parameter to fix the namingProperty, but in general it would be okay for us, to have the parameters in the Java POJOS in correct camelCase, but the serialized/deserialized parameters should match the originally specified name. And I havent found it to work in our version, but maybe I configured it incorrectly.

Swagger-codegen version

2.2.2 We tried updating to a later version, but unfortunately they seemed to have incompatibilities in other features, which breaks our Unit-Tests.

Swagger declaration file content or url
 /api/subscriptions/{subscription_id}:
    get:
      operationId: getSubscription
      produces:
        - application/json
      parameters:
        - name: subscription_id
          in: path
          required: true
          type: string

Command line used for generation
<configuration>
              <language>java</language>
              <output>.</output>
              <configHelp>false</configHelp>
              <configOptions>
                <library>feign</library>
                <dateLibrary>joda</dateLibrary>
                <hideGenerationTimestamp>true</hideGenerationTimestamp>
                <interfaceOnly>true</interfaceOnly>
                <modelPropertyNaming>snake_case</modelPropertyNaming> <!-- seems to have no effect -->
                <keepUnderscores>true</keepUnderscores><!-- seems to have no effect -->
              </configOptions>
            </configuration>
Suggest a fix/enhancement

the point where the content of the @Param Annotation is set, should not contain the camlizedName, but the baseName of the Parameter, at least this is what I think is causing the problem.

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 generation with the provided Swagger path, snake_case parameter, Feign library, and configuration options. Inspect the generated API interface containing @RequestLine and @Param, then verify that the generated parameter mapping preserves the declared path name while the Java method remains usable with camelCase naming.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.