|
6 | 6 | from enum import Flag, auto |
7 | 7 | from typing import Any, Callable, Dict, Generator, Mapping, Optional, cast |
8 | 8 |
|
9 | | -from jsonschema import Draft7Validator, RefResolver, ValidationError, Validator, validators |
10 | | -from referencing import Registry, Resource |
| 9 | +from jsonschema import Draft7Validator, ValidationError, Validator, validators |
| 10 | +from referencing import Registry, Resource, Resolver |
11 | 11 | from referencing.jsonschema import DRAFT7 |
12 | 12 |
|
13 | 13 | MAX_NESTING_DEPTH = 3 |
@@ -195,33 +195,15 @@ def normalizator( |
195 | 195 | """ |
196 | 196 |
|
197 | 197 | def resolve(subschema: dict[str, Any]) -> dict[str, Any]: |
198 | | - if "$ref" in subschema: |
199 | | - ref_url = subschema["$ref"] |
200 | | - |
201 | | - try: |
202 | | - root_schema = validator_instance.schema |
203 | | - resource = Resource.from_contents(root_schema, default_specification=DRAFT7) |
204 | | - registry = Registry().with_resource("", resource) |
205 | | - resolver = registry.resolver() |
206 | | - resolved = resolver.lookup(ref_url).contents |
207 | | - return cast(dict[str, Any], resolved) |
208 | | - except Exception: |
209 | | - try: |
210 | | - if ( |
211 | | - hasattr(validator_instance, "resolver") |
212 | | - and validator_instance.resolver is not None |
213 | | - ): |
214 | | - _, resolved = cast( |
215 | | - RefResolver, validator_instance.resolver |
216 | | - ).resolve(ref_url) |
217 | | - return cast(dict[str, Any], resolved) |
218 | | - except Exception: |
219 | | - # If both fail, we'll return original subschema, below. |
220 | | - # If both fail, we'll return original subschema, below. |
221 | | - pass |
222 | | - |
| 198 | + if "$ref" not in subschema: |
| 199 | + # Nothing to resolve |
223 | 200 | return subschema |
224 | | - return subschema |
| 201 | + |
| 202 | + # Else, we need to resolve "$ref": |
| 203 | + ref_url = subschema["$ref"] |
| 204 | + resolver: Resolver = validator_instance.resolver |
| 205 | + resolved_contents = resolver.lookup(ref_url).contents |
| 206 | + return cast(dict[str, Any], resolved_contents) |
225 | 207 |
|
226 | 208 | # Transform object and array values before running json schema type checking for each element. |
227 | 209 | # Recursively normalize every value of the "instance" sub-object, |
|
0 commit comments