Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve Product schema (inherit, field description) #58

Merged
merged 4 commits into from
Nov 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,37 @@ class UserBase(BaseModel):
class ProductCreate(BaseModel):
model_config = ConfigDict(from_attributes=True, arbitrary_types_allowed=True)

code: str
code: str = Field(
min_length=1,
pattern="^[0-9]+$",
description="barcode (EAN) of the product, as a string.",
examples=["8001505005707"],
)


class ProductBase(BaseModel):
class ProductBase(ProductCreate):
id: int
source: Flavor | None
product_name: str | None
product_quantity: int | None
image_url: AnyHttpUrl | None
created: datetime.datetime
updated: datetime.datetime | None
source: Flavor | None = Field(
description="source of data, either `off` (Open Food Facts), "
"`obf` (Open Beauty Facts), `opff` (Open Pet Food Facts) or `obf` (Open Beauty Facts)"
)
product_name: str | None = Field(
description="name of the product.", examples=["Nocciolata"]
)
product_quantity: int | None = Field(
description="quantity of the product, normalized in g or mL (depending on the product).",
examples=[700],
)
image_url: AnyHttpUrl | None = Field(
description="URL of the product image.",
examples=[
"https://images.openfoodfacts.org/images/products/800/150/500/5707/front_fr.161.400.jpg"
],
)
created: datetime.datetime = Field(description="datetime of the creation.")
updated: datetime.datetime | None = Field(
description="datetime of the last update."
)


class LocationCreate(BaseModel):
Expand Down Expand Up @@ -68,7 +88,7 @@ class PriceCreate(BaseModel):
min_length=1,
pattern="^[0-9]+$",
description="barcode (EAN) of the product, as a string.",
examples=["16584958", "1234567890123"],
examples=["16584958", "8001505005707"],
)
category_tag: str | None = Field(
default=None,
Expand Down
Loading