Utilisation oneOf pour les schéma Json
Bonjour,
je rencontre quelques difficultés à utiliser la propriété "oneOf" des schémas JSON.
Dans l'idée, je veux simplement qu'une seule propriété (d'un ensemble de propriété) d'un objet soit rentré par l'utilisateur du schéma. Mais j'obtiens l'erreur "Matches multiple schemas when only one must validate." avec les ligne suivantes :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": ".",
"definitions": {
"prof1": {
"type": "object",
"properties": {
"prof1": {
"title": "",
"enum": [
"tropical",
"midLatitudeSummer",
"midLatitudeWinter",
"subArticSummer",
"subArticWinter"
]
}
}
},
"prof2": {
"type": "object",
"properties": {
"prof2": {
"title": "",
"type": "number",
"minimum": 0,
"maximum": 143
}
}
}
"properties": {
"typeatm": {
"type": "object",
"oneOf": [
{ "$ref": "#/definitions/prof1" },
{ "$ref": "#/definitions/prof2" }
]
}
"additionalProperties": false
} |
fichier de test :
Code:
1 2 3 4 5
|
{
"$schema": "./schema.json",
"typeatm": {"prof2": 0}
} |
Merci de votre aide!