Spring Boot & Swagger UI. Set JWT token

前端 未结 4 1223
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 14:57

I have a Swagger config like this

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Bean
    public Docket api() {
        List

        
4条回答
  •  醉话见心
    2020-12-23 15:28

    For swagger version 2.9.2

    1. Create a SwaggerConfig class.

      @Bean
      public Docket api() {
          return new Docket(DocumentationType.SWAGGER_2)
                  .select()
                  .apis(RequestHandlerSelectors.any())
                  .paths(PathSelectors.any())
                  .build()
                  .apiInfo(apiInfo())
                  .securitySchemes(Arrays.asList(apiKey()));
      }
      
      private ApiInfo apiInfo() {
          return new ApiInfoBuilder()
                  .title("Sig-Predict REST API Document")
                  .description("work in progress")
                  .termsOfServiceUrl("localhost")
                  .version("1.0")
                  .build();
      }
      
      private ApiKey apiKey() {
          return new ApiKey("jwtToken", "Authorization", "header");
      }
      
      1. Then annotate each API you would like to send this Authorization header to with:

        @ApiOperation(value = "", authorizations = { @Authorization(value="jwtToken") })
        

提交回复
热议问题