Module aws_lambda_powertools.event_handler.openapi.encoders
Functions
def decimal_encoder(dec_value: Decimal) ‑> int | float
-
Encodes a Decimal as int of there's no exponent, otherwise float
This is useful when we use ConstrainedDecimal to represent Numeric(x,0) where an integer (but not int typed) is used. Encoding this as a float results in failed round-tripping between encode and parse.
>>> decimal_encoder(Decimal("1.0")) 1.0
>>> decimal_encoder(Decimal("1")) 1
def generate_encoders_by_class_tuples(type_encoder_map: dict[Any, Callable[[Any], Any]]) ‑> dict[typing.Callable[[typing.Any], typing.Any], tuple[typing.Any, ...]]
def iso_format(o: datetime.date | datetime.time) ‑> str
-
ISO format for date and time
def jsonable_encoder(obj: Any, include: IncEx | None = None, exclude: IncEx | None = None, by_alias: bool = True, exclude_unset: bool = False, exclude_defaults: bool = False, exclude_none: bool = False, custom_serializer: Callable[[Any], str] | None = None)
-
JSON encodes an arbitrary Python object into JSON serializable data types.
This is a modified version of fastapi.encoders.jsonable_encoder that supports encoding of pydantic.BaseModel objects.
Parameters
obj
:Any
- The object to encode
include
:IncEx | None
, optional- A set or dictionary of strings that specifies which properties should be included, by default None, meaning everything is included
exclude
:IncEx | None
, optional- A set or dictionary of strings that specifies which properties should be excluded, by default None, meaning nothing is excluded
by_alias
:bool
, optional- Whether field aliases should be respected, by default True
exclude_unset
:bool
, optional- Whether fields that are not set should be excluded, by default False
exclude_defaults
:bool
, optional- Whether fields that are equal to their default value (as specified in the model) should be excluded, by default False
exclude_none
:bool
, optional- Whether fields that are equal to None should be excluded, by default False
custom_serializer
:Callable
, optional- A custom serializer to use for encoding the object, when everything else fails.
Returns
Any
- The JSON serializable data types