Search in sources :

Example 1 with ResourceApi

use of com.webcohesion.enunciate.api.resources.ResourceApi in project enunciate by stoicflame.

the class AggregatedApiRegistry method getResourceApis.

@Override
public List<ResourceApi> getResourceApis(ApiRegistrationContext context) {
    ArrayList<ResourceApi> resourceApis = new ArrayList<ResourceApi>();
    List<EnunciateModule> modules = enunciate.getModules();
    for (EnunciateModule module : modules) {
        if (module.isEnabled() && module instanceof ApiRegistryProviderModule) {
            resourceApis.addAll(((ApiRegistryProviderModule) module).getApiRegistry().getResourceApis(context));
        }
    }
    return resourceApis;
}
Also used : ApiRegistryProviderModule(com.webcohesion.enunciate.module.ApiRegistryProviderModule) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) EnunciateModule(com.webcohesion.enunciate.module.EnunciateModule) ArrayList(java.util.ArrayList)

Example 2 with ResourceApi

use of com.webcohesion.enunciate.api.resources.ResourceApi 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;
}
Also used : JavaDocLink(com.webcohesion.enunciate.javac.javadoc.JavaDocLink) DecoratedElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedElement) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) Service(com.webcohesion.enunciate.api.services.Service) Method(com.webcohesion.enunciate.api.resources.Method) Operation(com.webcohesion.enunciate.api.services.Operation) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) DecoratedTypeElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedTypeElement) Value(com.webcohesion.enunciate.api.datatype.Value) DataType(com.webcohesion.enunciate.api.datatype.DataType) PackageElement(javax.lang.model.element.PackageElement) DecoratedPackageElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedPackageElement) Syntax(com.webcohesion.enunciate.api.datatype.Syntax) DecoratedPackageElement(com.webcohesion.enunciate.javac.decorations.element.DecoratedPackageElement) Property(com.webcohesion.enunciate.api.datatype.Property) ResourceGroup(com.webcohesion.enunciate.api.resources.ResourceGroup)

Example 3 with ResourceApi

use of com.webcohesion.enunciate.api.resources.ResourceApi 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);
    }
}
Also used : ServiceGroup(com.webcohesion.enunciate.api.services.ServiceGroup) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) EnunciateException(com.webcohesion.enunciate.EnunciateException) FileDirective(com.webcohesion.enunciate.util.freemarker.FileDirective) TemplateException(freemarker.template.TemplateException) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) ClientLibraryJavaArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact) Artifact(com.webcohesion.enunciate.artifacts.Artifact) ClientLibraryArtifact(com.webcohesion.enunciate.artifacts.ClientLibraryArtifact) Namespace(com.webcohesion.enunciate.api.datatype.Namespace) ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) FileArtifact(com.webcohesion.enunciate.artifacts.FileArtifact) Syntax(com.webcohesion.enunciate.api.datatype.Syntax)

Example 4 with ResourceApi

use of com.webcohesion.enunciate.api.resources.ResourceApi 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);
        }
    };
}
Also used : ResourceApi(com.webcohesion.enunciate.api.resources.ResourceApi) FacetFilter(com.webcohesion.enunciate.facets.FacetFilter) ServiceApi(com.webcohesion.enunciate.api.services.ServiceApi) ApiRegistrationContext(com.webcohesion.enunciate.api.ApiRegistrationContext) Syntax(com.webcohesion.enunciate.api.datatype.Syntax) ApiRegistry(com.webcohesion.enunciate.api.ApiRegistry)

Aggregations

ResourceApi (com.webcohesion.enunciate.api.resources.ResourceApi)4 Syntax (com.webcohesion.enunciate.api.datatype.Syntax)3 ServiceApi (com.webcohesion.enunciate.api.services.ServiceApi)3 FacetFilter (com.webcohesion.enunciate.facets.FacetFilter)2 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 ApiRegistrationContext (com.webcohesion.enunciate.api.ApiRegistrationContext)1 ApiRegistry (com.webcohesion.enunciate.api.ApiRegistry)1 DataType (com.webcohesion.enunciate.api.datatype.DataType)1 Namespace (com.webcohesion.enunciate.api.datatype.Namespace)1 Property (com.webcohesion.enunciate.api.datatype.Property)1 Value (com.webcohesion.enunciate.api.datatype.Value)1 Method (com.webcohesion.enunciate.api.resources.Method)1 ResourceGroup (com.webcohesion.enunciate.api.resources.ResourceGroup)1 Operation (com.webcohesion.enunciate.api.services.Operation)1 Service (com.webcohesion.enunciate.api.services.Service)1 ServiceGroup (com.webcohesion.enunciate.api.services.ServiceGroup)1 Artifact (com.webcohesion.enunciate.artifacts.Artifact)1 ClientLibraryArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryArtifact)1 ClientLibraryJavaArtifact (com.webcohesion.enunciate.artifacts.ClientLibraryJavaArtifact)1 FileArtifact (com.webcohesion.enunciate.artifacts.FileArtifact)1