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

not going inside custom resolver if absolute path is same but realtive path is different #350

Open utkarsh1222 opened 3 months ago

utkarsh1222 commented 3 months ago

while dereferencing the schema my logic written inside custom resolver is not getting executed because I think its just checking the absolute path and returns the resolved value from the cache. Code is: $RefParser.dereference(schemaObject, { abc: { order: 1, canRead: /^abc:/i, read: async (file, callback) => { const id = file.url.replace(/^abc:/, ''); const result = await api.fetchResource(id); const resolvedSchema = structuredClone(result); callback(null, resolvedSchema) } } });

in this case if I am having two $ref like "abc:12345#/schema/firstSchema" and "abc:12345#/schema/secondSchema". then first time it will go inside custom resolver but for the second ref it is not going.

Is there anyway I can prevent this because I wanted to add a check inside custom resolver itself to check if the schema mentioned in relative path exists or not, if not then it should return {} instead of throwing error.