Skip to content

Commit 43ee692

Browse files
authored
try making DRY
1 parent bb13c89 commit 43ee692

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

airbyte_cdk/sources/utils/transform.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from referencing import Registry, Resource
1111
from referencing._core import Resolver # used for type hints
1212
from referencing.jsonschema import DRAFT7
13+
from .schema_helpers import expand_refs
1314

1415
MAX_NESTING_DEPTH = 3
1516
json_to_python_simple = {
@@ -195,29 +196,18 @@ def normalizator(
195196
:
196197
"""
197198

198-
def resolve(subschema: dict[str, Any]) -> dict[str, Any]:
199-
if "$ref" not in subschema:
200-
# Nothing to resolve
201-
return subschema
202-
203-
# Else, we need to resolve "$ref":
204-
ref_url = subschema["$ref"]
205-
resolver: Resolver = validator_instance.resolver
206-
resolved_contents = resolver.lookup(ref_url).contents
207-
return cast(dict[str, Any], resolved_contents)
208-
209199
# Transform object and array values before running json schema type checking for each element.
210200
# Recursively normalize every value of the "instance" sub-object,
211201
# if "instance" is an incorrect type - skip recursive normalization of "instance"
212202
if schema_key == "properties" and isinstance(instance, dict):
213203
for k, subschema in property_value.items():
214204
if k in instance:
215-
subschema = resolve(subschema)
205+
subschema = resolve_refs(subschema)
216206
instance[k] = self.__normalize(instance[k], subschema)
217207
# Recursively normalize every item of the "instance" sub-array,
218208
# if "instance" is an incorrect type - skip recursive normalization of "instance"
219209
elif schema_key == "items" and isinstance(instance, list):
220-
subschema = resolve(property_value)
210+
subschema = resolve_refs(property_value)
221211
for index, item in enumerate(instance):
222212
instance[index] = self.__normalize(item, subschema)
223213

0 commit comments

Comments
 (0)