Add addFormat support for non string based properties
avkonst opened this issue · 3 comments
addFormat is a great tool for string based properties validation, I would like to have the same for JsNumber based properties.
It may look weird that we may want to validate integers and numbers, but I would like to add an extension to a validator, which could validate that a number is convertible to 32 bits integer or 64 bits integer. I know there is min/max validators for numbers, but I would like to follow the approach swagger takes in the declaration of underlying system type: to use format for number type, where you can specify int32 or int64. and leave min/max constraints for end-user purposes. Currently, I can not trap the overflow of Long type at the stage of json validation. JsNumber from Play Json captures numbers as BigDecimal, and it may overflow at the stage when I access it as Long.
It would be great to have addFormat for JsNumber and, if it is possible, built-in support for format=int32|int64 for integer based properties.
Thanks for the report! Your use case makes sense and I'll try to tackle implementation the upcoming weekend.
Great!