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

External reference cannot be referenced multiple times within the same schema #194

Closed
rjfredrick opened this issue Oct 5, 2020 · 1 comment

Comments

@rjfredrick
Copy link

Say I have a schema that looks like this:

"description": "some schema",
"properties": {
  "background_color": {
    "$ref": "./color.json"
  },
  "foreground_color": {
    "$ref": "./color.json"
    }
}
  • background_color is resolved correctly but foreground_color is undefined due to the following:

resolve-external.js

// resolving for foreground_color ends up in the if-block, due to parse call on background_color,
// but the value is undefined

if ($ref) {
  // We've already parsed this $ref, so use the existing value
  return Promise.resolve($ref.value);
}

parse.js

// parse is called for background_color and adds the path to $refs but the value is `undefined` 
// until the promise is resolved

// Remove the URL fragment, if any
path = url.stripHash(path);

// Add a new $Ref for this file, even though we don't have the value yet.
// This ensures that we don't simultaneously read & parse the same file multiple times
let $ref = $refs._add(path);
...

const parser = await parseFile(file, options, $refs);
$ref.value = parser.result;
@rjfredrick
Copy link
Author

I was using bundle when should have been using dereference, closing issue.

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

1 participant