|
10 | 10 | from referencing import Registry, Resource |
11 | 11 | from referencing._core import Resolver # used for type hints |
12 | 12 | from referencing.jsonschema import DRAFT7 |
| 13 | +from .schema_helpers import expand_refs |
13 | 14 |
|
14 | 15 | MAX_NESTING_DEPTH = 3 |
15 | 16 | json_to_python_simple = { |
@@ -195,29 +196,18 @@ def normalizator( |
195 | 196 | : |
196 | 197 | """ |
197 | 198 |
|
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 | | - |
209 | 199 | # Transform object and array values before running json schema type checking for each element. |
210 | 200 | # Recursively normalize every value of the "instance" sub-object, |
211 | 201 | # if "instance" is an incorrect type - skip recursive normalization of "instance" |
212 | 202 | if schema_key == "properties" and isinstance(instance, dict): |
213 | 203 | for k, subschema in property_value.items(): |
214 | 204 | if k in instance: |
215 | | - subschema = resolve(subschema) |
| 205 | + subschema = resolve_refs(subschema) |
216 | 206 | instance[k] = self.__normalize(instance[k], subschema) |
217 | 207 | # Recursively normalize every item of the "instance" sub-array, |
218 | 208 | # if "instance" is an incorrect type - skip recursive normalization of "instance" |
219 | 209 | elif schema_key == "items" and isinstance(instance, list): |
220 | | - subschema = resolve(property_value) |
| 210 | + subschema = resolve_refs(property_value) |
221 | 211 | for index, item in enumerate(instance): |
222 | 212 | instance[index] = self.__normalize(item, subschema) |
223 | 213 |
|
|
0 commit comments