如何将Swagger集成到我现有的OAuth服务器Spring Boot应用程序中?

我们有一个使用春季启动功能创建的OAuth2服务器端应用程序,我是大手大脚的初学者,我想将其与我现有的Oauth服务器应用程序集成。

liu461520 回答:如何将Swagger集成到我现有的OAuth服务器Spring Boot应用程序中?

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

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

然后创建/重用Spring配置(由@EnableSwagger2注释标记),在此进行解释: http://springfox.github.io/springfox/docs/current/#quick-start-guides

然后,您可以自定义如何以灵活的方式记录控制器的文档(例如@ApiOperation注释):

    @ApiOperation(value = "Get user by id",httpMethod = "GET")
    @GetMapping("/users/{id}")
    public APIUser getUser(@PathVariable("id") Long id){
        ...
    }
本文链接:https://www.f2er.com/3075994.html

大家都在问