Skip to content

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

Closed
bcherny wants to merge 2 commits into
APIDevTools:mainfrom
bcherny:main
Closed

bcherny wants to merge 2 commits into
APIDevTools:mainfrom
bcherny:main

Conversation

@bcherny

@bcherny bcherny commented Jun 29, 2022

Copy link
Copy Markdown
Contributor

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.

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

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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