Enum constraints and request parameters that are collections
On version 1.0.14 because we have not upgraded to spring 5 yet.
This looks like a combination of 181and 194 issues.
I have the case where I have an EnumSet as a parameter but I have tried this with List, Set and Arrays and they all come out the same.
public enum Color {
BLACK,
WHITE
}
Using the Color enum with an EnumSet as a parameter.
@RequestMapping(method = RequestMethod.POST)
public Set<Color> selectColors(
@CurrentSpringUser SpringUser springUser,
@RequestParam(name = "colors") EnumSet<Color> colors
{
return colors;
}
What it comes out as is
| Parameter | Type | Optional | Description |
|---|---|---|---|
| expand | Object | true |
I would expect it to come out as
| Parameter | Type | Optional | Description |
|---|---|---|---|
| expand | Array[String] | true | Must be one or more of [BLACK,WHITE] |
Also need to deal with the case of the Enum having a different "name" than the Enum
public enum Colors {
BLACK("Black"),
WHITE("White")
}
becomes
| Parameter | Type | Optional | Description |
|---|---|---|---|
| expand | Array[String] | true | Must be one or more of [Black,White] |
Additionally this should work with List, Set and Array not just EnumSet.
I checked 2.X but I didn't see anything that looks like it would have fixed this issue.
Hi, looks like we need to support EnumSet collections specifically, should not be a problem. Regarding different "name", how exactly should it behave? You added arbitrary String field to that enum, how do we know that it's the json representation of the enum?
There are a few situations I think have to be dealt with relating to having a different "name"
- Just an Enum
public enum Color {
BLACK,
WHITE
}
- Enum with a name, this one is a little bit tricky too because the name can have spaces in it.
public enum Crayon {
BLACK("Black Crayon"),
WHITE("White Crayon")
}
- Annotated for Jackson with @JsonProperty
public enum Crayon {
@JsonProperty("Black Crayon")
BLACK,
@JsonProperty("White Crayon")
WHITE
}
More complicated things I don't have quick examples for :) 4. @JsonValue and @JsonCreator 5. @JsonSerialize and @JsonDeserialize 6. Different configuration settings ie WRITE_ENUMS_USING_TO_STRING, READ_ENUMS_USING_TO_STRING
Most of these should just work since it comes from Jackson in spring-auto-restdocs, but dealing with different versions and future proofing might want to have test cases for these.
I will hopefully have some time to write some examples next week.
Hi, any examples which we could use to include in our test suite and be able to fix the underlying problem? You can also submit a PR.
I have been dealing with other things and this has been a low priority, I hoping to have it moved up in priority next week so I can write some test cases and maybe actually contribute support.
Sorry this has taken so long, actually working on another issue.
Hi all,
Is there any way to disable Auto enum description in Restdocs?
@ankit45621 Currently no.