英文:
JSON schema to force number to be a power of 10
问题
我想定义一个 JSON 模式,要求一个数字是 10 的幂次方(例如,但不限于 1e5
,100
,10
,1
,0.1
,1e-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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论