{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/tinyplates-dev/json-schema/tinyplates-dev-nutrition-totals-schema.json",
  "title": "NutritionTotals",
  "description": "The same nutrition told twice: for one serving, which is what recipes are compared on, and for the whole recipe, which is what the cook is making. Present only when the recipe carries nutrition and says how many servings it makes. Scaling the recipe changes the whole-recipe figures and leaves the per-serving ones alone.",
  "x-generated": "2026-10-31",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/tinyplates-dev-openapi.json#/components/schemas/NutritionTotals",
  "type": "object",
  "required": [
    "basisServings",
    "perRecipe",
    "perServing",
    "servings"
  ],
  "properties": {
    "basisServings": {
      "type": "number",
      "description": "The serving count perRecipe was multiplied up from: the label's own basis when the recipe declares one — a recipe stored as serving 8 to 10 can carry a label worked out on 10, not the stored 8 — otherwise the serving count the recipe had before any scaling."
    },
    "perRecipe": {
      "$ref": "#/$defs/Nutrition"
    },
    "perServing": {
      "$ref": "#/$defs/Nutrition"
    },
    "servings": {
      "type": "number"
    }
  },
  "additionalProperties": false,
  "$defs": {
    "NonEmptyTrimmedString": {
      "type": "string",
      "description": "a non empty string",
      "title": "nonEmptyString",
      "pattern": "^\\S[\\s\\S]*\\S$|^\\S$|^$",
      "minLength": 1
    },
    "NonNegative": {
      "type": "number",
      "description": "a non-negative number",
      "title": "nonNegative",
      "minimum": 0
    },
    "NutrientUnit": {
      "type": "string",
      "enum": [
        "IU",
        "g",
        "kcal",
        "mg",
        "µg"
      ]
    },
    "NutrientValue": {
      "type": "object",
      "required": [
        "unit",
        "value"
      ],
      "properties": {
        "unit": {
          "$ref": "#/$defs/NutrientUnit"
        },
        "value": {
          "$ref": "#/$defs/NonNegative"
        }
      },
      "additionalProperties": false
    },
    "Nutrition": {
      "type": "object",
      "required": [
        "basis",
        "source"
      ],
      "properties": {
        "basis": {
          "type": "object",
          "required": [
            "type"
          ],
          "properties": {
            "description": {
              "$ref": "#/$defs/NonEmptyTrimmedString"
            },
            "servings": {
              "$ref": "#/$defs/Positive"
            },
            "type": {
              "type": "string",
              "enum": [
                "100g",
                "recipe",
                "serving"
              ]
            }
          },
          "additionalProperties": false
        },
        "calories": {
          "$ref": "#/$defs/NutrientValue"
        },
        "carbohydrates": {
          "$ref": "#/$defs/NutrientValue"
        },
        "cholesterol": {
          "$ref": "#/$defs/NutrientValue"
        },
        "fat": {
          "$ref": "#/$defs/NutrientValue"
        },
        "fiber": {
          "$ref": "#/$defs/NutrientValue"
        },
        "micronutrients": {
          "type": "object",
          "required": [],
          "properties": {},
          "patternProperties": {
            "": {
              "$ref": "#/$defs/NutrientValue"
            }
          },
          "propertyNames": {
            "$ref": "#/$defs/Slug"
          }
        },
        "protein": {
          "$ref": "#/$defs/NutrientValue"
        },
        "saturatedFat": {
          "$ref": "#/$defs/NutrientValue"
        },
        "sodium": {
          "$ref": "#/$defs/NutrientValue"
        },
        "source": {
          "type": "string",
          "enum": [
            "calculated",
            "provided"
          ]
        },
        "sugar": {
          "$ref": "#/$defs/NutrientValue"
        }
      },
      "additionalProperties": false
    },
    "Positive": {
      "type": "number",
      "description": "a positive number",
      "title": "positive",
      "exclusiveMinimum": 0
    },
    "Slug": {
      "type": "string",
      "description": "a string matching the pattern ^[a-z0-9]+(-[a-z0-9]+)*$",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
    }
  }
}