From 4eb30dab98617dfee4cc6b1e5dbc1d50d4770779 Mon Sep 17 00:00:00 2001 From: Francis Charette-Migneault Date: Fri, 5 Apr 2024 00:31:55 -0400 Subject: [PATCH] add OmitIfNone reference code --- stac_model/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stac_model/base.py b/stac_model/base.py index ebbedb0..ec82721 100644 --- a/stac_model/base.py +++ b/stac_model/base.py @@ -17,7 +17,7 @@ class MLMBaseModel(BaseModel): """ Allows wrapping any field with an annotation to drop it entirely if unset. - ``` + ```python field: Annotated[Optional[], OmitIfNone] = None # or field: Annotated[, OmitIfNone] = None @@ -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):