【问题标题】:How to integrat Swagger to my existing OAuth server spring boot application?如何将 Swagger 集成到我现有的 OAuth 服务器 Spring Boot 应用程序中?
【发布时间】:2020-03-14 14:09:49
【问题描述】:

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

【问题讨论】:

  • @snieguu,您提供的答案是正确的,但我想提一下,在邮递员中测试生成的令牌,必须通过浏览器中的标头。
  • 如果答案正确,请采纳:)

标签: spring-security-oauth2 swagger-2.0


【解决方案1】:

首先,现在也有Swagger 3.0,正式名称为OpenAPI Specification,但你要求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

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

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-24
  • 1970-01-01
  • 2011-07-13
  • 2019-01-31
  • 1970-01-01
  • 2020-03-20
  • 1970-01-01
相关资源
最近更新 更多