APIDevTools / json-schema-ref-parser

Parse, Resolve, and Dereference JSON Schema $ref pointers in Node and browsers
https://apitools.dev/json-schema-ref-parser
MIT License
952 stars 227 forks source link

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

Closed bcherny closed 1 year ago

bcherny commented 2 years ago

This callback is needed for https://github.com/bcherny/json-schema-to-typescript/pull/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.

philsturgeon commented 1 year ago

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 commented 1 year ago

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.