swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.04k stars 6.03k forks source link

[Spring] doesn't generate default value for type array #3395

Open diega opened 8 years ago

diega commented 8 years ago
Description

Having a query parameter of type array and defaultValue, doesn't set the defaultValue field for the generated @RequestParam and @ApiParam annotations

Swagger-codegen version

master

Swagger declaration file content or url
swagger: '2.0'
info:
  version: "1.0.0"
  title: Title was not specified
host: 'localhost:9090'
basePath: /base
schemes:
  - http
paths:
  /base/foo:
    get:
      responses:
        '200':
          description: Success
      operationId: getFoo
      parameters:
        - in: query
          name: params
          required: false
          type: array
          items:
            type: string
          collectionFormat: csv
          default:
            - 0759
            - 0722
            - 6543
  /base/bar:
    get:
      responses:
        '200':
          description: Success
      operationId: getBar
      parameters:
        - in: query
          name: params
          required: false
          type: string
          default: "0759, 0722, 6543"
Command line used for generation

$ java -Dapis -jar swagger-codegen-cli.jar generate -i test.yml -l spring --additional-properties interfaceOnly=true -o swagger-output/

Steps to reproduce
@javax.annotation.Generated(value = "class io.swagger.codegen.languages.SpringCodegen", date = "2016-07-18T13:13:54.400-03:00")

@Api(value = "base", description = "the base API")
public interface BaseApi {

    @ApiOperation(value = "", notes = "", response = Void.class, tags={  })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "Success", response = Void.class) })
    @RequestMapping(value = "/base/bar",
        method = RequestMethod.GET)
    ResponseEntity<Void> getBar(@ApiParam(value = "", defaultValue = "0759, 0722, 6543") @RequestParam(value = "params", required = false, defaultValue="0759, 0722, 6543") String params);

    @ApiOperation(value = "", notes = "", response = Void.class, tags={  })
    @ApiResponses(value = {
        @ApiResponse(code = 200, message = "Success", response = Void.class) })
    @RequestMapping(value = "/base/foo",
        method = RequestMethod.GET)
    ResponseEntity<Void> getFoo(@ApiParam(value = "") @RequestParam(value = "params", required = false) List<String> params);

}
wing328 commented 8 years ago

I don't think default value of array/map is supported at the moment. We may need to update the swagger parser in order to support that.

cc @cbornet @ePaul