json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

How to see current path inside resolver?

Open qm3ster opened this issue 7 years ago • 7 comments

How can I make a custom resolver for relative paths? How do I see the path from which the $ref originates?

qm3ster avatar Aug 27 '18 01:08 qm3ster

Unfortunately, there's not currently a way to determine the source of the $ref inside a resolver. It only gives you the $ref itself. It would be a good idea to add though. I'd gladly accept a PR for it too.

JamesMessinger avatar Aug 27 '18 11:08 JamesMessinger

I'm on it. Should be on the file object, right, not as another param? This way it's a non-breaking change too.

qm3ster avatar Aug 27 '18 15:08 qm3ster

Yup. That's what I was thinking as well. Thanks for helping out! 🥇 💯

JamesMessinger avatar Aug 27 '18 15:08 JamesMessinger

@qm3ster - have you made any progress on this? I was thinking of tackling it this weekend as I need it too.

Any hints on which file(s) to look at - that would speed things up for me if you already know that.

ziadsawalha avatar Apr 07 '19 08:04 ziadsawalha

@ziadsawalha no, sorry. I started, but I don't think I have that branch any more.

qm3ster avatar Apr 07 '19 15:04 qm3ster

This is where the file object is created - https://github.com/APIDevTools/json-schema-ref-parser/blob/master/lib/parse.js#L29

qm3ster avatar Apr 07 '19 16:04 qm3ster

Thanks @qm3ster. After digging into this a little it turns out the behavior I was looking for was already implemented correctly.

My issue turned out to be a bug in https://github.com/maxdome/swagger-combine where it resolved files in relation to cwd and not the file itself.

ziadsawalha avatar Apr 07 '19 21:04 ziadsawalha

Implemented in #124.

philsturgeon avatar Nov 26 '22 13:11 philsturgeon