-
Notifications
You must be signed in to change notification settings - Fork 21
Description
Describe the bug
The documentation specifies that the second arg of dereferenceDocument is a custom resolved. It doesn't specify what the type of that resolver is but it seems to be using an outdated class instance from json-schema-tools/dereferencer. But no matter what you pass to the arg the output is never different. Methods don't run even when the protocols match specified ones.
To Reproduce
Steps to reproduce the behavior:
- Create an OpenRPC spec with at least one $ref field to an external location (separate file or https link for example).
- Create a custom resolver.
- Call
dereferenceDocumentand pass the custom resolver into the second argument.
Here's an example that just console logs method args:
const customResolver = {
protocolHandlerMap: {
file: async (uri: string, _root: JSONSchema) => {
console.log("URI", uri);
console.log("ROOT", _root);
return Promise.resolve({});
},
},
};
const resolvedSpec = await dereferenceDocument(spec, customResolver)Expected behavior
The file method should run first, before custom specified protocols. But neither it nor other protocols in protocolHandlerMap ever run. The console.logs in the example above never occur.
However, if you instead override the default protocolHanderMap it does work. This example works:
const defaultFileResolver = defaultResolver.protocolHandlerMap.file;
defaultResolver.protocolHandlerMap.file = async (
uri: string,
_root: JSONSchema,
) => {
console.log("URI", uri);
console.log("root", _root);
return Promise.resolve({});
};
const resolvedSpec = await dereferenceDocument(spec)We shouldn't have to do this just to resolve non-local files.
The resolver arg should also have its type documented.
Desktop (please complete the following information):
- OS: macOS 14.7.6
- Browser: Chrome but running this in local scripts
- Version: 2.1.2