禁用默认的 Swagger jaxrs2 openapi url
Disable default Swagger jaxrs2 openapi url
我们正在大张旗鼓地记录我们的 JAX-RS API。通过使用 swagger-jaxrs2
包,我们可以很好地创建我们的 api 文档。
我们唯一要更改的是:默认值 "openapi"-Url。
通过注册 Swaggers OpenApiResource Class,我们的应用程序每次都会生成默认的 "[host]/openapi"
端点。
我们可以创建自己的服务于开放api规范的端点,但我们无法禁用此默认端点。
欢迎任何提示!提前坦克你
我们解决了一个变通方法:修改 javax.ws.rs.core.Application
以仅加载我们自己提供的端点,忽略任何其他 3rdParty 端点,如 swagger-jaxrs2 openapi
或 openapi.{type:json|yaml}
@ApplicationPath("")
public class OurApplication extends javax.ws.rs.core.Application {
@Override
public Set<Class<?>> getClasses() {
// Start detecting only classes in your package! provided 3rdParty packages
// (like io.swagger.v3.jaxrs2.integration.resources) won't be provided
Reflections ourClasses = new Reflections("our.package.naming");
// Scan your classed for @javax.ws.rs.Path Annotaion. We need just collect
// API-Endpoints
Set<Class<?>> ourEndpoints = ourClasses.getTypesAnnotatedWith(Path.class);
// fyi - log the registered classes / endpoints
System.out.println("Providing "+ ourEndpoints);
// return endpoints to provide it in your application
return ourEndpoints;
}
}
提示:由于@ApplicationPath 注释,无需修改web.xml。
我们使用的Reflections由maven提供:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.12</version>
</dependency>
观看 https://github.com/ronmamo/reflections 了解有关反射包的更多信息。
我们没有找到更好的解决方案,但这对我们有用。好好享受吧。
我们正在大张旗鼓地记录我们的 JAX-RS API。通过使用 swagger-jaxrs2
包,我们可以很好地创建我们的 api 文档。
我们唯一要更改的是:默认值 "openapi"-Url。
通过注册 Swaggers OpenApiResource Class,我们的应用程序每次都会生成默认的 "[host]/openapi"
端点。
我们可以创建自己的服务于开放api规范的端点,但我们无法禁用此默认端点。
欢迎任何提示!提前坦克你
我们解决了一个变通方法:修改 javax.ws.rs.core.Application
以仅加载我们自己提供的端点,忽略任何其他 3rdParty 端点,如 swagger-jaxrs2 openapi
或 openapi.{type:json|yaml}
@ApplicationPath("")
public class OurApplication extends javax.ws.rs.core.Application {
@Override
public Set<Class<?>> getClasses() {
// Start detecting only classes in your package! provided 3rdParty packages
// (like io.swagger.v3.jaxrs2.integration.resources) won't be provided
Reflections ourClasses = new Reflections("our.package.naming");
// Scan your classed for @javax.ws.rs.Path Annotaion. We need just collect
// API-Endpoints
Set<Class<?>> ourEndpoints = ourClasses.getTypesAnnotatedWith(Path.class);
// fyi - log the registered classes / endpoints
System.out.println("Providing "+ ourEndpoints);
// return endpoints to provide it in your application
return ourEndpoints;
}
}
提示:由于@ApplicationPath 注释,无需修改web.xml。
我们使用的Reflections由maven提供:
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.12</version>
</dependency>
观看 https://github.com/ronmamo/reflections 了解有关反射包的更多信息。
我们没有找到更好的解决方案,但这对我们有用。好好享受吧。