Swagger UI嵌套的可扩展分组 [英] Swagger UI nested expandable groupings

查看:230
本文介绍了Swagger UI嵌套的可扩展分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用SwaggerUI记录API端点.当前,它们按控制器名称分组在一个很长的列表中.然后,您可以展开每个控制器以查看操作.一切都很标准.

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.

例如,您有一个Pet组,可以进行扩展以显示Cat和Dog控制器,然后可以将其扩展以显示其各自的操作.

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.

有人知道标准swaggerUI是否可以做到吗?还是我需要创建自定义HTML才能完成此任务?

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

推荐答案

我假设您正在使用Swashbuckle?您需要实现IDocumentFilter.查看 Swagger 2.0 Spec 中的标签.

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

来自文档:

DocumentFilter

通过连接一个或多个文档过滤器,对整个Swagger文档进行后修改.

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

IDocumentFilter具有以下接口:

IDocumentFilter has the following interface:

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

这可以完全控制修改最终的SwaggerDocument.您可以从提供的SwaggerDocument(例如版本)和IApiExplorer中获得其他上下文.您应该对Swagger 2.0规范有很好的了解.在使用此选项之前.

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.

这篇关于Swagger UI嵌套的可扩展分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