JSON模式强制数字为10的幂

huangapple go评论64阅读模式
英文:

JSON schema to force number to be a power of 10

问题

我想定义一个 JSON 模式,要求一个数字是 10 的幂次方(例如,但不限于 1e51001010.11e-5)。我尝试使用以下方式声明它:

"scaleFactor": {
  "type": "number",
  "multipleOf": 10
}

然而,至少根据 https://www.jsonschemavalidator.net/,这不适用于小于 10 的数字。是否有其他方法可以做到这一点?

英文:

I'd like to define a JSON schema which requires a number to be a power of 10 (for example, but not limited to 1e5, 100, 10, 1, 0.1, 1e-5). I tried to declare it using

"scaleFactor": {
  "type": "number",
   "multipleOf" : 10
}

However, at least according to https://www.jsonschemavalidator.net/ that does not work for numbers less than 10. Is there some other way to do this?

答案1

得分: 1

"Power of" 不是 JSON Schema 中存在的函数。

如果你正在使用的实现支持自定义关键字,你可以尝试自己实现它,但它将不受其他实现的支持,因此你的模式将无法共享。

英文:

"Power of" is not a function that exists in JSON Schema.

If the implementation you're using supports custom keywords, you can try implementing it yourself, but it won't be supported in other implementations, so your schema wouldn't be shareable.

huangapple
  • 本文由 发表于 2023年5月24日 21:20:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324010.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定