【发布时间】:2019-02-28 04:58:27
【问题描述】:
我对 spring fox swagger ui base url 感到困惑,他们没有指向正确的 url。
我刚刚在上下文中部署了一场战争,所以应用程序位于 127.0.0.1:8080/bff,我设法添加了招摇和成功,现在它在 127.0.0.1:8080/bff/swagger-ui.html 中运行,但是当我尝试测试 API 时,它指向 @987654325 @。为什么会有v2/api-docs!?
我知道 swagger-ui 上的 API 列表是从那个列表中填充的,但是为什么在我们测试 API 时它会被注入到 URL 中?因为我所有的 API 都在 127.0.0.1:8080/bff/api/v1
这是代码。
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Autowired
private GitVersionPropertiesConfig gitVersionPropertiesConfig;
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.globalOperationParameters(
Lists.newArrayList(new ParameterBuilder()
.name("Authorization")
.description("OAUTH2 Token")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.build()))
.apiInfo(apiInfo())
.pathMapping("/")
.pathProvider(new RelativePathProvider(null) {
@Override
public String getApplicationBasePath() {
return "/bff/";
}
})
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/api.*"))
.build();
}
ApiInfo apiInfo() {
String desc = "Bima Friends Forever API<br>"
+ "Current Branch : <b>"+gitVersionPropertiesConfig.getGitBranch()+"</b><br>"
+ "Timestamp : <b>"+gitVersionPropertiesConfig.getGitBuildTime()+"</b>";
return new ApiInfoBuilder()
.title("BFF - Hutchison")
.description(desc)
.version(gitVersionPropertiesConfig.getGitCommitIdAbbrev())
.build();
}
}
这是临时修复,但不是永久性的。
打开浏览器控制台,运行window.swaggerUi.api.setBasePath('/bff');
服务器:Wildfly 招摇用户界面版本:2.7.0
提前致谢。
【问题讨论】:
-
使用 springfox-swagger 2.9.2,您将看到您的基本 url 作为您的主机名/bff。顺便说一句,我没有使用 pathProvider。 contextPath 是自动解析的。
-
我使用那个 pathProvider 因为这里有人说该方法将覆盖 basePath,但它也不起作用....好吧,我将尝试更新到该版本,将更新结果尽快
-
更新:springfox-swagger 2.9.2 上仍然存在问题
标签: spring swagger swagger-ui springfox