Swagger基本授权不适用于@Api注释

时间:2019-04-27 17:24:16

标签: java spring spring-boot swagger-ui swagger-2.0

Swagger基本授权不适用于@Api注释。但是与@Apioperation一起使用时,它可以正常工作。我想在控制器级别而不是方法级别应用基本授权。

像这样使用:

@RestController
@Slf4j
@Api(value="API related ",authorizations = {@Authorization(value="basicAuth")})
@RequestMapping(value="invoices",produces =MediaType.APPLICATION_JSON_UTF8_VALUE)
@SuppressWarnings("rawtypes")
public class InvoiceController {


@SuppressWarnings("unchecked")
    @GetMapping
    @ApiOperation(value = "${InvoiceController.getAll.notes}", notes="${InvoiceController.getAll.notes}",response = Invoice.class)
    @ApiResponses(value = {@ApiResponse(code = 200, message = "Successfully retrieved list of invoices")})
    public  @ResponseBody ResponseEntity<Response> getAll(@Valid PaginationDto pagination,@Valid InvoiceFilterCriteriaDto filter) 
                    throws GenericServiceException{

}


}

在主类中,通过提及基本auth来创建如下所示的Docket:

        List<SecurityScheme> schemeList = new ArrayList<>();
        schemeList.add(new BasicAuth("basicAuth"));


        return new Docket(DocumentationType.SWAGGER_2)
                .forCodeGeneration(true)
                .produces(new HashSet<>(Arrays.asList( new String[] { MediaType.APPLICATION_JSON_UTF8_VALUE.toString()})))
                .apiInfo(apiInfo())
                .securitySchemes(schemeList)

0 个答案:

没有答案