Skip to content

[java spring] Doesn't support different response models #4693

Description

@stevecookform3
Description

If you have a schema that has multiple responses with different models, the generated controller code only supports the first model.

eg. using the simple pet example (and changing the 'default' response to '400'):

      responses:
        '200':
          description: pet response
          schema:
            type: array
            items:
              $ref: '#/definitions/pet'
        '400':
          description: unexpected error
          schema:
            $ref: '#/definitions/errorModel'

Generates the following interface:

@ApiOperation(value = "", notes = "Returns all pets from the system that the user has access to", response = Pet.class, responseContainer = "List", tags={  })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "pet response", response = Pet.class),
        @ApiResponse(code = 400, message = "unexpected error", response = Pet.class) })
    @RequestMapping(value = "/pets",
        produces = { "application/json", "application/xml", "text/xml", "text/html" }, 
        consumes = { "application/json" },
        method = RequestMethod.GET)
    ResponseEntity<List<Pet>> findPets(@ApiParam(value = "tags to filter by") @RequestParam(value = "tags", required = false) List<String> tags,
        @ApiParam(value = "maximum number of results to return") @RequestParam(value = "limit", required = false) Integer limit);

Note that the error model isnt referenced anywhere in the generated code, and the response is set to ResponseEntity<List<Pet>> rather than the more generic Reponse class.

Swagger-codegen version

Latest head. Also the current version on http://editor.swagger.io/#/

Command line used for generation

generate -v -i ./swagger.yaml -l spring -o .

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions