eclipsesource/play-json-schema-validator

int32 | int64 validator for integer property type

Closed this issue · 5 comments

Hi,

I have tested int32 | int64 format validator. It seems it works for number property type. I thought that Swagger spec allows format spec only for integer property type, which is missing.

Here is what I do:

  • I persist object in a database. JSON schema describes an instance.
  • I inspect the schema and identify object properties and it's types.
  • For number type I use double. It works fine and handles overflows, as double just drops precision when there is no enough bits to save all
  • For integer type I use BigDecimal if no format is specified, use Long if format is int64, and use Int if format is int32.

So, I effectively did not have an issue with number property type, I had an overflow of an integer. If you could let me know how I could fix it myself, I could contribute.

Got it, I forgot to actually validate the format for integers, although everything else is in place. I don't think this should be much of a hassle to fix. You'd need to pull up the validateFormat method to the NumberConstraintsValidator and call that within the IntegerValidator. Please note that in case you want to contribute, you should do so against the scala-2.11 branch, since master is on 2.12 and has some breaking changes against 2.11 (the 0.8.7 release was also created from the scala-2.11 branch).

Let me know if you want to take care of that (contributions are very welcome!). Otherwise I'll add additional tests and update in the evening.

I've pushed a PR. Maybe you could take a look to be sure it fits your needs? If so, I will backport the fix to the scala-2.11 branch.

Thanks for your review. This should be fixed with 0.8.8.