swagger-api / swagger-api/swagger-codegen

[JAVA][RxJava][Retrofit2] Query parameters are generated as path parameters

Open
#9,419 4 comments 3 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

The Java code generator is generating Query parameters as if they were path parameters.

Swagger-codegen version

3.0.8

Swagger declaration file content or url
/Reference/Countries:
    get:
      tags:
        - Reference
      description: 'TODO: Add Description'
      operationId: CountryDialingCodesGet
      parameters:
        - name: CountryCode
          in: query
          description: ''
          required: false
          style: form
          explode: true
          schema:
            type: string
        - name: CountryName
          in: query
          description: ''
          required: false
          style: form
          explode: true
          schema:
            type: string
Command line used for generation

java -jar swagger-codegen-cli-3.0.8.jar generate -i "custom.json" -l java -o samples/client/java --library retrofit2 -c "swagger_rxjava_config.json"

With the config being:

{
  "library": "retrofit2",
  "artifactId": "swagger-petstore-retrofit2-rx2",
  "useRxJava": true,
  "hideGenerationTimestamp": true
}

And this is the generated code:

public interface ReferenceApi {
  /**
   * 
   * TODO: Add Description
   * @param countryCode  (optional)
   * @param countryName  (optional)
   * @return Call<CountryDialingCodes>
   */
  @GET("Reference/Countries")
  Observable<CountryDialingCodes> countryDialingCodesGet(
          @Path("CountryCode") String countryCode, @Path("CountryName") String countryName
  );
}
Suggest a fix/enhancement

The generated code should have

@Query

instead of

@Path

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

Run the shown swagger-codegen CLI command with custom.json, the Java generator, and the retrofit2 library, using swagger_rxjava_config.json. Inspect the generated ReferenceApi interface and trace the parameter annotation generation; done means the query parameters use @Query instead of @Path.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.