Added validation error on parsing enum values outside of valid enum values #113
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
It fixes #111 with throwing
OpenAPIBadContentException
on parsing wrong value.This validation won't add anything to RouteSelectors, so you have to manually catch error via StatusPage ktor feature to show desired StatusCode and message to the user.
Which I think totally fine because current code throws
OpenAPIRequiredFieldException
on omitting non-nullable query parameter, so this is the same behavior.Behavior change
Assuming we have enum parameter with name
type
and valid values:[VALID]
Nullable
BEFORE
AFTER
NON nullable
BEFORE
AFTER
ADDED 20 Oct
Added opt-in behaviour to this feature.
Alternative implementations were:
Add new field to
ParameterModel
. That also would require changes to QueryParam, HeaderParam, PathParamPros: These annotations already exist and they could be placed freely on types you don't own
Cons: A lot of changes required in builders.
Add new annotation which will tell that this enum needs strict parsing
Pros: Really easy to implement
Cons: You have to own the type to annotate with new annotation. Can't put it on 3rd party enums
I've decided to go with the second approach just because I was overwhelmed by amount of changes needed for the first approach.
So in this PR I've added new annotation
StrictEnumParsing
which presence will change behaviour of EnumConverterBecause it is new annotation, no behaviour change for existing code.