Ich muss die folgenden Array-Elemente validieren.So überprüfen Sie jede Instanz in einem Array mit einer beliebigen Definition im JSON-Schema
{
contents: [{
type: "text",
content: "This is text context"
}, {
type: "image",
content: "http://image.url"
}]
}
Ich muss jedes Element im Inhaltsfeld überprüfen.
Inhalt Objekte sollten jeweils type
und content
Eigenschaften haben. type
kann "Text", "Bild" oder "Video" sein. Für Bild oder Video sollte content
eine gültige URL sein.
Dafür habe ich folgendes Schema geschrieben.
{
"id": "post",
"description": "generell schema for a post",
"definitions": {
"contents": {
"type": "array",
"minItems": 1,
"items": {
"allOf": [
{ "$ref": "#/definitions/text" },
{ "$ref": "#/definitions/image" },
{ "$ref": "#/definitions/video" },
{ "$ref": "#/definitions/mention" }
]
}
},
"text": {
"properties": {
"type": {"enum": ["text"]},
"content": {"type": "string"}
},
"required": [
"content",
"type"
]
},
"image": {
"properties": {
"type": {"enum": ["image"]},
"content": {
"type": "string",
"format": "url"
}
},
"required": [
"content",
"type"
]
},
"video": {
"properties": {
"type": {"enum": ["video"]},
"content": {
"type": "string",
"format": "url"
}
},
"required": [
"content",
"type"
]
}
}
}
Aber über JSON ist nicht gültig mit meinem Schema. Es sagte data.contents[0].type should be equal to one of the allowed values
Wenn ich oneOf anstelle allOf verwende, ist es gültig. Der Bildinhalt kann jedoch ohne gültige URL Zeichenfolge sein.
Was ist das korrekte Schema?
und die Frage ist ....? – Pedro