json-refs icon indicating copy to clipboard operation
json-refs copied to clipboard

Cannot find a way to use a custom ref resolver

Open alasdairhurst opened this issue 6 years ago • 2 comments
trafficstars

I have a swagger document with references which are valid JSON schema references (URIs), These are references to an internal library of schemas which understands this URI with a "schema://" protocol. Currently, I don't see any way of providing a function to resolve references myself. The preprocessor would be the only visible place to do this, although the output of the preprocessor has to be something which is still not dereferenced, otherwise you will end up getting the following error: (there should probably be a check on the return value of refPreProcessor to validate that the value is still ref-like.

{code} TypeError: Cannot read property 'reference' of undefined at getRefType (C:\git\s\node_modules\json-refs\index.js:156:33) at refFilter (C:\git\s\node_modules\json-refs\index.js:258:77) at C:\git\s\node_modules\json-refs\index.js:269:82 at C:\git\s\node_modules\json-refs\index.js:269:82 at Object.filter (C:\git\s\node_modules\json-refs\index.js:269:82) at C:\git\s\node_modules\json-refs\index.js:606:24 at walk (C:\git\s\node_modules\json-refs\index.js:436:23) at walkItem (C:\git\s\node_modules\json-refs\index.js:430:5) at C:\git\s\node_modules\json-refs\index.js:450:11 at C:\git\s\node_modules\lodash\lodash.js:4911:15 {code}

I'd like to be able to provide an async function/promise/function with callback with similar parameters to refPreProcessor, so that I can resolve specific references myself and then fall back to json-refs if this was not possible (for example by returning/resolving with the original ref-like object).

alasdairhurst avatar Dec 12 '18 16:12 alasdairhurst

I will get started on https://github.com/whitlockjc/path-loader/issues/1, update json-refs to use the new version of path-loader and then you could pass on options.jsonRefs.loaderOptions to use a custom loader.

whitlockjc avatar Dec 13 '18 21:12 whitlockjc

Issue # 1, nice.

alasdairhurst avatar Dec 13 '18 21:12 alasdairhurst