swagger-api / swagger-api/swagger-codegen
GET @ApiParam(value="myList", allowMultiple = true) List<String> myList
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
I declared my GET API in Java8 as follows:
@ApiParam(value = "myList", allowMultiple = true) @RequestParam(value = "myList", required = false) List<String /MyType as JSON/> myList
Multiple &myList= params in requests are accepted and ok like that.
However the String-Items contain Json serialized objects like (for reading reasons non-encoded as follows): {"myValue":"85", myEnum":["X"]}
And I get a deserialization behaviour which seems buggy to me:
- OK: if I send 2 &myList items -> myList will contain 2 items in my service (even with commas)
- OK: if I send 1 &myList item (without comma separation in the param), for e.g. {"value":"8507100"} -> myList will contain 1 &myList item in my service
- NOK: if I send 1 &myList item (with comma separation), for e.g. {"myValue":"85", myEnum":["X"]} -> myList will contain 2 items where I expect 1 item only (the comma lead to 2 separated items instead of one including the comma):
myList[0] -> {"value":"85"
myList[1] -> "myEnum":["X"]}
I tried several settings for @ApiParam but it makes no difference:
- collectionFormat="multi"
- type="string" or type="array"
Please let me know if my declaration is insufficient or if it is a bug (what I suppose currently).
I have a nasty workaround for all 3 sample cases above, but I think it is correct just by chance only:
List myDeserializedList = jacksonMapper.readValue(myList.toString(),
new TypeReference<List>() { });
Another problem is the specification of @ApiParam(..,example = "{"myValue":"85","myEnum":["X"]}") for lists, they are not visible in "try it out" by adding an item.
Remark:
- I am fully aware that parameters as JSON-String-objects do not please everyone (it is not about this topic here)
Swagger-codegen version
Springfox-swagger2 v2.9.2
Swagger-annotations v1.5.22
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 by reproducing the @ApiParam and @RequestParam declaration with Springfox-swagger2 v2.9.2 and Swagger annotations v1.5.22, testing repeated parameters and comma-containing JSON strings. Check how these annotations describe list serialization and how the example is rendered in “try it out”; done means the behavior is explained or corrected and the list example is visible as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100