如何将 Swagger 集成到我现有的 OAuth 服务器 spring 启动应用程序?

How to integrat Swagger to my existing OAuth server spring boot application?

我们有使用 spring 引导创建的 OAuth2 服务器端应用程序,我是 swagger 的初学者,我想将它与我现有的 Oauth 服务器应用程序集成。

首先,现在它也可用 Swagger 3.0,正式称为 OpenAPI 规范,但你要求 招摇 2.0。所以,在我看来,最好的选择是使用 Spring Fox - https://springfox.github.io/springfox/ 你只需要添加依赖:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>

然后是create/reuseSpring配置(用@EnableSwagger2注解标注),这里解释一下: http://springfox.github.io/springfox/docs/current/#quick-start-guides

然后您可以自定义 swagger 如何以这种方式记录您的控制器(例如 @ApiOperation 注释):

    @ApiOperation(value = "Get user by id", httpMethod = "GET")
    @GetMapping("/users/{id}")
    public APIUser getUser(@PathVariable("id") Long id){
        ...
    }