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

feat: add support for options.dereference.onDereference #272

Closed
wants to merge 2 commits into from

Conversation

bcherny
Copy link
Contributor

@bcherny bcherny commented Jun 29, 2022

This callback is needed for bcherny/json-schema-to-typescript#453, in order to more intelligently emit TypeScript types from JSON Schemas. Specifically, this change lets us use referenced names for type names, which results in more intuitive and human-readable types. I've implemented it as a generic hook for json-schema-ref-parser.

path.includes("/example/")
path.includes("/example/"),
onDereference: (path, value) => // Callback invoked during dereferencing
console.log(path, value)

Choose a reason for hiding this comment

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

is this an C&P artifact or intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is intended. It's the documentation.

@philsturgeon
Copy link
Member

Hi I'm trying to get this merged via a new pull request, and got past the linting issues. Now it's giving me a failed test, could you take a look?

  File names with special characters
    1) should parse successfully


  0 passing (47ms)
  1 failing

  1) File names with special characters
       should parse successfully:
     TypeError [ERR_INVALID_URL]: Invalid URL: specs/__(%7B%5B%20%25%20&%20$%20%23%20@%20%60%20~%20,)%7D%5D__/__(%7B%5B%20%25%20&%20$%20%23%20@%20%60%20~%20,)%7D%5D__.yaml
      at new NodeError (internal/errors.js:322:7)
      at onParseError (internal/url.js:270:9)
      at new URL (internal/url.js:346:5)
      at Object.resolve (lib\util\url.js:8:136)
      at $RefParser.parse (lib\index.js:46:39)
      at Context.<anonymous> (test\specs\__({[ % & $ # @ ` ~ ,)}]__\special-characters.spec.js:13:33)
      at processImmediate (internal/timers.js:464:21)

@philsturgeon
Copy link
Member

Turns out that issue is unrelated to this PR so I've got it merged! Thank you.

If you could help fix #283 that would be ideal but either way this change will be out in the next release.

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.

3 participants