Swagger-ui anchor link to model definitions
Asked Answered
A

2

12

Is it possible to access a model definition of via swagger-ui directly via an anchor?

In the example page http://petstore.swagger.io/ I see that the anchor works for a groups of endpoints, e.g. http://petstore.swagger.io/#/pet.

Hovering the mouse over a model description shows me an anchor (e.g. #/definitions/Category for the Category model), but http://petstore.swagger.io/#/definitions/Category does not bring me there.

If I inspect the elements, I see a real link to anchor pet:

<a class="nostyle" href="#/pet"><span>pet</span></a>

while for Category this is a model-hint:

<span class="model-hint">#/definitions/Category</span>

So I wonder if anchoring models is supported at all..

Antagonism answered 19/10, 2017 at 10:6 Comment(0)
B
4

Swagger UI does not support permalinks for schemas/models. There's an existing feature request:
https://github.com/swagger-api/swagger-ui/issues/1369

Bromo answered 11/8, 2020 at 9:35 Comment(0)
D
2

This can be achieved with built-in HTML mechanisms:

Every model in swagger is within a div . These divs have an ID with the schema model-<ModelName . Adding them as fragment to your URL allows you to jump to them directly. Taking the petstore example, this would be: https://petstore.swagger.io/#model-Category .

If you want to embed a link in a description of your swagger document to create a local link, you can use: <a href="#model-<SchemaName>">schema</a>, e.g. <a href="#model-Category">schema</a>

Dispel answered 10/5 at 8:8 Comment(1)
Thanks for this answer, it works for me, but Models must be expanded when the page is loaded, Swagger can be configured for that.Transduction

© 2022 - 2024 — McMap. All rights reserved.