Skip to content
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
4 changes: 4 additions & 0 deletions airbyte_cdk/sources/declarative/validators/dpath_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ def validate(self, input_data: dict[str, Any]) -> None:
if "*" in path:
try:
values = dpath.values(input_data, path)
if not values:
Comment thread
pnilan marked this conversation as resolved.
return
for value in values:
self.strategy.validate(value)
except KeyError as e:
raise ValueError(f"Error validating path '{self.field_path}': {e}")
else:
try:
value = dpath.get(input_data, path)
if not value:
return
Comment thread
pnilan marked this conversation as resolved.
self.strategy.validate(value)
except KeyError as e:
raise ValueError(f"Error validating path '{self.field_path}': {e}")
12 changes: 12 additions & 0 deletions unit_tests/sources/declarative/validators/test_dpath_validator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2025 Airbyte, Inc., all rights reserved.

from unittest import TestCase

import pytest
Expand Down Expand Up @@ -90,3 +92,13 @@ def test_path_with_wildcard_when_validate_then_validate_is_successful(self):
assert strategy.validate_called
assert strategy.validated_value in ["user1@example.com", "user2@example.com"]
self.assertIn(strategy.validated_value, ["user1@example.com", "user2@example.com"])

def test_given_no_values_when_validate_then_validate_is_not_called(self):
strategy = MockValidationStrategy()
validator = DpathValidator(field_path=["users", "*", "email"], strategy=strategy)

validator.validate({"users": {}})
validator.validate(None)
validator.validate({"users": [{"name": "Octavia"}]})

assert not strategy.validate_called
Comment thread
pnilan marked this conversation as resolved.
Loading