[英]SpringFox Swagger UI has wrong base url
I got confused with spring fox swagger ui base url, they are not pointing to correct url. 我对spring fox swagger ui基本URL感到困惑,他们没有指向正确的URL。
I just deployed a war in a context, so the app is in 127.0.0.1:8080/bff
, i managed to add swagger and success, now its running in 127.0.0.1:8080/bff/swagger-ui.html
, but when i try to test the api its pointing to 127.0.0.1:8080/bff/v2/api-docs/api/v1/home/profile
. 我只是在上下文中部署了一次战争,因此该应用程序位于
127.0.0.1:8080/bff
,我设法增加了成功和成功,现在它运行在127.0.0.1:8080/bff/swagger-ui.html
,但是当我尝试测试api指向127.0.0.1:8080/bff/v2/api-docs/api/v1/home/profile
指向。 Why there is v2/api-docs
!? 为什么会有
v2/api-docs
I know the API list on the swagger-ui is populated from that one, but why it's injected to URL when we test the API? 我知道swagger-ui上的API列表就是从该列表填充的,但是为什么我们在测试API时将其注入URL? because all of my API lay on the
127.0.0.1:8080/bff/api/v1
因为我所有的API都位于
127.0.0.1:8080/bff/api/v1
This is the code. 这是代码。
@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();
}
}
This is the temporary fix, but not permanent. 这是临时解决方法,但不是永久解决方法。
Open browser console and run window.swaggerUi.api.setBasePath('/bff');
打开浏览器控制台并运行window.swaggerUi.api.setBasePath('/ bff');
Server : Wildfly Swagger UI Version : 2.7.0 服务器:Wildfly Swagger UI版本:2.7.0
Thanks in advance. 提前致谢。
I manage to fix it.. the culprit was jboss-web.xml context 我设法解决它。.罪魁祸首是jboss-web.xml上下文
Previously 先前
<jboss-web>
<context-root>/bff/</context-root>
</jboss-web>
Fix : 解决:
<jboss-web>
<context-root>/bff</context-root>
</jboss-web>
oh my god... 哦,我的上帝...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.