validate using jsonschema, not manually

This commit is contained in:
Emi Vasilek 2023-11-06 05:18:39 +01:00
parent a2cbbb2068
commit 2f183c758f
4 changed files with 125 additions and 70 deletions

46
schemas/ingredients.json Normal file
View file

@ -0,0 +1,46 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/ingredients.json",
"title": "Ingredients",
"description": "Ingredients",
"type": "array",
"items": {
"type": "object",
"required": [ "name" ],
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"wdid": { "type": "integer" },
"pricedb": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [ "price", "amount", "unit" ],
"properties": {
"price": { "type": "integer" },
"amount": { "type": "integer" },
"unit": { "type": "string" }
}
}
},
"conversions": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [ "from", "to", "ratio" ],
"properties": {
"from": { "type": "string" },
"to": { "type": "string" },
"ratio": { "type": "integer" }
}
}
},
"aliases": {
"type": "array",
"items": { "type": "string" }
}
}
}
}

36
schemas/recipe.json Normal file
View file

@ -0,0 +1,36 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/recipe.json",
"title": "Recipe",
"description": "Recipe",
"type": "object",
"required": [ "title" ],
"additionalProperties": false,
"properties": {
"title": { "type": "string" },
"ingredients": {
"type": "array",
"items": {
"$id": "https://example.com/ingredient.json",
"type": "object",
"additionalProperties": false,
"required": [ "name" ],
"properties": {
"name": { "type": "string" },
"amount": { "type": "number" },
"unit": { "type": "string" },
"or": { "items": { "$ref": "/ingredient.json" } },
"note": { "type": "string" }
}
}
},
"steps": {
"type": "array",
"items": { "type": "string" }
},
"parts": {
"type": "array",
"items": { "$ref": "/recipe.json" }
}
}
}

31
schemas/units.json Normal file
View file

@ -0,0 +1,31 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/units.json",
"title": "Units",
"description": "Units",
"type": "array",
"items": {
"type": "object",
"required": [ "name" ],
"additionalProperties": false,
"properties": {
"name": { "type": "string" },
"conversions": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"required": [ "to", "ratio" ],
"properties": {
"to": { "type": "string" },
"ratio": { "type": "integer" }
}
}
},
"aliases": {
"type": "array",
"items": { "type": "string" }
}
}
}
}