Skip to content

Remote $ref in linked local $ref throws ArgumentError #201

@Dampfwalze

Description

@Dampfwalze

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:

// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions