Skip to content

docs(api): migrating the event handler utility to mkdocstrings #6023

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 1 commit into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,10 @@ def __init__(
middlewares: list[Callable[..., Response]] | None = None,
):
"""
Internally used Route Configuration

Parameters
----------

method: str
The HTTP method, example "GET"
path: str
Expand Down Expand Up @@ -908,6 +908,8 @@ def build(self, event: ResponseEventT, cors: CORSConfig | None = None) -> dict[s


class BaseRouter(ABC):
"""Base class for Routing"""

current_event: BaseProxyEvent
lambda_context: LambdaContext
context: dict
Expand Down Expand Up @@ -1459,7 +1461,7 @@ def _registered_api_adapter(app: ApiGatewayResolver, next_middleware: Callable[.


class ApiGatewayResolver(BaseRouter):
"""API Gateway and ALB proxy resolver
"""API Gateway, VPC Laticce, Bedrock and ALB proxy resolver

Examples
--------
Expand Down Expand Up @@ -2570,6 +2572,8 @@ def register_exception_handler(func: Callable):


class APIGatewayRestResolver(ApiGatewayResolver):
"""Amazon API Gateway REST and HTTP API v1 payload resolver"""

current_event: APIGatewayProxyEvent

def __init__(
Expand Down Expand Up @@ -2650,6 +2654,8 @@ def _compile_regex(rule: str, base_regex: str = _ROUTE_REGEX):


class APIGatewayHttpResolver(ApiGatewayResolver):
"""Amazon API Gateway HTTP API v2 payload resolver"""

current_event: APIGatewayProxyEventV2

def __init__(
Expand Down Expand Up @@ -2685,6 +2691,8 @@ def _get_base_path(self) -> str:


class ALBResolver(ApiGatewayResolver):
"""Amazon Application Load Balancer (ALB) resolver"""

current_event: ALBEvent

def __init__(
Expand Down
2 changes: 1 addition & 1 deletion aws_lambda_powertools/event_handler/middlewares/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BaseMiddlewareHandler(Generic[EventHandlerInstance], ABC):
This is the middleware handler function where middleware logic is implemented.
The next middleware handler is represented by `next_middleware`, returning a Response object.

Examples
Example
--------

**Correlation ID Middleware**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OpenAPIValidationMiddleware(BaseMiddlewareHandler):
Lambda handler. It also validates the response against the OpenAPI schema defined by the Lambda handler. It
should not be used directly, but rather through the `enable_validation` parameter of the `ApiGatewayResolver`.

Examples
Example
--------

```python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class SchemaValidationMiddleware(BaseMiddlewareHandler):
"""Middleware to validate API request and response against JSON Schema using the [Validation utility](https://docs.powertools.aws.dev/lambda/python/latest/utilities/validation/).

Examples
Example
--------
**Validating incoming event**

Expand Down
9 changes: 4 additions & 5 deletions aws_lambda_powertools/event_handler/openapi/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,6 @@ def get_flat_dependant(
----------
dependant: Dependant
The dependant model to flatten
skip_repeats: bool
If True, child Dependents already visited will be skipped to avoid duplicates
visited: list[CacheKey], optional
Keeps track of visited Dependents to avoid infinite recursion. Defaults to empty list.

Expand Down Expand Up @@ -932,8 +930,9 @@ def analyze_param(
ModelField | None
The type annotation and the Pydantic field representing the parameter
"""
field_info, type_annotation = \
get_field_info_and_type_annotation(annotation, value, is_path_param, is_response_param)
field_info, type_annotation = get_field_info_and_type_annotation(
annotation, value, is_path_param, is_response_param,
)

# If the value is a FieldInfo, we use it as the FieldInfo for the parameter
if isinstance(value, FieldInfo):
Expand Down Expand Up @@ -964,7 +963,7 @@ def analyze_param(


def get_field_info_and_type_annotation(
annotation, value, is_path_param: bool, is_response_param: bool
annotation, value, is_path_param: bool, is_response_param: bool,
) -> tuple[FieldInfo | None, Any]:
"""
Get the FieldInfo and type annotation from an annotation and value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def generate_swagger_html(
spec: str
The OpenAPI spec
swagger_js: str
Swagger UI JavaScript source code or URL
Swagger UI JavaScript source code or URL
swagger_css: str
Swagger UI CSS source code or URL
swagger_base_url: str
Expand Down
1 change: 1 addition & 0 deletions aws_lambda_powertools/logging/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ class InvalidLoggerSamplingRateError(Exception):
"""
Logger configured with Invalid Sampling value
"""

pass
1 change: 1 addition & 0 deletions aws_lambda_powertools/logging/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!!! abstract "Usage Documentation"
[`Logger`](../../core/logger.md)
"""

from __future__ import annotations

import functools
Expand Down
4 changes: 0 additions & 4 deletions aws_lambda_powertools/metrics/provider/datadog/datadog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ def add_metric(
Timestamp in int for the metrics, default = time.time()
tags: list[str]
In format like ["tag:value", "tag2:value2"]
args: Any
extra args will be dropped for compatibility
kwargs: Any
extra kwargs will be converted into tags, e.g., add_metrics(sales=sam) -> tags=['sales:sam']

Examples
--------
Expand Down
1 change: 1 addition & 0 deletions aws_lambda_powertools/tracing/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
!!! abstract "Usage Documentation"
[`Tracer`](../../core/tracer.md)
"""

from __future__ import annotations

import abc
Expand Down
2 changes: 2 additions & 0 deletions docs/api_doc/event_handler/api_gateway.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- markdownlint-disable MD043 MD041 -->
::: aws_lambda_powertools.event_handler.api_gateway
2 changes: 2 additions & 0 deletions docs/api_doc/event_handler/appsync.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- markdownlint-disable MD043 MD041 -->
::: aws_lambda_powertools.event_handler.appsync
2 changes: 2 additions & 0 deletions docs/api_doc/event_handler/middleware.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- markdownlint-disable MD043 MD041 -->
::: aws_lambda_powertools.event_handler.middlewares
2 changes: 2 additions & 0 deletions docs/api_doc/event_handler/openapi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- markdownlint-disable MD043 MD041 -->
::: aws_lambda_powertools.event_handler.openapi
5 changes: 5 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ nav:
- Base: api_doc/data_masking/base.md
- Exception: api_doc/data_masking/exceptions.md
- Provider: api_doc/data_masking/provider.md
- Event Handler:
- AppSync: api_doc/event_handler/appsync.md
- Middleware: api_doc/event_handler/middleware.md
- OpenAPI: api_doc/event_handler/openapi.md
- REST: api_doc/event_handler/api_gateway.md
- Feature Flags:
- AppConfig: api_doc/feature_flags/appconfig.md
- Base: api_doc/feature_flags/base.md
Expand Down
Loading