Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
add OmitIfNone reference code
Browse files Browse the repository at this point in the history
  • Loading branch information
fmigneault committed Apr 5, 2024
1 parent 4d57e41 commit 4eb30da
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stac_model/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MLMBaseModel(BaseModel):
"""
Allows wrapping any field with an annotation to drop it entirely if unset.
```
```python
field: Annotated[Optional[<desiredType>], OmitIfNone] = None
# or
field: Annotated[<desiredType>, OmitIfNone] = None
Expand All @@ -26,6 +26,8 @@ class MLMBaseModel(BaseModel):
```
It is important to use `MLMBaseModel`, otherwise the serializer will not be called and applied.
Reference: https://github.com/pydantic/pydantic/discussions/5461#discussioncomment-7503283
"""
@model_serializer
def model_serialize(self):
Expand Down

0 comments on commit 4eb30da

Please sign in to comment.