{
  "openapi": "3.1.0",
  "info": {
    "title": "Matdata API",
    "version": "1.0.0",
    "summary": "Swedish food composition data (Livsmedelsverket) as static JSON.",
    "description": "Static, read-only JSON files with nutrient values per 100 g edible part for every food in the Swedish Food Agency database (version 2026-07-01). No key, CORS enabled. Data licence: CC BY 4.0 – credit \"Livsmedelsverkets livsmedelsdatabas via Matdata.se\".",
    "license": {
      "name": "CC BY 4.0",
      "url": "https://creativecommons.org/licenses/by/4.0/"
    }
  },
  "servers": [
    {
      "url": "https://matdata.se"
    }
  ],
  "paths": {
    "/api/v1/foods.json": {
      "get": {
        "operationId": "listFoods",
        "summary": "All foods in summary",
        "responses": {
          "200": {
            "description": "Food list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "foods": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/FoodSummary"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/foods/{id}.json": {
      "get": {
        "operationId": "getFood",
        "summary": "One food with all nutrient values",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "example": 553
          }
        ],
        "responses": {
          "200": {
            "description": "Food",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Food"
                }
              }
            }
          },
          "404": {
            "description": "Unknown id"
          }
        }
      }
    },
    "/api/v1/nutrients.json": {
      "get": {
        "operationId": "listNutrients",
        "summary": "Nutrient definitions",
        "responses": {
          "200": {
            "description": "Nutrients",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "nutrients": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Nutrient"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/categories.json": {
      "get": {
        "operationId": "listCategories",
        "summary": "Categories and groups",
        "responses": {
          "200": {
            "description": "Categories",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/references.json": {
      "get": {
        "operationId": "getReferenceValues",
        "summary": "NNR 2023 and EU reference values per group",
        "responses": {
          "200": {
            "description": "Reference values",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/changes.json": {
      "get": {
        "operationId": "listChanges",
        "summary": "Changes between database versions",
        "responses": {
          "200": {
            "description": "Changes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "FoodSummary": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name_sv": {
            "type": "string"
          },
          "name_en": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "kcal": {
            "type": [
              "number",
              "null"
            ]
          },
          "protein": {
            "type": [
              "number",
              "null"
            ]
          },
          "fat": {
            "type": [
              "number",
              "null"
            ]
          },
          "carbohydrate": {
            "type": [
              "number",
              "null"
            ]
          },
          "fibre": {
            "type": [
              "number",
              "null"
            ]
          },
          "url_sv": {
            "type": "string",
            "format": "uri"
          },
          "url_en": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "Food": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "name_sv": {
            "type": "string"
          },
          "name_en": {
            "type": "string"
          },
          "scientific_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "category": {
            "type": [
              "object",
              "null"
            ]
          },
          "group": {
            "type": [
              "object",
              "null"
            ]
          },
          "type": {
            "enum": [
              "analysed",
              "calculated"
            ]
          },
          "diet": {
            "enum": [
              "vegan",
              "vegetarian",
              "pescetarian",
              "omnivore",
              null
            ]
          },
          "per": {
            "const": "100 g"
          },
          "values": {
            "type": "object",
            "additionalProperties": {
              "type": "number"
            },
            "description": "Nutrient code → value per 100 g; see /api/v1/nutrients.json for units"
          },
          "portions": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "label_sv": {
                  "type": "string"
                },
                "label_en": {
                  "type": "string"
                },
                "grams": {
                  "type": "number"
                },
                "source": {
                  "type": "string"
                }
              }
            }
          },
          "density_g_per_dl": {
            "type": [
              "number",
              "null"
            ]
          },
          "international": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "ingredients": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "similar": {
            "type": "array",
            "items": {
              "type": "integer"
            }
          },
          "url_sv": {
            "type": "string",
            "format": "uri"
          },
          "url_en": {
            "type": "string",
            "format": "uri"
          },
          "updated": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "license": {
            "type": "string"
          },
          "attribution": {
            "type": "string"
          }
        }
      },
      "Nutrient": {
        "type": "object",
        "properties": {
          "code": {
            "type": "string"
          },
          "unit": {
            "type": "string"
          },
          "group": {
            "type": "string"
          },
          "name_sv": {
            "type": "string"
          },
          "name_en": {
            "type": "string"
          }
        }
      }
    }
  }
}