From 19618744e007685fe67f24e3fe7c188543419a41 Mon Sep 17 00:00:00 2001 From: Ole Lensmar Date: Mon, 6 Jul 2015 12:16:11 +0200 Subject: [PATCH 1/2] fixed initialization order --- .../src/main/java/io/swagger/jaxrs/config/BeanConfig.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java index 720a5fe50d..c712024309 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java @@ -169,10 +169,8 @@ public boolean getScan() { public void setScan(boolean shouldScan) { Set> classes = classes(); if (classes != null) { - reader.read(classes) - .host(host) - .basePath(basePath) - .info(info); + reader.getSwagger().host(host).basePath(basePath).info(info); + reader.read(classes); } ScannerFactory.setScanner(this); } From 3ceace001417d31b4783dff7791e63dff023b1d7 Mon Sep 17 00:00:00 2001 From: Ole Lensmar Date: Mon, 6 Jul 2015 14:44:18 +0200 Subject: [PATCH 2/2] fixed so config overrides code only if set --- .../io/swagger/jaxrs/config/BeanConfig.java | 51 +++++++++++-------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java index c712024309..7736188ac7 100644 --- a/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java +++ b/modules/swagger-jaxrs/src/main/java/io/swagger/jaxrs/config/BeanConfig.java @@ -169,8 +169,16 @@ public boolean getScan() { public void setScan(boolean shouldScan) { Set> classes = classes(); if (classes != null) { - reader.getSwagger().host(host).basePath(basePath).info(info); - reader.read(classes); + Swagger swagger = reader.read(classes); + if( StringUtils.isNotBlank( host )){ + swagger.setHost(host); + } + + if( StringUtils.isNotBlank( basePath )){ + swagger.setBasePath(basePath); + } + + updateInfoFromConfig(); } ScannerFactory.setScanner(this); } @@ -195,6 +203,27 @@ public Set> classes() { config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner()); + final Reflections reflections = new Reflections(config); + Set> classes = reflections.getTypesAnnotatedWith(Api.class); + classes.addAll(reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class)); + classes.addAll(reflections.getTypesAnnotatedWith(SwaggerDefinition.class )); + + Set> output = new HashSet>(); + for (Class cls : classes) { + if (allowAllPackages) { + output.add(cls); + } else { + for (String pkg : acceptablePackages) { + if (cls.getPackage().getName().startsWith(pkg)) { + output.add(cls); + } + } + } + } + return output; + } + + private void updateInfoFromConfig() { info = getSwagger().getInfo(); if( info == null ){ info = new Info(); @@ -232,24 +261,6 @@ public Set> classes() { } reader.getSwagger().setInfo(info); - final Reflections reflections = new Reflections(config); - Set> classes = reflections.getTypesAnnotatedWith(Api.class); - classes.addAll(reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class)); - classes.addAll(reflections.getTypesAnnotatedWith(SwaggerDefinition.class )); - - Set> output = new HashSet>(); - for (Class cls : classes) { - if (allowAllPackages) { - output.add(cls); - } else { - for (String pkg : acceptablePackages) { - if (cls.getPackage().getName().startsWith(pkg)) { - output.add(cls); - } - } - } - } - return output; } public Swagger getSwagger() {