whitlockjc / json-refs

Various utilities for JSON Pointers (http://tools.ietf.org/html/rfc6901) and JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find a way to use a custom ref resolver

alasdairhurst opened this issue · comments

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).

I will get started on whitlockjc/path-loader#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.

Issue # 1, nice.