我有一个 Spring 应用程序,我在其中公开了两个休息接口以供使用。一种用于内部开发人员,另一种用于客户。
Swagger 确实在/swagger-ui.html 下生成了一个很好的文档。
在此 URL 下,它显示了内部和外部用户的文档。
这是我的代码设置:
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
@EnableSwagger2
public class Swagger2UiConfiguration extends WebMvcConfigurerAdapter {
@Bean(name="restInternalSwaggerApi")
public Docket internalApi(BuildProperties build) {
final Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName( "internal" )
.select()
.apis( RequestHandlerSelectors.basePackage("com.xyz.web.internal") )
.build();
return docket;
}
@Bean(name="restPublicSwaggerApi")
public Docket publicApi(BuildProperties build) {
final Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName( "public" )
.select()
.apis( RequestHandlerSelectors.basePackage("com.xyz.web.public") )
.build();
return docket;
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我想分离这些 swagger-ui 文档。这样我们的内部开发人员就可以像
/documentation/private/swagger-ui.html和/documentation/public/api-v1.html一样访问它
两人不见不散。怎么做?
我在这里找到了一些提示,但它们对我来说确实没有建设性:
http://sp ingfox.github.io/springfox/docs/current/#q13和链接的资源
使用 springfox Swagger Swagger
路径中的多个版本自定义文档的端点
https://github.com/springfox/springfox/issues/963
https ://github.com/springfox/springfox/issues/1263#issuecomment-210839308
如果有人愿意让我提供适当的文件,我也会很高兴。
如果问题难以理解以及如何改进,请告诉我。
有关 java 的 maven 的版本信息:
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.8.0</version>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.8.0</version>
Run Code Online (Sandbox Code Playgroud)
换句话说:
我希望 DropDown-Box 到达的不同 API 被不同的 URL 调用:
我想要这个,所以我可以用不同的 API 为客户提供不同的 URL,而不是向我的开发人员同事提供另一个 URL。
小智 0
Swagger-ui 是一个包含 html 和 css 的模块(作为解决方案的 swagger ui 包含的许多 jar 之一),因此,如果您需要多一个页面(在您的情况下为 api-v1.html),您需要再添加一个 html 。
以下是swagger-ui 的源代码,基于此我创建了一个修改后的 springfox.js 文件(适用于 2.10.5 版本),该文件允许仅显示一个具有页面 groupName== 前缀的摘要(例如,如果您有您的摘要) .groupName(" external ") 它将显示在页面external -swagger-ui.html上
因此,为了使其工作,您需要添加 2 个文件,总文件放置
请注意,html 文件也被修改为使用自定义 springfox.js,<script src="springfox.js"> </script>而不是与 springfox-ui jar 一起使用的文件。(在我的情况下,它是资源根作为你可以在截图中看到)
默认的 swagger-ui.html 对此解决方案没有干扰。