如何更改 Springfox Swagger 2.0 的 basePath

编程入门 行业动态 更新时间:2024-10-18 16:54:07
本文介绍了如何更改 Springfox Swagger 2.0 的 basePath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I'm running a service, where Swagger UI is accessible at:

serviceURL/swagger-ui.html

但是,它是在代理后面的,比如:

However, it is behind a proxy, such as:

proxyURL/serviceName

由 Swagger UI 生成的 URL 如下所示:

Generated URLs by Swagger UI are looking like:

proxyURL/

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

instead of the actual URL with the serviceName as suffix. As far as I get it, this means manipulating the basePath property. As per documentation:

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

A swagger API documentation can no longer describe operations on different base paths. In 1.2 and earlier, each resource could have had a separate basePath. In 2.0, the basePath equivalents (schemes+host+basePath) are defined for the whole specification.

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

@Api(basePath) is deprecated, and it doesn't say what to use and how to use it. How to make the paths generated by Swagger appear properly?

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

I'm using Spring Boot, Springfox Swagger and annotations.

推荐答案

@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"); }

更多推荐

如何更改 Springfox Swagger 2.0 的 basePath

本文发布于:2023-11-16 14:33:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1605150.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何更改   Springfox   Swagger   basePath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!