Repository: cxf Updated Branches: refs/heads/master df0c72713 -> eec5aaf5a
[CXF-7474] Checking all the resources if UI is required (always by default) and making it possible to disable it from the properties file too Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/eec5aaf5 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/eec5aaf5 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/eec5aaf5 Branch: refs/heads/master Commit: eec5aaf5a7974dffef5c25ddcbd1d0b3721660d0 Parents: df0c727 Author: Sergey Beryozkin <sberyoz...@gmail.com> Authored: Wed Aug 30 16:10:48 2017 +0100 Committer: Sergey Beryozkin <sberyoz...@gmail.com> Committed: Wed Aug 30 16:10:48 2017 +0100 ---------------------------------------------------------------------- .../cxf/jaxrs/swagger/Swagger2Feature.java | 25 ++++++++++++++++---- .../cxf/jaxrs/swagger/SwaggerUiResolver.java | 16 ++++++------- 2 files changed, 28 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/eec5aaf5/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java ---------------------------------------------------------------------- diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java index eab36a6..33ee47c 100644 --- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java +++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/Swagger2Feature.java @@ -96,6 +96,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature { private static final String FILTER_CLASS_PROPERTY = "filter.class"; private static final String HOST_PROPERTY = "host"; private static final String USE_PATH_CFG_PROPERTY = "use.path.based.config"; + private static final String SUPPORT_UI_PROPERTY = "support.swagger.ui"; private boolean runAsFilter; @@ -103,7 +104,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature { private String ignoreRoutes; - private boolean supportSwaggerUi = true; + private Boolean supportSwaggerUi; private String swaggerUiVersion; @@ -162,7 +163,8 @@ public class Swagger2Feature extends AbstractSwaggerFeature { customizer)); } - if (supportSwaggerUi) { + Properties swaggerProps = getSwaggerProperties(bus); + if (checkSupportSwaggerUiProp(swaggerProps)) { String swaggerUiRoot = SwaggerUiResolver.findSwaggerUiRoot(swaggerUiMavenGroupAndArtifact, swaggerUiVersion); if (swaggerUiRoot != null) { @@ -194,7 +196,7 @@ public class Swagger2Feature extends AbstractSwaggerFeature { BeanConfig beanConfig = appInfo == null ? new BeanConfig() : new ApplicationBeanConfig(appInfo.getProvider()); - initBeanConfig(bus, beanConfig); + initBeanConfig(beanConfig, swaggerProps); Swagger swagger = beanConfig.getSwagger(); if (swagger != null && securityDefinitions != null) { @@ -211,7 +213,18 @@ public class Swagger2Feature extends AbstractSwaggerFeature { factory.setUserProviders(providers); } - protected void initBeanConfig(Bus bus, BeanConfig beanConfig) { + protected boolean checkSupportSwaggerUiProp(Properties props) { + Boolean theSupportSwaggerUI = this.supportSwaggerUi; + if (theSupportSwaggerUI == null && props != null && props.containsKey(SUPPORT_UI_PROPERTY)) { + theSupportSwaggerUI = PropertyUtils.isTrue(props.get(SUPPORT_UI_PROPERTY)); + } + if (theSupportSwaggerUI == null) { + theSupportSwaggerUI = true; + } + return theSupportSwaggerUI; + } + + protected Properties getSwaggerProperties(Bus bus) { InputStream is = ResourceUtils.getClasspathResourceStream(propertiesLocation, AbstractSwaggerFeature.class, bus); @@ -224,6 +237,10 @@ public class Swagger2Feature extends AbstractSwaggerFeature { props = null; } } + return props; + } + protected void initBeanConfig(BeanConfig beanConfig, Properties props) { + // resource package String theResourcePackage = getResourcePackage(); if (theResourcePackage == null && props != null) { http://git-wip-us.apache.org/repos/asf/cxf/blob/eec5aaf5/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java ---------------------------------------------------------------------- diff --git a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java index 63043b18..f3a30ba 100644 --- a/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java +++ b/rt/rs/description-swagger/src/main/java/org/apache/cxf/jaxrs/swagger/SwaggerUiResolver.java @@ -52,17 +52,15 @@ public class SwaggerUiResolver { return root; } } - } else { - Enumeration<URL> urls = cl.getResources(UI_RESOURCES_ROOT_START); - while (urls.hasMoreElements()) { - String urlStr = urls.nextElement().toString().replace(UI_RESOURCES_ROOT_START, ""); - String root = checkUiRoot(urlStr, swaggerUiMavenGroupAndArtifact, swaggerUiVersion); - if (root != null) { - return root; - } + } + Enumeration<URL> urls = cl.getResources(UI_RESOURCES_ROOT_START); + while (urls.hasMoreElements()) { + String urlStr = urls.nextElement().toString().replace(UI_RESOURCES_ROOT_START, ""); + String root = checkUiRoot(urlStr, swaggerUiMavenGroupAndArtifact, swaggerUiVersion); + if (root != null) { + return root; } } - } catch (Throwable ex) { // ignore }