Ich habe dieses JSON-Schema, das ein Array hat, das mehrere Objekte enthält, und jedes Objekt unterscheidet sich leicht von den anderen basierend auf bestimmten Mustern.Ist es möglich, gemeinsame Eigenschaften vor oneOf zu haben?
Beispiel.
[
{
"ID": "pgID",
"Name": "John",
"Surname": "Doe",
"ProjectsInvolved": [
"My Project",
"My Project 2"
]
},
{
"ID": "jtID",
"Name": "John",
"Surname": "Doe",
"WorksOn": [
"Monday",
"Thursday"
]
}
]
Das json-Schema für das wäre:
{
"$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
}
Mein Problem ist, dass, obwohl die reale json ähnlich ist, es viele weitere Elemente hat, und es ist bereit, größer zu wachsen, da mehr Zeit vergeht . Daher muss ich fragen, ist es möglich, dass das Schema die identischen Elemente Name und Nachname gruppiert und nur die ID und die Arrays in der oneOf hat?
Ein Beispiel für das vorgeschlagene Schema:
{
"$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
}
Genau was ich brauchte! Ich wünschte, ich könnte dir ein zusätzliches +1 geben, nur weil du Jason heißt und auf eine JSON-Frage antwortest. : D –