Skip to content
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

Deep linking for models #1369

Open
ghost opened this issue Jun 12, 2015 · 16 comments
Open

Deep linking for models #1369

ghost opened this issue Jun 12, 2015 · 16 comments

Comments

@ghost
Copy link

ghost commented Jun 12, 2015

For large complex models, it'd be very nice to be able to click on a type that's referenced in some property and have it link to the schema for that type (especially since types aren't displayed in any particular order, so scrolling to find them can be tedious). The current styling actually makes the type names look like links, but they're not.

@dijikul
Copy link

dijikul commented Jan 25, 2017

+1

We need the ability to display JSON models separate from APIs. The use case cares not for paths or HTTP Verbs; simply how the JSON model is structured along with its data types.

@webron
Copy link
Contributor

webron commented Mar 20, 2017

I believe this is covered by 3.0 now. If not, please reopen.

@webron webron closed this as completed Mar 20, 2017
@patcon
Copy link

patcon commented Sep 26, 2017

Can anyone give an example deeplink to a model from http://petstore.swagger.io/? They don't see to be linkable, as far as I can tell :) Thanks!

@patcon
Copy link

patcon commented Sep 26, 2017

Seems models aren't included? #2884 (comment)

Can we re-open?

@CameronGo
Copy link

I too would like to see deep links for models. It would be helpful when attempting to refer a customer/partner to a particular section of the documentation.

@Lakmus85
Copy link

+1. I was thinking something is wrong with the way I enable Deep Linking in the setup, but it turned out there's no deep linking for model / definitions. Nice feature to have.

@MrFix93
Copy link

MrFix93 commented Feb 22, 2019

+1. It would be very nice to be able to link to these model definitions. My specific use-case is to link request and response models in sequence diagrams to swagger specs.

@gigaga
Copy link

gigaga commented Oct 11, 2019

+1 :)

@Xophe
Copy link

Xophe commented Nov 6, 2019

I have the same need : link my documentation to the swagger specs

@PeterKottas
Copy link

PeterKottas commented Mar 3, 2020

Weird that this is still not implemented. At least I was not able to find it. Anyways, here's how you can do it:

document.addEventListener("DOMContentLoaded", function (event) {
    var elemId = window.location.hash.replace('!/', '').replace('/', '').replace('#','');
    setTimeout(function () {
        var elem = document.getElementById(elemId );
        if (elem) {
            var top = elem.offsetTop;
            window.scrollTo({ top: top, behavior: 'auto' });
            var anchor = elem.querySelector('.model');
            if (anchor) {
                anchor.click();
            }
        }
    }, 700);
});

This obviously goes into a javascript that you inject via:

c.InjectJavascript("/path/to/your-file.js");

Also remember to enable StaticFiles middleware in dot net core.

@mdhtr
Copy link

mdhtr commented May 7, 2020

+1: If someone would like to implement HATEOAS link relations, they would need to provide a uri to the specification of the object. I would like to use the Model object in Swagger UI for this purpose, with a deep link.

@mdhtr mdhtr mentioned this issue May 8, 2020
17 tasks
@mdhtr
Copy link

mdhtr commented May 10, 2020

I started implementing the part where it would be possible to expand and scroll to a model by specifying a reference to it in the URL.

I'm curious if anyone would still like to have the original feature request implemented? It was, in my understanding, to be able to navigate to a model definition by clicking that model's name in another model or in an operation definition. If yes, how would you expect it to work? Because currently if you click on a model's name it expands/collapses, so I don't know where would the link navigation fit into this behavior. Any ideas?

@olli-miettinen-arm
Copy link

@mdhtr Would it be possible to expand only from the > symbol, and have the name as a link?

@reinseth
Copy link

reinseth commented Jan 8, 2021

A non-breaking way for the existing expand/collapse functionality could be to add a link next to the name, with the text "link" / "permalink" / "🔗" or similar.

@rocklan
Copy link

rocklan commented Jul 23, 2021

@PeterKottas thanks for the code! A minor bug, if the model is near the bottom of the page it doesn't scroll down far enough, because the link hasn't been expanded yet and the offsetTop won't be correct after the click. This can be fixed by doing the scrolling after the click:

document.addEventListener("DOMContentLoaded", function (event) {
    var elemId = window.location.hash.replace('!/', '').replace('/', '').replace('#', '');
    setTimeout(function () {
        var elem = document.getElementById(elemId);
        if (elem) {
            var anchor = elem.querySelector('.model');
            if (anchor) {
                anchor.click();
            }
            setTimeout(function () {
                var top = elem.offsetTop;
                window.scrollTo({ top: top, behavior: 'auto' });
            }, 100);
        }
    }, 700);
});

@dirkbolte
Copy link

dirkbolte commented May 10, 2024

There's another approach with works with standard HTML mechanisms and does not require extra JavaScript or a patch. It is dependent on the current swagger implementation though and might change.

Every model div and an ID with the pattern model-<SchemaName>. You can directly link to it by adding the ID to the fragment of your URL.

Taking the Petstore example, you can directly jump to Category via the URL https://petstore.swagger.io#model-Category . If you want to add this link within a description of your YAML, you can use <a href="#model-Category">schema</a>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests