Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Dampfwalze opened this issue Feb 7, 2025 · 1 comment
Open

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

Dampfwalze opened this issue Feb 7, 2025 · 1 comment

Comments

@Dampfwalze
Copy link

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.

@kyleferguson-wk
Copy link

Hello @Dampfwalze! I think one potential workaround here in this case could be to just use the $ref directly. As far as the issue being addressed here, I can't guarantee we'll be able to get to it quickly. That being said if you want to put up a PR with a fix we'd be more than happy to review it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants