如何更改Springfox Swagger 2.0的basePath

Mar*_*nov 20 swagger-ui swagger-2.0 springfox

我正在运行一个服务,可以在以下位置访问Swagger UI:

http://serviceURL/swagger-ui.html
Run Code Online (Sandbox Code Playgroud)

但是,它位于代理之后,例如:

http://proxyURL/serviceName
Run Code Online (Sandbox Code Playgroud)

Swagger UI生成的URL看起来像:

http://proxyURL/
Run Code Online (Sandbox Code Playgroud)

而不是具有serviceName作为后缀的实际URL.据我所知,这意味着操纵basePath属性.根据文件:

swagger API文档无法再描述不同基本路径上的操作.在1.2及更早版本中,每个资源都可以有一个单独的basePath.在2.0中,为整个规范定义了basePath等价物(scheme + host + basePath).

@Api(basePath)已弃用,它没有说明使用什么以及如何使用它.如何使Swagger生成的路径正确显示?

我正在使用Spring Boot,Springfox Swagger和注释.

ast*_*eny 7

@Bean
public Docket newsApi(ServletContext servletContext) {
    return new Docket(DocumentationType.SWAGGER_2).pathProvider(new RelativePathProvider(servletContext) {
        @Override
        public String getApplicationBasePath() {
            return "/serviceName" + super.getApplicationBasePath();
        }
    }).host("proxyURL");
}
Run Code Online (Sandbox Code Playgroud)