1
我想爲oneOf
指定多個值並定義了以下成功驗證的模式(http://json-schema-validator.herokuapp.com/)。請注意,在此示例中,故意在oneOf
下僅有一個值。如何使用JSON模式oneOf對於具有固定值的數組
{
"id": "test-schema",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "test schema",
"type": "object",
"properties": {
"alpha": {
"type": "object",
"properties": {
"beta": {
"oneOf": [
{
"type": "object",
"properties": {
"ObjA": {
"type": "object",
"properties": {
"a": {
"type": "array",
"items": {
"type": "number",
"default": [90, 95],
"additionalProperties": false
},
"additionalProperties": false
},
"b": {
"type": "array",
"items": {
"type": "number",
"default": [4, 8],
"additionalProperties": false
},
"additionalProperties": false
},
"c": {
"type": "array",
"items": {
"type": "number",
"default": [0.2, 0.6],
"additionalProperties": false
},
"additionalProperties": false
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
]
}
},
"additionalProperties": false
}
},
"additionalProperties": false
}
Q1:我使用default
指定初始數組值,但真的希望這些固定下來,並禁止任何其他值。我怎樣才能做到這一點?
這裏回答了How to specify which oneOf item a JSON object should take?。
Q2:我想指定beta
被分配到ObjA
在一個JSON文件中驗證這個模式,我該如何指定這個?
這裏回答了How to specify which oneOf item a JSON object should take?。