我想让我的JSON模式验证是否将不超过两个小数位发送到我的REST api.
I want to have my JSON Schema validate that no more than two decimal places are sent to my REST api.
根据我在最新的JSON模式RFC(v4)中看到的内容,不允许这样做. V1有一个maxDecimals验证器.
From what I can see in the latest JSON Schema RFC (v4) doesn't allow this. V1 had a maxDecimals validator.
有人知道为什么要这么做吗?
Does anyone know why that was taken out?
我有一个字段,当我将其存储在数据库中时,该字段仅包含两位小数,并且我不只是想舍入到两位小数.对于某些用户而言,那将极大地改变输入.因此,我想拒绝任何更高的精度,并强迫他们四舍五入.
I have a field that only holds two decimals when I store it in the database, and I do not just want to round down to two decimals. That would be changing the input quite dramatically for some users. So I want to reject any greater precision and force them to round them selves.
我当然可以使用我自己编写的自定义验证程序来执行此操作,但除非绝对必要,否则我不愿意这样做.
I can of course do this using a custom validator that I write myself, but I would rather not unless I absolutely have to.
在v4中还有另一种指示方式吗?
Is there another way of indicating this in v4?
谢谢
推荐答案他们将其替换为multipleOf(通过v3 divisibleBy).
They replaced it with multipleOf (via v3 divisibleBy).
对于2个小数位,只需添加倍数Of:0.01.
For 2 decimal places, just add multipleOf: 0.01.
更多推荐
JSON模式中的小数精度
发布评论