this.apiSource = apiSource;
}
@Override
public void loadDocuments() throws GenerateException {
SwaggerConfig swaggerConfig = new SwaggerConfig();
swaggerConfig.setApiVersion(apiSource.getApiVersion());
swaggerConfig.setSwaggerVersion(SwaggerSpec.version());
List<ApiListingReference> apiListingReferences = new ArrayList<ApiListingReference>();
if (apiSource.getSwaggerInternalFilter() != null) {
FilterFactory$ filterFactory = FilterFactory$.MODULE$;
try {
LOG.info("Setting filter configuration: " + apiSource.getSwaggerInternalFilter());
filterFactory.filter_$eq((SwaggerSpecFilter) Class.forName(apiSource.getSwaggerInternalFilter()).newInstance());
} catch (Exception e) {
throw new GenerateException("Cannot load: " + apiSource.getSwaggerInternalFilter(), e);
}
}
List<AuthorizationType> authorizationTypes = new ArrayList<AuthorizationType>();
for (Class c : apiSource.getValidClasses()) {
ApiListing doc;
try {
doc = getDocFromClass(c, swaggerConfig, getBasePath());
} catch (Exception e) {
throw new GenerateException(e);
}
if (doc == null) continue;
LOG.info("Detect Resource:" + c.getName());
Buffer<AuthorizationType> buffer = doc.authorizations().toBuffer();
authorizationTypes.addAll(JavaConversions.asJavaList(buffer));
ApiListingReference apiListingReference = new ApiListingReference(doc.resourcePath(), doc.description(), doc.position());
apiListingReferences.add(apiListingReference);
acceptDocument(doc);
}
// sort apiListingRefernce by position
Collections.sort(apiListingReferences, new Comparator<ApiListingReference>() {
@Override
public int compare(ApiListingReference o1, ApiListingReference o2) {
if (o1 == null && o2 == null) return 0;
if (o1 == null && o2 != null) return -1;
if (o1 != null && o2 == null) return 1;
return o1.position() - o2.position();
}
});
serviceDocument = new ResourceListing(swaggerConfig.apiVersion(), swaggerConfig.swaggerVersion(),
scala.collection.immutable.List.fromIterator(JavaConversions.asScalaIterator(apiListingReferences.iterator())),
scala.collection.immutable.List.fromIterator(JavaConversions.asScalaIterator(authorizationTypes.iterator())),
toSwaggerApiInfo(apiSource.getApiInfo()));
}