一个 Swagger 文件中的多个 API 文档 [英] Multiple API documentation in one Swagger file
问题描述
是否可以有多个(以某种方式分开的)REST API 文档,但只能在一个 swagger yaml 文件中?
Is it possible to have multiple (somehow separated) REST API documentations but only in one swagger yaml file?
或者 swagger yaml 可以只包含一个 API 文档吗?
Or can the swagger yaml contain only one API documentation?
因为我有 2 个由我开发的 REST API,并且我想要一个通用的 swagger ui 而不是两个,我可以使用像 Tyk 这样的网关来管理.
Because I have 2 REST API developed by me, and I want to have a common swagger ui instead of two, which I could manage with a gateway like Tyk.
推荐答案
你可以用 swagger.io 标签
You can do it with swagger.io tags
例如在 spring (springfox-swagger) 中,您只需将相同的标签放在多个 API 类上,它就会在 swagger UI 中将它们合并为一组.
For example in spring (springfox-swagger) you need just to put the same tag on multiple API classes and it will merge them in one group in the swagger UI.
@Api(value = "First API", tags = {"first-api"})
public class FirstApi { ... }
@Api(tags = {"first-api"})
public class SecondApi { ... }
在 swagger UI 中,您只会看到一个 API(first-api),其中包含来自两个类的所有方法.
In the swagger UI you will see only one API (first-api) with all the methods inside from both classes.
这篇关于一个 Swagger 文件中的多个 API 文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!