Swagger UI nested expandable groupings

2019-07-27 17:29发布

I am using SwaggerUI for documenting API endpoints. Currently they are grouped by controller name, in one long list. You can then expand each controller to view the operations. Everything standard.

What I would like to do, is group the controllers under common expandable groups.

So for example, you have a Pet group, which can be expanded, to reveal Cat and Dog controllers, which can then in turn be expanded to show their respective operations.

I have tried using Tags to accomplish this, but the best I can get is all operations grouped under one expandable group.

Does anyone know if this is possible with the standard swaggerUI? Or would I need to create custom HTML to accomplish this?

1条回答
Explosion°爆炸
2楼-- · 2019-07-27 18:13

I assume you are using Swashbuckle? What you need is to implement IDocumentFilter. Look in to the tags om the Swagger 2.0 Spec.

From the docs:

DocumentFilter

Post-modify the entire Swagger document by wiring up one or more Document filters.

IDocumentFilter has the following interface:

void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer);

This gives full control to modify the final SwaggerDocument. You can gain additional context from the provided SwaggerDocument (e.g. version) and IApiExplorer. You should have a good understanding of the Swagger 2.0 spec. before using this option.

查看更多
登录 后发表回答