How to validate a union type of an enum and a collection of this enum in query parameters? #1734
-
Hi there! So I have an enum type: enum Color {
RED: 'red',
GREEN: 'green',
BLUE: 'blue'
} And I have a model class that describes all possible query parameters for a REST request: @AdditionalProperties(false)
class GetColorsQueryParameters {
@AnyOf(Color, array().items(Color))
@OnDeserialize(deserializeColors)
public color: Color | Color[]
} What I want to achieve here is to allow the following requests:
And I obviously want to forbid any other query parameters along with unsupported colors from being queried. Please don't mind the P.S. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Because Try that: @CollectionOf(Color)
@OnDeserialize(deserializeColors)
public color: Color[] I think it should works, because, the ValidationService will try to coerce data before validating it and the deserializeColors will map correctly the data to an array See you |
Beta Was this translation helpful? Give feedback.
Because
@AnyOf(Color, array().items(Color))
is probably not correct.Try that:
I think it should works, because, the ValidationService will try to coerce data before validating it and the deserializeColors will map correctly the data to an array
See you
romain