swagger-api / swagger-api/swagger-codegen

[JAVA][jaxrs-spec] @DefaultValue missing in API for query parameters

Open
#5,023 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
Swagger-codegen version

<= 2.2.3-SNAPSHOT (latest available here on master)

Swagger declaration file content or url
paths:
  /health:
    post:
      operationId: postHealth
      tags:
        - Health
      parameters:
        - name: phoey
          in: query
          type: string
          default: foobar
Command line used for generation

generate -l jaxrs-spec -i myapi.yaml -o jaxrs-spec-stub

Steps to reproduce

It always happens because the template swagger-codegen/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/queryParams.mustache doesn't output @DefaultValue("{{{defaultValue}}}")

I would normally expect to see:

    @POST
    @Produces({ "application/json" })
    @ApiOperation(value = "", notes = "", response = void.class, tags={ "Health" })
    @ApiResponses(value = { 
        @ApiResponse(code = 201, message = "Null response", response = void.class),
        @ApiResponse(code = 200, message = "unexpected error", response = void.class) })
    public Response postHealth(@QueryParam("phoey")  @DefaultValue("foobar") String phoey) {
    	return Response.ok().entity("magic!").build();
    }
Related issues

Not really, this one is simpler than the other "defaultValue" issues reported here.

Suggest a Fix

Change swagger-codegen/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/queryParams.mustache from

{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}} {{{dataType}}} {{paramName}}{{/isQueryParam}}

to

{{#isQueryParam}}@QueryParam("{{baseName}}"){{#useBeanValidation}}{{>beanValidationQueryParams}}{{/useBeanValidation}} {{#defaultValue}}@DefaultValue("{{{defaultValue}}}"){{/defaultValue}} {{{dataType}}} {{paramName}}{{/isQueryParam}}

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

Read swagger-codegen/modules/swagger-codegen/src/main/resources/JavaJaxRS/spec/queryParams.mustache and compare it with the supplied Swagger declaration. Run the jaxrs-spec generation command, then verify that the generated postHealth signature includes the default query-parameter annotation and value.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.