-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by sebastienbeau
- Loading branch information
Showing
9 changed files
with
62 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
* New base schemas: *PagedCollection*. This schema is used to define the | ||
the structure of a paged collection of resources. This schema is similar | ||
to the ones defined in the Odoo's **fastapi** addon but works as/with | ||
extendable models. | ||
|
||
* The *StrictExtendableBaseModel* has been moved to the *extendable_pydantic* | ||
python lib. You should consider to import it from there. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
from extendable_pydantic import ExtendableBaseModel | ||
from typing import Annotated, Generic, TypeVar | ||
|
||
from extendable_pydantic import StrictExtendableBaseModel | ||
|
||
class StrictExtendableBaseModel( | ||
ExtendableBaseModel, | ||
revalidate_instances="always", | ||
validate_assignment=True, | ||
extra="forbid", | ||
): | ||
""" | ||
An ExtendableBaseModel with strict validation. | ||
from pydantic import Field | ||
|
||
By default, Pydantic does not revalidate instances during validation, nor | ||
when the data is changed. Validation only occurs when the model is created. | ||
This is not suitable for a REST API, where the data is changed after the | ||
model is created or the model is created from a partial set of data and | ||
then updated with more data. This class enforces strict validation by | ||
forcing the revalidation of instances when the method `model_validate` is | ||
called and by ensuring that the values assignment is validated. | ||
T = TypeVar("T") | ||
|
||
The following parameters are added: | ||
* revalidate_instances="always": model instances are revalidated during validation | ||
(default is "never") | ||
* validate_assignment=True: revalidate the model when the data is changed (default is False) | ||
* extra="forbid": Forbid any extra attributes (default is "ignore") | ||
""" | ||
|
||
class PagedCollection(StrictExtendableBaseModel, Generic[T]): | ||
"""A paged collection of items""" | ||
|
||
# This is a generic model. The type of the items is defined by the generic type T. | ||
# It provides you a common way to return a paged collection of items of | ||
# extendable models. It's based on the StrictExtendableBaseModel to ensure | ||
# a strict validation when used within the odoo fastapi framework. | ||
|
||
count: Annotated[int, Field(..., description="The count of items into the system")] | ||
items: list[T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
The field *total* in the *PagedCollection* schema is replaced by the field *count*. | ||
The field *total* is now deprecated and will be removed in the next major version. | ||
This change is backward compatible. The json document returned will now | ||
contain both fields *total* and *count* with the same value. In your python | ||
code the field *total*, if used, will fill the field *count* with the same | ||
value. You are encouraged to use the field *count* instead of *total* and adapt | ||
your code accordingly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters