1+ from __future__ import annotations
2+
13import logging
2- from typing import Any , Callable , Dict , Optional , Union
4+ from typing import Any , Callable
35
6+ from aws_lambda_powertools .middleware_factory import lambda_handler_decorator
47from aws_lambda_powertools .utilities import jmespath_utils
5-
6- from ...middleware_factory import lambda_handler_decorator
7- from .base import validate_data_against_schema
8+ from aws_lambda_powertools .utilities .validation .base import validate_data_against_schema
89
910logger = logging .getLogger (__name__ )
1011
1112
1213@lambda_handler_decorator
1314def validator (
1415 handler : Callable ,
15- event : Union [ Dict , str ] ,
16+ event : dict | str ,
1617 context : Any ,
17- inbound_schema : Optional [ Dict ] = None ,
18- inbound_formats : Optional [ Dict ] = None ,
19- outbound_schema : Optional [ Dict ] = None ,
20- outbound_formats : Optional [ Dict ] = None ,
18+ inbound_schema : dict | None = None ,
19+ inbound_formats : dict | None = None ,
20+ outbound_schema : dict | None = None ,
21+ outbound_formats : dict | None = None ,
2122 envelope : str = "" ,
22- jmespath_options : Optional [ Dict ] = None ,
23+ jmespath_options : dict | None = None ,
2324 ** kwargs : Any ,
2425) -> Any :
2526 """Lambda handler decorator to validate incoming/outbound data using a JSON Schema
@@ -28,21 +29,21 @@ def validator(
2829 ----------
2930 handler : Callable
3031 Method to annotate on
31- event : Dict
32+ event : dict
3233 Lambda event to be validated
3334 context : Any
3435 Lambda context object
35- inbound_schema : Dict
36+ inbound_schema : dict
3637 JSON Schema to validate incoming event
37- outbound_schema : Dict
38+ outbound_schema : dict
3839 JSON Schema to validate outbound event
39- envelope : Dict
40+ envelope : dict
4041 JMESPath expression to filter data against
41- jmespath_options : Dict
42+ jmespath_options : dict
4243 Alternative JMESPath options to be included when filtering expr
43- inbound_formats: Dict
44+ inbound_formats: dict
4445 Custom formats containing a key (e.g. int64) and a value expressed as regex or callback returning bool
45- outbound_formats: Dict
46+ outbound_formats: dict
4647 Custom formats containing a key (e.g. int64) and a value expressed as regex or callback returning bool
4748
4849 Example
@@ -140,26 +141,26 @@ def handler(event, context):
140141
141142def validate (
142143 event : Any ,
143- schema : Dict ,
144- formats : Optional [ Dict ] = None ,
145- envelope : Optional [ str ] = None ,
146- jmespath_options : Optional [ Dict ] = None ,
144+ schema : dict ,
145+ formats : dict | None = None ,
146+ envelope : str | None = None ,
147+ jmespath_options : dict | None = None ,
147148):
148149 """Standalone function to validate event data using a JSON Schema
149150
150151 Typically used when you need more control over the validation process.
151152
152153 Parameters
153154 ----------
154- event : Dict
155+ event : dict
155156 Lambda event to be validated
156- schema : Dict
157+ schema : dict
157158 JSON Schema to validate incoming event
158- envelope : Dict
159+ envelope : dict
159160 JMESPath expression to filter data against
160- jmespath_options : Dict
161+ jmespath_options : dict
161162 Alternative JMESPath options to be included when filtering expr
162- formats: Dict
163+ formats: dict
163164 Custom formats containing a key (e.g. int64) and a value expressed as regex or callback returning bool
164165
165166 Example
0 commit comments