swagger-api / swagger-api/swagger-codegen
[Spring] doesn't generate default value for type array
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
- Generate stubs
- Open swagger-output/src/main/java/io/swagger/api/BaseApi.java
- See differences between the two generated methods
Generated stub
@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);
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the test.yml declaration and regenerate the Spring output using the command shown, then inspect swagger-output/src/main/java/io/swagger/api/BaseApi.java. Compare the array-valued getFoo annotations with the scalar getBar annotations and trace the Spring generator path that produces them. Done means the array parameter's default value appears in both generated annotations without changing the scalar case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100