Skip to content

docs(event_handlers): new data validation and OpenAPI feature #3386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 37 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
297ef84
chore(docs): added validation and OpenAPI docs
rubenfonseca Nov 21, 2023
0e5c7af
chore: refactor
rubenfonseca Nov 22, 2023
96a27eb
chore: remove bad file
rubenfonseca Nov 22, 2023
b5f438c
docs(apigateway): add install section for new data validation feat
heitorlessa Nov 22, 2023
d78bfc3
docs(apigateway): add new data validation section
heitorlessa Nov 22, 2023
ffb6c0e
docs(apigateway): improve wording to emphasize validation error
heitorlessa Nov 22, 2023
a7f9662
docs: improve data validation example using a DTO
heitorlessa Nov 22, 2023
26cf7c0
docs: add handling validation errors section
heitorlessa Nov 22, 2023
3c741d8
docs: bring validation errors pydantic upfront to discuss later
heitorlessa Nov 22, 2023
3beb9c4
docs: add initial validating payloads section
heitorlessa Nov 22, 2023
9513959
docs(apigateway): complete catching validation errors
heitorlessa Nov 22, 2023
3e8347b
docs: correct validating payload output filename
heitorlessa Nov 22, 2023
4db84ab
fix: restore file name in older location
heitorlessa Nov 22, 2023
b4a8fe8
chore: move first example to REST API
rubenfonseca Nov 22, 2023
47f3894
chore: rewrote the other examples
rubenfonseca Nov 22, 2023
5c55490
docs: add validating query strings section
heitorlessa Nov 22, 2023
7e382e0
docs: improve examples with list type inference
heitorlessa Nov 22, 2023
0ccfc2c
docs: add path validation section
heitorlessa Nov 22, 2023
b611700
docs: add missing highlight for path validation
heitorlessa Nov 22, 2023
bb404fc
docs: document how to inject query strings w/o validation
heitorlessa Nov 22, 2023
2caa5b1
chore: add query strings to Param, Path and Query
rubenfonseca Nov 22, 2023
e5bbc0a
docs: add OpenAPI and Swagger UI advanced
heitorlessa Nov 22, 2023
f052551
docs: add openapi parameters section
heitorlessa Nov 23, 2023
d9ae183
docs: link data validation to openapi params section
heitorlessa Nov 23, 2023
3b8ffab
docs: add payload subset subsection
heitorlessa Nov 23, 2023
c799f0e
docs: update code snippets
heitorlessa Nov 23, 2023
1edd283
docs: use new validation error output; improve wording
heitorlessa Nov 23, 2023
cba319f
docs: add OpenAPI and data validation as key features
heitorlessa Nov 23, 2023
63076cb
docs: remove older examples from openapi validation
heitorlessa Nov 23, 2023
7fc2c50
docs: fix swagger UI example
heitorlessa Nov 23, 2023
0ebc72d
docs: add note that dataclasses are supported too
heitorlessa Nov 23, 2023
cc55bf3
docs: add swagger UI routes for API GW
heitorlessa Nov 23, 2023
27beb90
chore: remove openapi docs for now
rubenfonseca Nov 23, 2023
62bdb85
Merge branch 'develop' into rf/openapi-docs
rubenfonseca Nov 23, 2023
d2223e4
fix: example for old pythons
rubenfonseca Nov 23, 2023
53fdc8c
fix: more types
rubenfonseca Nov 23, 2023
345fd0b
fix: one more
rubenfonseca Nov 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
174 changes: 174 additions & 0 deletions aws_lambda_powertools/event_handler/openapi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,64 @@ def __init__(
json_schema_extra: Union[Dict[str, Any], None] = None,
**extra: Any,
):
"""
Constructs a new Param.

Parameters
----------
default: Any
The default value of the parameter
default_factory: Callable[[], Any], optional
Callable that will be called when a default value is needed for this field
annotation: Any, optional
The type annotation of the parameter
alias: str, optional
The public name of the field
alias_priority: int, optional
Priority of the alias. This affects whether an alias generator is used
validation_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for validation only
serialization_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for serialization only
title: str, optional
The title of the parameter
description: str, optional
The description of the parameter
gt: float, optional
Only applies to numbers, required the field to be "greater than"
ge: float, optional
Only applies to numbers, required the field to be "greater than or equal"
lt: float, optional
Only applies to numbers, required the field to be "less than"
le: float, optional
Only applies to numbers, required the field to be "less than or equal"
min_length: int, optional
Only applies to strings, required the field to have a minimum length
max_length: int, optional
Only applies to strings, required the field to have a maximum length
pattern: str, optional
Only applies to strings, requires the field match against a regular expression pattern string
discriminator: str, optional
Parameter field name for discriminating the type in a tagged union
strict: bool, optional
Enables Pydantic's strict mode for the field
multiple_of: float, optional
Only applies to numbers, requires the field to be a multiple of the given value
allow_inf_nan: bool, optional
Only applies to numbers, requires the field to allow infinity and NaN values
max_digits: int, optional
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
decimal_places: int, optional
Only applies to Decimals, requires the field to have at most a number of decimal places
examples: List[Any], optional
A list of examples for the parameter
deprecated: bool, optional
If `True`, the parameter will be marked as deprecated
include_in_schema: bool, optional
If `False`, the parameter will be excluded from the generated OpenAPI schema
json_schema_extra: Dict[str, Any], optional
Extra values to include in the generated OpenAPI schema
"""
self.deprecated = deprecated
self.include_in_schema = include_in_schema

