a3.14_Infinity
a3.14_Infinity

Reputation: 5843

Why does swagger generate void methods for GET requests in client SDK?

  1. I used swagger codegen to generate client SDK in Java.
  2. For example:

    java -jar swagger-codegen-cli-2.2.1.jar generate -i http://weburl/apidocs/swagger.json -l java -o output

  3. In the generated files, there is a ModelAPI.java, where in the method (corresponding to HTTP GET request) returns void.

  4. I expected the POJO object (corresponding to json of the response) to be returned, but void is returned.

  5. Is there a way to generate POJO objects, so that when I use the client SDK in my code, I can use the POJO object?

Am I missing something?

Upvotes: 2

Views: 2247

Answers (1)

a3.14_Infinity
a3.14_Infinity

Reputation: 5843

The output of swagger codegen is based on the input - swagger api specification.

The reason for void is because in the specification, for response: 200, schema was not specified.

For example:

responses:
        '200':
          description: successful operation
          schema:
            $ref: '#/definitions/Pet'

Please have a look at:

https://github.com/swagger-api/swagger-codegen/issues/3888

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L174-L177

Upvotes: 5

Related Questions