在Spring Boot中暴露给Swagger2时如何模式化API的匹配?

问题描述 投票:0回答:1

下面是我需要为其编写swagger2 API文档的控制器:

@RestController
@RequestMapping("/abc/def/pqr")
public class Controller {
    @GetMapping(path = "", consumes = "application/json", produces = "application/json")
    @ResponseBody
    public <T> PagedResources<SomeResource> get(Pageable pageable,
            Assembler assembler) {
        Page<Something> somethings = service.get(pageable);
        return pagedAssembler.toResource(somethings, assembler);
    }
}

以下是我试图通过它向API文档写信的代码:

@Bean
public Docket swaggerConfiguration() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .paths(PathSelectors.ant("/abc/def/pqr/"))
            .build()
}

但是即使编写了此API,它也不会暴露于swagger2。无论在哪里,我都能理解问题,我认为PathSelectors.ant(“ / abc / def / pqr /”)中存在一些问题。因此,请有人可以帮助我,然后对我更好。

提前感谢...

spring-boot pattern-matching swagger-ui swagger-2.0
1个回答
0
投票

尝试一下

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket productApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .select()                 .apis(RequestHandlerSelectors.basePackage("your.base.package"))
                .paths(regex("/product.*"))
                .build();
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.