OpenAPITools / OpenAPITools/openapi-generator

[BUG][Java][Jaxrs-resteasy] Enum parameter in query badly generated

Open
#4,376 4 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Jaxrs-resteasy generator generates wrong code if api defines an enum in query parameters.

openapi-generator version

4.2.0

OpenAPI declaration file content or url
openapi: 3.0.0
servers:
  - url: 'http://petstore.swagger.io/v2'
info:
  description: >-
    This is a sample server Petstore server. For this sample, you can use the api key
    `special-key` to test the authorization filters.
  version: 1.0.0
  title: OpenAPI Petstore
paths:
  /pet/findByStatus:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      parameters:
        - name: status
          in: query
          description: Status values that need to be considered for filter
          required: true
          schema:
            $ref: '#/components/schemas/Status'
      responses:
        '200':
          description: OK
components:
  schemas:
    Status:
      type: string
      enum:
        - available
        - pending
        - sold
Command line used for generation

java -jar openapi-generator-cli-4.2.0.jar generate -i pet.yaml -g jaxrs-resteasy -o test

Steps to reproduce

Run the above command.

Generated code doesn't compile because in method signature, there is , allowableValues="available, pending, sold" between annotations.

    @GET
    @Path("/findByStatus")
    
    
    @io.swagger.annotations.ApiOperation(value = "Finds Pets by status", notes = "Multiple status values can be provided with comma separated strings", response = Void.class, tags={ "pet", })
    @io.swagger.annotations.ApiResponses(value = { 
        @io.swagger.annotations.ApiResponse(code = 200, message = "OK", response = Void.class) })
    public Response findPetsByStatus( @NotNull , allowableValues="available, pending, sold" @QueryParam("status") Status status,@Context SecurityContext securityContext)
    throws NotFoundException {
        return service.findPetsByStatus(status,securityContext);
    }
Suggest a fix

In queryParams.mustache file, removing {{#allowableValues}}, {{> allowableValues }}{{/allowableValues}} fix the issue.

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 the jaxrs-resteasy generator's queryParams.mustache template and reproduce the issue using the OpenAPI YAML and generation command in the report. Check the generated findPetsByStatus method signature; done means the generated Java code compiles without the misplaced allowableValues text.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.