Skip to content

Commit

Permalink
Merge pull request #1239 from swagger-api/beanconfig-swagger-definiti…
Browse files Browse the repository at this point in the history
…on-scanning

fixed initialization order
  • Loading branch information
Ole Lensmar committed Jul 6, 2015
2 parents 69409bb + 3ceace0 commit b0a9530
Showing 1 changed file with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,16 @@ public boolean getScan() {
public void setScan(boolean shouldScan) {
Set<Class<?>> classes = classes();
if (classes != null) {
reader.read(classes)
.host(host)
.basePath(basePath)
.info(info);
Swagger swagger = reader.read(classes);
if( StringUtils.isNotBlank( host )){
swagger.setHost(host);
}

if( StringUtils.isNotBlank( basePath )){
swagger.setBasePath(basePath);
}

updateInfoFromConfig();
}
ScannerFactory.setScanner(this);
}
Expand All @@ -197,6 +203,27 @@ public Set<Class<?>> classes() {

config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());

final Reflections reflections = new Reflections(config);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Api.class);
classes.addAll(reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class));
classes.addAll(reflections.getTypesAnnotatedWith(SwaggerDefinition.class ));

Set<Class<?>> output = new HashSet<Class<?>>();
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();
Expand Down Expand Up @@ -234,24 +261,6 @@ public Set<Class<?>> classes() {
}

reader.getSwagger().setInfo(info);
final Reflections reflections = new Reflections(config);
Set<Class<?>> classes = reflections.getTypesAnnotatedWith(Api.class);
classes.addAll(reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class));
classes.addAll(reflections.getTypesAnnotatedWith(SwaggerDefinition.class ));

Set<Class<?>> output = new HashSet<Class<?>>();
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() {
Expand Down

0 comments on commit b0a9530

Please sign in to comment.