Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 81cf9d3

Browse files
committedJun 6, 2024·
Addressing Heitor's feedback
1 parent 7125c72 commit 81cf9d3

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed
 

‎aws_lambda_powertools/event_handler/openapi/encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def jsonable_encoder( # noqa: PLR0911
155155
)
156156
except ValueError as exc:
157157
raise SerializationError(
158-
f"Unable to serializer the object {obj} as it is not a supported type. Error details: {str(exc)}",
158+
f"Unable to serialize the object {obj} as it is not a supported type. Error details: {exc}",
159159
"See: https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#serializing-objects",
160160
) from exc
161161

‎docs/core/event_handler/api_gateway.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,22 @@ In the following example, we use a new `Header` OpenAPI type to add [one out of
460460

461461
#### Serializing objects
462462

463-
We support the serialization of various Python objects, including Pydantic models, dataclasses, enumerations, file paths, scalar types (strings, integers, floats, and None), dictionaries, various sequence types (lists, sets, frozen sets, generators, tuples, and deques), and others defined [here](https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/event_handler/openapi/encoders.py#L24).
464-
465-
For objects we do not support, such as SQLAlchemy models, we suggest providing your own [custom serializer](#custom-serializer).
463+
With data validation enabled, we natively support serializing the following data types to JSON:
464+
465+
| Data type | Serialized type |
466+
| -------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
467+
| **Pydantic models** | `dict` |
468+
| **Python Dataclasses** | `dict` |
469+
| **Enum** | Enum values |
470+
| **Datetime** | Datetime ISO format string |
471+
| **Decimal** | `int` if no exponent, or `float` |
472+
| **Path** | `str` |
473+
| **UUID** | `str` |
474+
| **Set** | `list` |
475+
| **Python primitives** _(dict, string, sequences, numbers, booleans)_ | [Python's default JSON serializable types](https://docs.python.org/3/library/json.html#encoders-and-decoders){target="_blank" rel="nofollow"} |
476+
477+
???+ info "See [custom serializer section](#custom-serializer) for bringing your own."
478+
Otherwise, we will raise `SerializationError` for any unsupported types _e.g., SQLAlchemy models_.
466479

467480
### Accessing request details
468481

‎tests/functional/event_handler/test_openapi_encoders.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,5 @@ def test_openapi_encode_with_error():
191191
class MyClass:
192192
__slots__ = []
193193

194-
with pytest.raises(SerializationError, match="Unable to serializer the object*"):
194+
with pytest.raises(SerializationError, match="Unable to serialize the object*"):
195195
jsonable_encoder(MyClass())

0 commit comments

Comments
 (0)
Please sign in to comment.