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

$ref support #12

Merged
merged 5 commits into from
Oct 8, 2016
Merged

$ref support #12

merged 5 commits into from
Oct 8, 2016

Conversation

delvedor
Copy link
Member

@delvedor delvedor commented Oct 7, 2016

As titled.
This implementation supports both internal and external definitions.

Caveats:
If the user is using an external json file for his definitions it must use __dirname to get the correct path.
See the following example (the same of the test).

const schema = {
  title: 'object with $ref',
  type: 'object',
  properties: {
    obj: {
      $ref: __dirname + '/ref.json#/definitions/def'
    }
  }
}

If everything is ok to you I can update the docs.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, one minor issue on the use of require.

// If external file
if (ref[0]) {
schema = require(ref[0])
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never do this, it's sync and done in a place where it might cause to bugs. We should not load files into Node. However, we should use an approach similar to https://www.npmjs.com/package/is-my-json-valid#external-schemas.

for (let i = 1; i < walk.length; i++) {
code += `['${walk[i]}']`
}
return (new Function('schema', code))(schema)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!!!!

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor delvedor merged commit b7146d1 into master Oct 8, 2016
@delvedor delvedor deleted the $ref-support branch October 8, 2016 13:32
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

Successfully merging this pull request may close these issues.

None yet

2 participants