Expand Down Expand Up @@ -207,6 +265,64 @@ def __init__(
json_schema_extra: Union[Dict[str, Any], None] = None,
**extra: Any,
):
"""
Constructs a new Path param.

Parameters
----------
default: Any
The default value of the parameter
default_factory: Callable[[], Any], optional
Callable that will be called when a default value is needed for this field
annotation: Any, optional
The type annotation of the parameter
alias: str, optional
The public name of the field
alias_priority: int, optional
Priority of the alias. This affects whether an alias generator is used
validation_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for validation only
serialization_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for serialization only
title: str, optional
The title of the parameter
description: str, optional
The description of the parameter
gt: float, optional
Only applies to numbers, required the field to be "greater than"
ge: float, optional
Only applies to numbers, required the field to be "greater than or equal"
lt: float, optional
Only applies to numbers, required the field to be "less than"
le: float, optional
Only applies to numbers, required the field to be "less than or equal"
min_length: int, optional
Only applies to strings, required the field to have a minimum length
max_length: int, optional
Only applies to strings, required the field to have a maximum length
pattern: str, optional
Only applies to strings, requires the field match against a regular expression pattern string
discriminator: str, optional
Parameter field name for discriminating the type in a tagged union
strict: bool, optional
Enables Pydantic's strict mode for the field
multiple_of: float, optional
Only applies to numbers, requires the field to be a multiple of the given value
allow_inf_nan: bool, optional
Only applies to numbers, requires the field to allow infinity and NaN values
max_digits: int, optional
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
decimal_places: int, optional
Only applies to Decimals, requires the field to have at most a number of decimal places
examples: List[Any], optional
A list of examples for the parameter
deprecated: bool, optional
If `True`, the parameter will be marked as deprecated
include_in_schema: bool, optional
If `False`, the parameter will be excluded from the generated OpenAPI schema
json_schema_extra: Dict[str, Any], optional
Extra values to include in the generated OpenAPI schema
"""
if default is not ...:
raise AssertionError("Path parameters cannot have a default value")

Expand Down Expand Up @@ -279,6 +395,64 @@ def __init__(
json_schema_extra: Union[Dict[str, Any], None] = None,
**extra: Any,
):
"""
Constructs a new Query param.

Parameters
----------
default: Any
The default value of the parameter
default_factory: Callable[[], Any], optional
Callable that will be called when a default value is needed for this field
annotation: Any, optional
The type annotation of the parameter
alias: str, optional
The public name of the field
alias_priority: int, optional
Priority of the alias. This affects whether an alias generator is used
validation_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for validation only
serialization_alias: str | AliasPath | AliasChoices | None, optional
Alias to be used for serialization only
title: str, optional
The title of the parameter
description: str, optional
The description of the parameter
gt: float, optional
Only applies to numbers, required the field to be "greater than"
ge: float, optional
Only applies to numbers, required the field to be "greater than or equal"
lt: float, optional
Only applies to numbers, required the field to be "less than"
le: float, optional
Only applies to numbers, required the field to be "less than or equal"
min_length: int, optional
Only applies to strings, required the field to have a minimum length
max_length: int, optional
Only applies to strings, required the field to have a maximum length
pattern: str, optional
Only applies to strings, requires the field match against a regular expression pattern string
discriminator: str, optional
Parameter field name for discriminating the type in a tagged union
strict: bool, optional
Enables Pydantic's strict mode for the field
multiple_of: float, optional
Only applies to numbers, requires the field to be a multiple of the given value
allow_inf_nan: bool, optional
Only applies to numbers, requires the field to allow infinity and NaN values
max_digits: int, optional
Only applies to Decimals, requires the field to have a maxmium number of digits within the decimal.
decimal_places: int, optional
Only applies to Decimals, requires the field to have at most a number of decimal places
examples: List[Any], optional
A list of examples for the parameter
deprecated: bool, optional
If `True`, the parameter will be marked as deprecated
include_in_schema: bool, optional
If `False`, the parameter will be excluded from the generated OpenAPI schema
json_schema_extra: Dict[str, Any], optional
Extra values to include in the generated OpenAPI schema
"""
super().__init__(
default=default,
default_factory=default_factory,
Expand Down
Loading