我们的应用程序部署在使用以下代码开发的 DC/OS 内 spring boot (2.0.6.RELEASE) 和 swagger (2.6.1)。
我们遇到的问题是通过访问 swagger
https://api.example.com/appname/swagger-ui.html这工作正常,并通过我们所有的 REST 端点返回 swagger UI。
当我尝试通过 swagger 请求我们的 API 时,此主机名将更改为 https://api.example.com:80
Wrong request URL generated by swagger - https://api.example.com:80/health
Correct request URL should be https://api.example.com/appname/health
我们的配置
@SpringBootApplication
@EnableSwagger2
public class AppConfig {
public static void main(String[] args) {
SpringApplication.run(AppConfig.class, args);
}
}
我想了解
- 如何为请求 URL 生成主机名?
- 为什么不是基于访问的URL的相对路径?
- 如何配置 swagger 的这个基本 url,以便请求 url 可以基于用于访问 swagger 的 URL 进行相对。
最佳答案
您可以查看Springfox Swagger generating requests with port 80 for HTTPS URLS对于报告的类似问题
您可以设置属性
springfox.documentation.swagger.v2.host=api.example.com
或者通过配置API
docket.host("your host url")
关于spring-boot - Swagger 为 REST 端点生成的主机名无效 REQUEST url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53929469/