Files
formulation/container/schemas/v2/source-mapping.schema.json

65 lines
2.4 KiB
JSON

{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://recipes.uuard.com/schemas/v2/source-mapping.schema.json",
"title": "Nutrition or allergen source mapping",
"type": "object",
"required": ["schema_version", "id", "subject", "mapping_type", "source", "status"],
"additionalProperties": false,
"properties": {
"schema_version": { "$ref": "common.schema.json#/$defs/schemaVersion" },
"id": { "$ref": "common.schema.json#/$defs/id" },
"subject": {
"type": "object",
"required": ["type", "id"],
"additionalProperties": false,
"properties": {
"type": { "type": "string", "enum": ["ingredient", "purchase_item", "recipe"] },
"id": { "$ref": "common.schema.json#/$defs/id" }
}
},
"mapping_type": { "type": "string", "enum": ["nutrition", "allergen"] },
"status": { "type": "string", "enum": ["candidate", "reviewed", "rejected", "superseded"] },
"source": { "$ref": "common.schema.json#/$defs/sourceReference" },
"usda": {
"type": "object",
"required": ["fdc_id", "data_type", "description"],
"additionalProperties": false,
"properties": {
"fdc_id": { "type": "integer", "minimum": 1 },
"data_type": { "type": "string", "enum": ["Foundation", "SR Legacy", "FNDDS", "Branded", "Experimental"] },
"description": { "$ref": "common.schema.json#/$defs/nonEmptyString" },
"brand_owner": { "type": "string" },
"gtin_upc": { "type": "string" }
}
},
"nutrition_per_100g": {
"type": "object",
"additionalProperties": { "type": ["number", "null"], "minimum": 0 },
"propertyNames": { "pattern": "^[a-z][a-z0-9_]*_(?:g|mg|mcg|kcal|kj)$" }
},
"allergens": {
"type": "array",
"items": {
"type": "object",
"required": ["allergen_id", "presence"],
"additionalProperties": false,
"properties": {
"allergen_id": { "$ref": "common.schema.json#/$defs/id" },
"presence": { "type": "string", "enum": ["contains", "may_contain", "free_from", "unknown"] }
}
}
}
},
"allOf": [
{
"if": { "properties": { "source": { "properties": { "source_type": { "const": "usda_fdc" } } } } },
"then": { "required": ["usda"] }
},
{
"if": { "properties": { "mapping_type": { "const": "nutrition" } } },
"then": { "required": ["nutrition_per_100g"] },
"else": { "required": ["allergens"] }
}
]
}