-
Notifications
You must be signed in to change notification settings - Fork 760
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add support for relative urls in resolver #417
Comments
Any reason for closing it? |
It's open? |
Sorry, it's the issue in swagger-ui the one that has been closed. I need more coffee. |
☕ |
Some thoughts on this request. First, relative refs will be, by definition, relative to the schema document. That means, for the swagger document at http://www.foo.com/swagger.json, the relative ref, Next, if you follow the swagger schema definition, you cannot arbitrarily put models in different locations. It is specific about where you put it. You cannot put it at So... how will relative references work? We could say |
To clarify: I think the request is more about
IMO Path Examples
Swagger Examples:Definitions from a peer file
Definitions from a sub-folder/file
Common definition in a parent folder/file
Parameter from shared definitionReally just to highlight that this would work for other
Essentially, the current resolution looks for P.S. If the resolution of |
Thank you. These all make sense and are doable but I believe are not legal in JSON schema. Let me dig into it more or perhaps @webron knows more about what is allowed. |
OK looking at this more, here are some thoughts.
For example: Pet:
properties:
id:
type: integer
format: int64
category:
$ref: "http://foo.com/bar/models/Category" and at Category:
properties:
id:
type: integer
format: int64
person:
$ref: "/models/Person" Where does The first 3 scenarios are easily supported. The fourth makes my head hurt. |
It's definitely legit in JSON Schema. I sometimes wish it wasn't...the horrors I've seen 😱 From http://spacetelescope.github.io/understanding-json-schema/structuring.html:
|
Thanks--what do you think of item 4? |
Redoing your example based on my experience of how this works (150+ repos full of linked JSON Schema).
and at http://foo.com/bar/models/Category.json:
In the revised example, However, the dot resolution adds a slightly tricky twist to think about too.
Plus there's file + anchor resolution to think about:
|
As far as I can tell, the first two are equivalent. |
@webron definitely equivalent, some folks do the dot slash (linux-ey habits I guess), which should work in premise. |
isn't the relative reference always relative to the absolute path of the containing file/resource? So in your 4th example above @fehguy it would resolve relative to the path http://foo.com/bar/models/Category - which I think is in line with what @jasonh-n-austin added!? |
@olensmar yep that's the idea. Each file resolves it's own refs, regardless where they're included from. In the |
@jasonh-n-austin - regarding |
@webron yeah I don't think it's something not worth supporting, but if there's any issue with scope, I'd make it higher on the list to kill, that's all. |
big 👍 to get this working |
Been working on it, but there are many details to finalize the cases that @jasonh-n-austin brought up (which I think are valid cases). |
🍻 => @fehguy, only after ☕ ;) |
@jasonh-n-austin this has been a grind, but I've refactored Lines 561 to 635 in 6fc1063
Note that in each test case, we're calling the resolver with the location of the spec being read (that's required for traversing the path and will happen automatically). For the test cases, we're assuming the location of the spec is this:
The expected results are captured by enumerating the
indicates that we'd be using the object at this location:
Can you please confirm that this is what is expected from the relative ref examples? This whole thing gave me a huge headache, btw. |
I have no doubt this was a tough one. I took a gander at the code, and decided I should just help quantify it in the issue instead of mangling your code (I'm not strong in Node)...glad you're performing the surgery 😷 Looked through the tests, this hits all the right scenarios...peer, parent, sub. Reviewing the cases I outlined before, these tests should cover it all. A thought: I've been fiddling with various Java, Ruby & Python-based swagger libraries in Github this week...it's going to be a long haul to get everything to support this. |
FYI @fehguy created a PR with some samples to start the discussion: |
FYI @fehguy swagger-parser has external file support built in, could be helpful |
OK I believe this is mostly working. Adding tests now, and hope to merge to develop_2.0 & close this out tonight. |
@fehguy FYI examples are merged in swagger-spec/master now: Doc updates for Reference Object next: |
No description provided.
The text was updated successfully, but these errors were encountered: