com.github.kongchen.swagger.docgen.mavenplugin.ApiSource Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-maven-plugin Show documentation
Show all versions of swagger-maven-plugin Show documentation
A maven build plugin which helps you generate API document during build phase
package com.github.kongchen.swagger.docgen.mavenplugin;
import com.github.kongchen.swagger.docgen.GenerateException;
import com.wordnik.swagger.annotations.Api;
import org.reflections.Reflections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
/**
* Created with IntelliJ IDEA.
* User: kongchen
* Date: 3/7/13
*/
public class ApiSource {
/**
* @parameter
*/
private String locations;
/**
* @parameter
*/
private String apiVersion;
/**
* @parameter
*/
private String basePath;
/**
* @parameter
*/
private String outputTemplate;
/**
* @parameter
*/
private String outputPath;
/**
* @parameter
*/
private String swaggerDirectory;
public String mustacheFileRoot;
/**
* @parameter
*/
public boolean useOutputFlatStructure = true;
/**
* @parameter
*/
private String swaggerUIDocBasePath;
public Set getValidClasses() throws GenerateException {
Set classes = new HashSet();
if (getLocations() == null) {
Set> c = new Reflections("").getTypesAnnotatedWith(Api.class);
classes.addAll(c);
} else {
if (locations.contains(";")) {
String[] sources = locations.split(";");
for (String source : sources) {
Set> c = new Reflections(source).getTypesAnnotatedWith(Api.class);
classes.addAll(c);
}
} else {
classes.addAll(new Reflections(locations).getTypesAnnotatedWith(Api.class));
}
}
Iterator it = classes.iterator();
while (it.hasNext()) {
if (it.next().getName().startsWith("com.wordnik.swagger")) {
it.remove();
}
}
return classes;
}
public String getLocations() {
return locations;
}
public void setLocations(String locations) {
this.locations = locations;
}
public String getOutputTemplate() {
return outputTemplate;
}
public void setOutputTemplate(String outputTemplate) {
this.outputTemplate = outputTemplate;
}
public String getMustacheFileRoot() {
return mustacheFileRoot;
}
public void setMustacheFileRoot(String mustacheFileRoot) {
this.mustacheFileRoot = mustacheFileRoot;
}
public boolean isUseOutputFlatStructure() {
return useOutputFlatStructure;
}
public void setUseOutputFlatStructure(boolean useOutputFlatStructure) {
this.useOutputFlatStructure = useOutputFlatStructure;
}
public String getOutputPath() {
return outputPath;
}
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}
public String getApiVersion() {
return apiVersion;
}
public void setApiVersion(String apiVersion) {
this.apiVersion = apiVersion;
}
public String getBasePath() {
return basePath;
}
public void setBasePath(String basePath) {
this.basePath = basePath;
}
public String getSwaggerDirectory() {
return swaggerDirectory;
}
public void setSwaggerDirectory(String swaggerDirectory) {
this.swaggerDirectory = swaggerDirectory;
}
public void setSwaggerUIDocBasePath(String swaggerUIDocBasePath) {
this.swaggerUIDocBasePath = swaggerUIDocBasePath;
}
public String getSwaggerUIDocBasePath() {
return swaggerUIDocBasePath;
}
}