Search in sources :

Example 1 with RestResource

use of com.google.api.services.discovery.model.RestResource in project endpoints-java by cloudendpoints.

the class DiscoveryGenerator method getMethodMapFromDoc.

/**
 * Gets the correct map in a {@link RestDescription} to add a method to, based on its name. This
 * is slightly complicated due to the fact that methods can exist outside of resources and on the
 * {@link RestDescription} object itself.
 */
private Map<String, RestMethod> getMethodMapFromDoc(RestDescription doc, List<String> parts) {
    if (parts.size() == 2) {
        if (doc.getMethods() == null) {
            doc.setMethods(new TreeMap<String, RestMethod>());
        }
        return doc.getMethods();
    }
    RestResource resource = null;
    Map<String, RestResource> resources = doc.getResources();
    if (resources == null) {
        resources = new TreeMap<>();
        doc.setResources(resources);
    }
    for (int i = 1; i < parts.size() - 1; i++) {
        String part = parts.get(i);
        if (resources == null) {
            resources = new TreeMap<>();
            resource.setResources(resources);
        }
        resource = resources.get(part);
        if (resource == null) {
            resource = new RestResource();
            resources.put(part, resource);
        }
        resources = resource.getResources();
    }
    if (resource.getMethods() == null) {
        resource.setMethods(new TreeMap<String, RestMethod>());
    }
    return resource.getMethods();
}
Also used : RestResource(com.google.api.services.discovery.model.RestResource) RestMethod(com.google.api.services.discovery.model.RestMethod)

Aggregations

RestMethod (com.google.api.services.discovery.model.RestMethod)1 RestResource (com.google.api.services.discovery.model.RestResource)1