use of com.webcohesion.enunciate.api.services.ServiceApi in project enunciate by stoicflame.
the class AggregatedApiRegistry method getServiceApis.
@Override
public List<ServiceApi> getServiceApis(ApiRegistrationContext context) {
ArrayList<ServiceApi> serviceApis = new ArrayList<ServiceApi>();
List<EnunciateModule> modules = enunciate.getModules();
for (EnunciateModule module : modules) {
if (module.isEnabled() && module instanceof ApiRegistryProviderModule) {
serviceApis.addAll(((ApiRegistryProviderModule) module).getApiRegistry().getServiceApis(context));
}
}
return serviceApis;
}
use of com.webcohesion.enunciate.api.services.ServiceApi in project enunciate by stoicflame.
the class ApiDocsJavaDocTagHandler method onInlineTag.
@Override
public String onInlineTag(String tagName, String tagText, DecoratedElement context) {
if ("link".equals(tagName)) {
JavaDocLink link = JavaDocLink.parse(tagText);
String classRef = link.getClassName();
String subelementRef = link.getMemberName();
String value = link.getLabel();
// use the current context as the class ref.
if ("".equals(classRef)) {
DecoratedElement type = context;
while (!(type instanceof DecoratedTypeElement)) {
type = (DecoratedElement) type.getEnclosingElement();
if (type == null || type instanceof PackageElement) {
break;
}
}
if (type instanceof DecoratedTypeElement) {
classRef = ((DecoratedTypeElement) type).getQualifiedName().toString();
}
}
if (!"".equals(classRef)) {
if (classRef.indexOf('.') < 0) {
// if it's a local reference, assume it's in the current package.
DecoratedElement pckg = context;
while (!(pckg instanceof DecoratedPackageElement)) {
pckg = (DecoratedElement) pckg.getEnclosingElement();
if (pckg == null) {
break;
}
}
if (pckg != null) {
classRef = ((DecoratedPackageElement) pckg).getQualifiedName() + "." + classRef;
}
}
// now find the reference
Set<Syntax> syntaxes = this.registry.getSyntaxes(this.context);
for (Syntax syntax : syntaxes) {
List<DataType> dataTypes = syntax.findDataTypes(classRef);
if (dataTypes != null && !dataTypes.isEmpty()) {
DataType dataType = dataTypes.get(0);
Value dataTypeValue = dataType.findValue(subelementRef);
if (dataTypeValue != null) {
return "<a href=\"" + dataType.getSlug() + ".html#" + dataTypeValue.getValue() + "\">" + (value != null ? value : dataTypeValue.getValue()) + "</a>";
}
Property property = dataType.findProperty(subelementRef);
if (property != null) {
return "<a href=\"" + dataType.getSlug() + ".html#prop-" + property.getName() + "\">" + (value != null ? value : property.getName()) + "</a>";
}
return "<a href=\"" + dataType.getSlug() + ".html\">" + (value != null ? value : (subelementRef.isEmpty() ? dataType.getLabel() : subelementRef)) + "</a>";
}
}
List<ResourceApi> resourceApis = this.registry.getResourceApis(this.context);
for (ResourceApi resourceApi : resourceApis) {
Method method = resourceApi.findMethodFor(classRef, subelementRef);
if (method != null) {
if (value == null) {
value = method.getLabel() + " " + method.getResource().getGroup().getLabel();
}
return "<a href=\"" + method.getResource().getGroup().getSlug() + ".html#" + method.getSlug() + "\">" + value + "</a>";
} else {
ResourceGroup resourceGroup = resourceApi.findResourceGroupFor(classRef);
if (resourceGroup != null) {
if (value == null) {
value = resourceGroup.getLabel();
}
return "<a href=\"" + resourceGroup.getSlug() + ".html\">" + value + "</a>";
}
}
}
List<ServiceApi> serviceApis = this.registry.getServiceApis(this.context);
for (ServiceApi serviceApi : serviceApis) {
Operation operation = serviceApi.findOperationFor(classRef, subelementRef);
if (operation != null) {
if (value == null) {
value = operation.getName();
}
return "<a href=\"" + operation.getService().getSlug() + ".html#" + operation.getSlug() + "\">" + value + "</a>";
} else {
Service service = serviceApi.findServiceFor(classRef);
if (service != null) {
if (value == null) {
value = service.getLabel();
}
return "<a href=\"" + service.getSlug() + ".html\">" + value + "</a>";
}
}
}
}
return value != null ? value : tagText.trim();
} else if ("code".equals(tagName)) {
return "<code>" + tagText + "</code>";
}
return tagText;
}
use of com.webcohesion.enunciate.api.services.ServiceApi in project enunciate by stoicflame.
the class DocsModule method call.
@Override
public void call(EnunciateContext context) {
try {
File docsDir = getDocsDir();
String subDir = getDocsSubdir();
if (subDir != null) {
docsDir = new File(docsDir, subDir);
}
if (!isUpToDateWithSources(docsDir)) {
Set<String> facetIncludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(this.enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
ApiRegistrationContext registrationContext = new DocsRegistrationContext(this.apiRegistry, facetFilter);
List<ResourceApi> resourceApis = this.apiRegistry.getResourceApis(registrationContext);
Set<Syntax> syntaxes = this.apiRegistry.getSyntaxes(registrationContext);
List<ServiceApi> serviceApis = this.apiRegistry.getServiceApis(registrationContext);
Set<Artifact> documentationArtifacts = findDocumentationArtifacts();
if (syntaxes.isEmpty() && serviceApis.isEmpty() && resourceApis.isEmpty() && documentationArtifacts.isEmpty()) {
warn("No documentation generated: there are no data types, services, or resources to document.");
return;
}
// make sure the docs dir exists.
docsDir.mkdirs();
Map<String, Object> model = new HashMap<String, Object>();
String intro = this.enunciate.getConfiguration().readDescription(context, false, registrationContext.getTagHandler());
if (intro != null) {
model.put("apiDoc", intro);
}
String copyright = this.enunciate.getConfiguration().getCopyright();
if (copyright != null) {
model.put("copyright", copyright);
}
String title = this.enunciate.getConfiguration().getTitle();
model.put("title", title == null ? "Web Service API" : title);
// extract out the documentation base
String cssPath = buildBase(docsDir);
if (cssPath != null) {
model.put("cssFile", cssPath);
}
model.put("file", new FileDirective(docsDir, this.enunciate.getLogger()));
model.put("apiRelativePath", getRelativePathToRootDir());
model.put("includeApplicationPath", isIncludeApplicationPath());
model.put("includeDataTypesHomeIndex", isIncludeDataTypesHomeIndex());
model.put("favicon", getFavicon());
// iterate through schemas and make sure the schema is copied to the docs dir
for (Syntax syntax : syntaxes) {
for (Namespace namespace : syntax.getNamespaces()) {
if (namespace.getSchemaFile() != null) {
namespace.getSchemaFile().writeTo(docsDir);
}
}
}
model.put("data", syntaxes);
for (ResourceApi resourceApi : resourceApis) {
if (resourceApi.getWadlFile() != null) {
resourceApi.getWadlFile().writeTo(docsDir);
}
}
model.put("resourceApis", resourceApis);
InterfaceDescriptionFile swaggerUI = this.apiRegistry.getSwaggerUI();
if (swaggerUI != null) {
swaggerUI.writeTo(docsDir);
model.put("swaggerUI", swaggerUI);
}
// iterate through wsdls and make sure the wsdl is copied to the docs dir
for (ServiceApi serviceApi : serviceApis) {
for (ServiceGroup serviceGroup : serviceApi.getServiceGroups()) {
if (serviceGroup.getWsdlFile() != null) {
serviceGroup.getWsdlFile().writeTo(docsDir);
}
}
}
model.put("serviceApis", serviceApis);
model.put("downloads", copyDocumentationArtifacts(documentationArtifacts, docsDir));
model.put("indexPageName", getIndexPageName());
model.put("disableMountpoint", isDisableRestMountpoint());
model.put("additionalCssFiles", getAdditionalCss());
model.put("disableResourceLinks", isDisableResourceLinks());
processTemplate(getDocsTemplateURL(), model);
} else {
info("Skipping documentation source generation as everything appears up-to-date...");
}
this.enunciate.addArtifact(new FileArtifact(getName(), "docs", docsDir));
} catch (IOException e) {
throw new EnunciateException(e);
} catch (TemplateException e) {
throw new EnunciateException(e);
}
}
use of com.webcohesion.enunciate.api.services.ServiceApi in project enunciate by stoicflame.
the class SwaggerModule method getApiRegistry.
@Override
public ApiRegistry getApiRegistry() {
return new ApiRegistry() {
@Override
public List<ServiceApi> getServiceApis(ApiRegistrationContext context) {
return Collections.emptyList();
}
@Override
public List<ResourceApi> getResourceApis(ApiRegistrationContext context) {
return Collections.emptyList();
}
@Override
public Set<Syntax> getSyntaxes(ApiRegistrationContext context) {
return Collections.emptySet();
}
@Override
public InterfaceDescriptionFile getSwaggerUI() {
Set<String> facetIncludes = new TreeSet<String>(enunciate.getConfiguration().getFacetIncludes());
facetIncludes.addAll(getFacetIncludes());
Set<String> facetExcludes = new TreeSet<String>(enunciate.getConfiguration().getFacetExcludes());
facetExcludes.addAll(getFacetExcludes());
FacetFilter facetFilter = new FacetFilter(facetIncludes, facetExcludes);
ApiRegistrationContext context = new SwaggerRegistrationContext(facetFilter);
List<ResourceApi> resourceApis = apiRegistry.getResourceApis(context);
if (resourceApis == null || resourceApis.isEmpty()) {
info("No resource APIs registered: Swagger UI will not be generated.");
}
return new SwaggerInterfaceDescription(resourceApis, context);
}
};
}
Aggregations