0
我有這個json模式有一個數組包含多個對象,並且每個對象與其他基於某些模式略有不同。在oneOf之前有可能擁有共同的屬性嗎?
例子。
[
{
"ID": "pgID",
"Name": "John",
"Surname": "Doe",
"ProjectsInvolved": [
"My Project",
"My Project 2"
]
},
{
"ID": "jtID",
"Name": "John",
"Surname": "Doe",
"WorksOn": [
"Monday",
"Thursday"
]
}
]
爲JSON的模式是:
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"ID": {
"type": "string",
"pattern": "^(pg)\\w*$"
},
"Name": {
"type": "string"
},
"Surname": {
"type": "string"
},
"ProjectsInvolved": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
{
"type": "object",
"properties": {
"ID": {
"type": "string",
"pattern": "^(jt)\\w*$"
},
"Name": {
"type": "string"
},
"Surname": {
"type": "string"
},
"WorksOn": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
]
},
"additionalProperties": false
}
我的問題是,雖然真正的JSON是相似的,它有更多的項目,並有望隨着更多時間過去增長較大。因此,我必須問,模式是否可以對相同的元素Name和Surname進行分組,並且只有ID和數組在OneOf中?
建議架構的一個例子:
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "array",
"items": {
"type": "object",
"properties": {
"Name": {
"type": "string"
},
"Surname": {
"type": "string"
},
"oneOf": [
{
"ID": {
"type": "string",
"pattern": "^(pg)\\w*$"
},
"ProjectsInvolved": {
"type": "array",
"items": {
"type": "string"
}
}
},
{
"ID": {
"type": "string",
"pattern": "^(jt)\\w*$"
},
"WorksOn": {
"type": "array",
"items": {
"type": "string"
}
}
}
]
}
},
"additionalProperties": false
}
正是我所需要的!我希望我可以給你一個額外的+1,只是因爲你的名字是Jason,而你正在回答一個與JSON相關的問題。 :d –