Support for specifying property model #72
Merged
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.
Except for (JSON) request content, request parameters (query, params, headers) contain string values. So even though in your validation you ensure that they match a number or boolean, the application code still needs to deal with type conversions.
In this PR an optional
model
property can be specified to transform the request value to a specific type. When validation of a property succeeds and amodel
is specified, the original request value is replaced with the transformed value.When handling the request
GET /search?text=Hello&from=2017-12-1&to=1514678400000&summary=true&page=3
, the query property types will bestring
,number
,Date
,Date
andnumber
, respectively and the following will be logged:Without specifying the
model
settings, the query property types would have been strings and the following would have been logged: