swagger-api / swagger-api/swagger-codegen

[JAVA] 3.0.65 java stub generates method with no return value for get endpoints if $ref is used

Open
#12,504 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

With 3.0.65 the methods that are generated for get endpoints (havent checked others) are not returning anything. Same specs worked with 3.0.64.

The generated code looks like this:

    public void whateverGet() throws ApiException {
        whateverGetWithHttpInfo();
    }

while with 3.0.64:

    public InlineResponse200 whateverGet() throws ApiException {
        ApiResponse<InlineResponse200> resp = whateverGetWithHttpInfo();
        return resp.getData();
    }

If i put the schema directly, without using the $ref, the generated code is having the return statement.

Swagger-codegen version

3.0.65

Swagger declaration file content or url
openapi: 3.0.1
paths:
  /whatever:
    get:
      responses:
        "200":
          $ref: "#/components/responses/WhateverGetResponse"

components: 
  responses: 
    WhateverGetResponse:
      description: test
      content:
        application/json:
          schema:
            type: object
            properties:
              name:
                type: string
Command line used for generation

java -jar ~/Downloads/swagger-codegen-cli-3.0.65.jar generate -i test.yaml -l java -o ./debug -DhideGenerationTimestamp=true

Steps to reproduce

just generate with 3.0.65

Related issues/PRs
Suggest a fix/enhancement

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 the issue with test.yaml and the listed swagger-codegen CLI command, then trace Java generation for the whateverGet endpoint and its referenced response. Done means a $ref response generates a return type and resp.getData() as in 3.0.64, without regressing inline schemas.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.