Swagger 2.0 where to declare Basic Auth Schema

前端 未结 3 2239
自闭症患者
自闭症患者 2021-02-18 16:48

How do I define basic authentication using Swagger 2.0 annotations and have it display in swagger UI.

In the resource I have:

@ApiOperation(value = \"Re         


        
3条回答
  •  既然无缘
    2021-02-18 17:32

    Using Springfox 2.6 annotations, you must first define Basic authentication as one of the security schemes when you set up the Docket in your configuration, like this:

    List schemeList = new ArrayList<>();
    schemeList.add(new BasicAuth("basicAuth"));
    
    return new 
      Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo)
                                         .securitySchemes(schemeList)
                                         ...
    

    Then you can use the Springfox annotations in your service to set Basic Auth for the operation for which you want to require authentication:

    @ApiOperation(value = "Return list of categories", response=Category.class, responseContainer="List", httpMethod="GET", authorizations = {@Authorization(value="basicAuth")})
    public Response getCategories();
    

提交回复
热议问题