forked from patefacio/json_schema
-
Notifications
You must be signed in to change notification settings - Fork 38
Open
Description
When a $ref refers to a local definition (for example: "$ref": "#$defs/someDef"), the _baseResolvePaths() step tries to resolve that local path, while assuming all references have been resolved (using resolvePath()). But this assumption is wrong. Because the target of that path might still have a remote source:
final schema = await JsonSchema.createAsync({
r"$schema": "https://json-schema.org/draft/2020-12/schema",
r"$id": "test.schema.json",
r'$defs': {
'geographical-location': {
r'$ref': 'https://example.com/geographical-location.schema.json',
},
},
'type': 'array',
'items': {r'$ref': r'#/$defs/geographical-location'},
}, refProvider: refProvider);throws:
ArgumentError ("Invalid argument(s): Failed to get schema for path because the schema file (https://example.com/geographical-location.schema.json#) could not be found. Unable to resolve path https://example.com/geographical-location.schema.json")This is where the assumption is made:
json_schema/lib/src/json_schema/json_schema.dart
Lines 459 to 462 in dc39865
| // Resolve sub schema of fetched schema if a fragment was included. | |
| if (resolvedSuccessfully && schemaUri.fragment.isNotEmpty) { | |
| localSchema?.resolvePath(Uri.parse('#${schemaUri.fragment}')); | |
| } |
But the result of that operation is not used at all. Is this simply a validation step, or can this be omitted? When removing this part, the example works fine.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels