diff --git a/api/openapi.py b/api/openapi.py index ad3163d..fc3ed2e 100644 --- a/api/openapi.py +++ b/api/openapi.py @@ -103,6 +103,19 @@ def extend_with_problem_and_cookie_auth(app: FastAPI) -> None: if not any(isinstance(s, dict) and "cookieAuth" in s for s in security): security.append({"cookieAuth": []}) + # Ensure the cookie parameter is documented as required integer (non-null) + params = op.get("parameters") + if isinstance(params, list): + for p in params: + if not isinstance(p, dict): + continue + if p.get("in") == "cookie" and p.get("name") == "user_id": + p["required"] = True + schema = p.setdefault("schema", {}) + if isinstance(schema, dict): + schema.clear() + schema.update({"type": "integer", "title": "User Id"}) + # Keep endpoint-specific schemas driven by route declarations only (no forced overrides) return spec diff --git a/api/recipes.py b/api/recipes.py index 849cf55..95293a8 100644 --- a/api/recipes.py +++ b/api/recipes.py @@ -79,8 +79,7 @@ async def load_full_recipe(conn: aiosqlite.Connection, id: int) -> Optional[reci async for ingredient in ingredients.find_ingredients_by_recipe_id(conn, id): r.ingredients.append(ingredient) - if r.created_by_id is not None: - r.created_by = await persons.get_by_id(conn, r.created_by_id) + r.created_by = await persons.get_by_id(conn, r.created_by_id) return r diff --git a/common.py b/common.py index faf3b9a..a029ad0 100644 --- a/common.py +++ b/common.py @@ -53,4 +53,4 @@ class Page(ApiModel, Generic[T]): items: List[T] next_cursor: Optional[str] = Field(default=None, alias="nextCursor") prev_cursor: Optional[str] = Field(default=None, alias="prevCursor") - total: Optional[int] = Field(default=None, description="Optional total count") + total: int = Field(default=0, description="Total count") diff --git a/openapi.json b/openapi.json index fb4b492..866a2bc 100644 --- a/openapi.json +++ b/openapi.json @@ -1866,16 +1866,10 @@ "title": "Prevcursor" }, "total": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "null" - } - ], + "type": "integer", "title": "Total", - "description": "Optional total count" + "description": "Total count", + "default": 0 } }, "type": "object", @@ -1916,16 +1910,10 @@ "title": "Prevcursor" }, "total": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "null" - } - ], + "type": "integer", "title": "Total", - "description": "Optional total count" + "description": "Total count", + "default": 0 } }, "type": "object", @@ -2046,17 +2034,6 @@ "imgLarge": { "type": "string", "title": "Imglarge" - }, - "rawData": { - "anyOf": [ - { - "type": "object" - }, - { - "type": "null" - } - ], - "title": "Rawdata" } }, "type": "object", @@ -2175,14 +2152,7 @@ "title": "Datecreated" }, "createdById": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "null" - } - ], + "type": "integer", "title": "Createdbyid" }, "createdBy": { @@ -2288,14 +2258,7 @@ "title": "Datecreated" }, "createdById": { - "anyOf": [ - { - "type": "integer" - }, - { - "type": "null" - } - ], + "type": "integer", "title": "Createdbyid" }, "createdBy": { diff --git a/products/models.py b/products/models.py index ba7d662..0f5ac19 100644 --- a/products/models.py +++ b/products/models.py @@ -3,6 +3,7 @@ from __future__ import annotations from typing import ClassVar, List, Optional from common import ApiModel +from pydantic import PrivateAttr class Product(ApiModel): @@ -28,5 +29,13 @@ class Product(ApiModel): unit: str img_small: str img_large: str - # Non-persisted field used in tests and insert helper - raw_data: Optional[dict] = None + # Non-persisted field used in tests and insert helper (not part of public schema) + _raw_data: Optional[dict] = PrivateAttr(default=None) + + @property + def raw_data(self) -> Optional[dict]: + return self._raw_data + + @raw_data.setter + def raw_data(self, value: Optional[dict]) -> None: + self._raw_data = value diff --git a/recipes/models.py b/recipes/models.py index 91d6423..51eb420 100644 --- a/recipes/models.py +++ b/recipes/models.py @@ -36,7 +36,7 @@ class Recipe(ApiModel): date_created: datetime.datetime = Field( default_factory=lambda: datetime.datetime.now().astimezone() ) - created_by_id: Optional[int] + created_by_id: int created_by: Optional[Person] = None date_hidden: Optional[datetime.datetime] = None