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
942 stars 226 forks source link

feat: add object and propName to onDereference callback #324

Closed toomuchdesign closed 5 months ago

toomuchdesign commented 11 months ago

This is an implementation proposal to add 2 new arguments to dereference.onDereference options.

The 2 new arguments are:

In other words: the current 2nd onDereference argument (the inlined schema) would be the result of object[propName].

Extra info

Exposing a callback with 4 arguments is probably sub optimal in terms of API. In a next major release the callback could be refactored to accept an object to provide named arguments.

The idea behind this PR was born while developing openapi-ts-json-schema, where json-schema-ref-parser's onDereference callback is used to append meta data to the dereferenced objects. This would sensibly provide more flexibility and power to the callback.

I'm aware it could be quite niche use case and I'll be fine whatever decision you are going to take about this PR. Happy to update this PR based on you feedback, if the case.

Thank you so much for the priceless work you are doing here! 🙌 Cheers!

coveralls commented 5 months ago

Pull Request Test Coverage Report for Build 8160456238

Details


Totals Coverage Status
Change from base Build 8160379361: 0.05%
Covered Lines: 3219
Relevant Lines: 3318

💛 - Coveralls
github-actions[bot] commented 5 months ago

:tada: This PR is included in version 11.2.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: