Skip to content

Commit 96ed44f

Browse files
committed
fix: handle built-in custom formats correctly #496
1 parent 8724294 commit 96ed44f

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Diff for: tests/functional/validator/conftest.py

+21
Original file line numberDiff line numberDiff line change
@@ -565,3 +565,24 @@ def eventbridge_schema_registry_cloudtrail_v2_s3():
565565
"x-amazon-events-detail-type": "AWS API Call via CloudTrail",
566566
"x-amazon-events-source": "aws.s3",
567567
}
568+
569+
570+
@pytest.fixture
571+
def schema_datetime_format():
572+
return {
573+
"$schema": "http://json-schema.org/draft-07/schema",
574+
"$id": "http://example.com/example.json",
575+
"type": "object",
576+
"title": "Sample schema with string date-time format",
577+
"description": "The root schema comprises the entire JSON document.",
578+
"required": ["message"],
579+
"properties": {
580+
"message": {
581+
"$id": "#/properties/message",
582+
"type": "string",
583+
"format": "date-time",
584+
"title": "The message",
585+
"examples": ["hello world"],
586+
},
587+
},
588+
}

Diff for: tests/functional/validator/test_validator.py

+9
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,12 @@ def _func_echo_decoder(self, value):
151151
envelope="powertools_json(data).payload",
152152
jmespath_options=jmespath_opts,
153153
)
154+
155+
156+
def test_validate_date_time_format(schema_datetime_format):
157+
raw_event = {"message": "2021-06-29T14:46:06.804Z"}
158+
validate(event=raw_event, schema=schema_datetime_format)
159+
160+
invalid_datetime = {"message": "2021-06-29T14"}
161+
with pytest.raises(exceptions.SchemaValidationError, match="data.message must be date-time"):
162+
validate(event=invalid_datetime, schema=schema_datetime_format)

0 commit comments

Comments
 (0)