Skip to content

feat(validation): returns output from validate function #4839

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 6 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Adding documentation
  • Loading branch information
leandrodamascena committed Aug 5, 2024
commit a457e5fc032aa13b47979d56384a7f85e4c7744c
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/validation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def validate_data_against_schema(
Returns
-------
Dict
The validated event. If the schema includes a `default` for fields that are not provided, they will be included
in the response.
The validated event. If the schema specifies a `default` value for fields that are omitted,
those default values will be included in the response.

Raises
------
Expand Down
4 changes: 2 additions & 2 deletions aws_lambda_powertools/utilities/validation/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ def handler(event, context):
Returns
-------
Dict
The validated event. If the schema includes a `default` for fields that are not provided, they will be included
in the response.
The validated event. If the schema specifies a `default` value for fields that are omitted,
those default values will be included in the response.

Raises
------
Expand Down
4 changes: 4 additions & 0 deletions docs/utilities/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ It will fail fast with `SchemaValidationError` exception if event or response do

**Validate** standalone function is typically used within the Lambda handler, or any other methods that perform data validation.

???+ info
This function returns the validated event as a JSON object. If the schema specifies `default` values for omitted fields,
those default values will be included in the response.

You can also gracefully handle schema validation errors by catching `SchemaValidationError` exception.

=== "getting_started_validator_standalone_function.py"
Expand Down
24 changes: 12 additions & 12 deletions tests/functional/validator/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@pytest.fixture
def schema():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://example.com/example.json",
"type": "object",
"title": "Sample schema",
"description": "The root schema comprises the entire JSON document.",
Expand All @@ -33,8 +33,8 @@ def schema():
@pytest.fixture
def schema_default():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://example.com/example.json",
"type": "object",
"title": "Sample schema",
"description": "The root schema comprises the entire JSON document.",
Expand All @@ -61,8 +61,8 @@ def schema_default():
@pytest.fixture
def schema_array():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://example.com/example.json",
"type": "array",
"title": "Sample schema",
"description": "Sample JSON Schema for dummy data in an array",
Expand Down Expand Up @@ -99,8 +99,8 @@ def schema_array():
@pytest.fixture
def schema_response():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "https://example.com/example.json",
"type": "object",
"title": "Sample outgoing schema",
"description": "The root schema comprises the entire JSON document.",
Expand All @@ -117,7 +117,7 @@ def schema_response():
def schema_refs():
return {
"ParentSchema": {
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "testschema://ParentSchema",
"type": "object",
"title": "Sample schema",
Expand All @@ -132,7 +132,7 @@ def schema_refs():
},
},
"ChildSchema": {
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "testschema://ChildSchema",
"type": "object",
"title": "Sample schema",
Expand Down Expand Up @@ -440,7 +440,7 @@ def cloudwatch_logs_event():
@pytest.fixture
def cloudwatch_logs_schema():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "array",
"title": "Sample schema",
Expand Down Expand Up @@ -655,7 +655,7 @@ def eventbridge_schema_registry_cloudtrail_v2_s3():
@pytest.fixture
def schema_datetime_format():
return {
"$schema": "http://json-schema.org/draft-07/schema",
"$schema": "https://json-schema.org/draft-07/schema",
"$id": "http://example.com/example.json",
"type": "object",
"title": "Sample schema with string date-time format",
Expand Down