swagger-api / swagger-api/swagger-codegen

[JAVA][Retrofit2][swagger-codegen-cli-3.0.4] Version 3.0.4 don't have the template fixes from swagger code gen 2.x

Open
#8,971 0 comments 4 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 using swagger-codegen-cli-3.0.4 and add for configuration that we want to use Retrofit2 as library and with the use of RxJava2 ('useRxJava2' at true).

We have an issue with the generation where a wrong annotation is used (retrofit2.http.Path instead of retrofit2.http.Query) This issue is already fixed since a very long time in the version 2. But it still present in the version 3.0.4.

I tried to fork the project to mirror the fix and make a merge-request for the v3 but the template files are not present anymore. In the source file for the v3.

I dezip the jar, in the file handlebars\Java\libraries\retrofit2\queryParams.mustache we should have
{{#is this 'query-param'}}@retrofit2.http.Query("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}}
instead of
{{#is this 'query-param'}}@retrofit2.http.Path("{{baseName}}") {{{dataType}}} {{paramName}}{{/is}}

A funny thing is that the files from the v2 are also present in the same jar and HAVE the related fixes.

Also there is a invalid character in /handlebars/Java/libraries/retrofit2/api_test.mustache . A letter f is not an ascii char but a really funny char who appeared like a wild pokemon.

Swagger-codegen version

swagger-codegen-cli-3.0.4-SNAPSHOT

Swagger declaration file content or url
openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  license:
    name: MIT
servers:
  - url: http://petstore.swagger.io/v1
paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets
      tags:
        - pets
      parameters:
        - name: limit
          in: query
          description: How many items to return at one time (max 100)
          required: false
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: A paged array of pets
          headers:
            x-next:
              description: A link to the next page of responses
              schema:
                type: string
          content:
            application/json:    
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
    post:
      summary: Create a pet
      operationId: createPets
      tags:
        - pets
      responses:
        '201':
          description: Null response
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
  /pets/{petId}:
    get:
      summary: Info for a specific pet
      operationId: showPetById
      tags:
        - pets
      parameters:
        - name: petId
          in: path
          required: true
          description: The id of the pet to retrieve
          schema:
            type: string
      responses:
        '200':
          description: Expected response to a valid request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Pets"
        default:
          description: unexpected error
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
components:
  schemas:
    Pet:
      required:
        - id
        - name
      properties:
        id:
          type: integer
          format: int64
        name:
          type: string
        tag:
          type: string
    Pets:
      type: array
      items:
        $ref: "#/components/schemas/Pet"
    Error:
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
        message:
          type: string

Command line used for generation

java -jar swagger-codegen-cli-3.0.4-20181205.061456-5.jar generate -i petstore.yaml -l java --library retrofit2 --api-package io.petstore.api --model-package io.petstore.model -o api/petstore -Dapis,models --additional-properties java8=true,dateLibrary=java8,useRxJava2=true

Steps to reproduce

Use the command and see.

Related issues/PRs
Suggest a fix/enhancement

For handlebars\Java\libraries\retrofit2\queryParams.mustache copy the content from Java\libraries\retrofit2\queryParams.mustache

Fix the wrong and funny character in _handlebars\Java\libraries\retrofit2\api_test.mustache by using the file from Java\libraries\retrofit2\api_test.mustache.

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 with handlebars/Java/libraries/retrofit2/queryParams.mustache and handlebars/Java/libraries/retrofit2/api_test.mustache, comparing them with the corresponding Java/libraries/retrofit2 files mentioned in the issue. Run the provided Java generation command with Retrofit2 and useRxJava2 enabled; done means query parameters use the Query annotation and the invalid character is removed from the generated test template.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, java
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.