Search in sources :

Example 1 with ApiMethod

use of com.emc.apidocs.model.ApiMethod in project coprhd-controller by CoprHD.

the class EncunciationReaderTests method main.

public static void main(String[] args) throws Exception {
    InputStream enunciateStream = EncunciationReaderTests.class.getResourceAsStream("apisvc-1.1.xml");
    EnunciateFileReader reader = new EnunciateFileReader();
    Map<String, ApiService> services = reader.loadServices(enunciateStream);
    for (ApiService service : services.values()) {
        System.out.println(service.getFqJavaClassName());
        for (ApiMethod method : service.methods) {
            System.out.println("== " + method.httpMethod + " " + method.path);
            if (method.input != null) {
                System.out.println("==---  IN : " + method.input.name);
            }
            if (method.output != null) {
                System.out.println("==---  OUT : " + method.output.name);
            }
        }
    }
}
Also used : ApiService(com.emc.apidocs.model.ApiService) InputStream(java.io.InputStream) ApiMethod(com.emc.apidocs.model.ApiMethod) EnunciateFileReader(com.emc.apidocs.differencing.EnunciateFileReader)

Example 2 with ApiMethod

use of com.emc.apidocs.model.ApiMethod in project coprhd-controller by CoprHD.

the class DifferenceEngineTest method main.

public static void main(String[] args) throws Exception {
    List<ApiService> oldApi = MetaData.load(EncunciationReaderTests.class.getResourceAsStream("MetaData-1.1.json"));
    List<ApiService> newApi = MetaData.load(EncunciationReaderTests.class.getResourceAsStream("MetaData-2.0.json"));
    ApiDifferences differences = DifferenceEngine.calculateDifferences(oldApi, newApi);
    ApiReferenceTocOrganizer organizer = new ApiReferenceTocOrganizer(new File("/Users/maddid/SourceCode/bourne/vipr-controller/tools/apidocs/src/content/reference/ApiReferenceGrouping.txt"));
    Map<String, List<ApiService>> newServicesToc = organizer.organizeServices(differences.newServices);
    Map<String, List<ApiService>> removedServicesToc = organizer.organizeServices(differences.removedServices);
    System.out.println("\n===== NEW SERVICES:");
    dumpServices(newServicesToc);
    System.out.println("\n===== SERVICE CHANGES");
    for (ApiServiceChanges changes : differences.modifiedServices) {
        System.out.println(changes.service.getFqJavaClassName());
        if (!changes.newMethods.isEmpty()) {
            System.out.println("---- NEW METHODS");
            for (ApiMethod apiMethod : changes.newMethods) {
                System.out.println("-- " + apiMethod.httpMethod + " " + apiMethod.path);
            }
        }
        if (!changes.removedMethods.isEmpty()) {
            System.out.println("---- REMOVED METHODS");
            for (ApiMethod apiMethod : changes.removedMethods) {
                System.out.println("-- " + apiMethod.httpMethod + " " + apiMethod.path);
            }
        }
    }
}
Also used : ApiService(com.emc.apidocs.model.ApiService) ApiDifferences(com.emc.apidocs.model.ApiDifferences) ApiMethod(com.emc.apidocs.model.ApiMethod) ApiReferenceTocOrganizer(com.emc.apidocs.generating.ApiReferenceTocOrganizer) ApiServiceChanges(com.emc.apidocs.model.ApiServiceChanges) List(java.util.List) File(java.io.File)

Example 3 with ApiMethod

use of com.emc.apidocs.model.ApiMethod in project coprhd-controller by CoprHD.

the class ApiDoclet method processClass.

/**
 * Process a JAXRS Class into an API Service
 */
public static synchronized ApiService processClass(ClassDoc classDoc, String baseUrl, boolean isDataService) {
    ApiService apiService = new ApiService();
    apiService.packageName = classDoc.containingPackage().name();
    apiService.javaClassName = classDoc.name();
    apiService.description = classDoc.commentText();
    apiService.path = baseUrl;
    addDefaultPermissions(classDoc, apiService);
    addDeprecated(classDoc, apiService);
    TemporaryCleanup.applyCleanups(apiService);
    // Process ALL methods on EMC classes, including super classes
    Set<String> methodsAdded = new HashSet<>();
    ClassDoc currentClass = classDoc;
    while (currentClass != null && currentClass.containingPackage().name().startsWith("com.emc")) {
        for (MethodDoc method : currentClass.methods()) {
            if (isApiMethod(method) && !isInternalMethod(method) && !methodBlackList.contains(apiService.getFqJavaClassName() + "::" + method.name()) && !methodBlackList.contains(apiService.javaClassName + "::" + method.name())) {
                ApiMethod apiMethod = MethodProcessor.processMethod(apiService, method, apiService.path, isDataService);
                // Some methods are marked internal via brief comments, but we only know that after processing it
                if (!apiMethod.brief.toLowerCase().startsWith("internal")) {
                    // Add method to service only if it is not overridden by subclass
                    if (methodsAdded.add(apiMethod.javaMethodName + ":" + apiMethod.httpMethod + ":" + apiMethod.path)) {
                        apiService.addMethod(apiMethod);
                    } else {
                        System.out.println("Service " + classDoc.name() + ": skip overridden method " + currentClass.name() + "::" + method.name());
                    }
                }
            }
            methodsAdded.add(method.name());
        }
        currentClass = currentClass.superclass();
    }
    return apiService;
}
Also used : ApiService(com.emc.apidocs.model.ApiService) ApiMethod(com.emc.apidocs.model.ApiMethod)

Example 4 with ApiMethod

use of com.emc.apidocs.model.ApiMethod in project coprhd-controller by CoprHD.

the class PlayRoutesParser method parse.

private static void parse(File routeFile, Map<String, ApiService> services, String moduleRoot) throws Exception {
    byte[] bytes = IOUtils.toByteArray(new FileInputStream(routeFile));
    String file = new String(bytes);
    Matcher serviceMatcher = docPattern.matcher(file);
    while (serviceMatcher.find()) {
        int groupCount = serviceMatcher.groupCount();
        String className = getClassName(serviceMatcher.group(groupCount));
        String packageName = getPackage(serviceMatcher.group(groupCount));
        ApiService apiService = null;
        if (services.containsKey(className)) {
            apiService = services.get(className);
        } else {
            apiService = new ApiService();
            apiService.packageName = packageName;
            apiService.javaClassName = className;
            apiService.description = "";
            apiService.path = moduleRoot + "/api";
            services.put(className, apiService);
        }
        if (!serviceMatcher.group(groupCount - 1).endsWith("{<json|xml>format}")) {
            ApiMethod apiMethod = new ApiMethod();
            apiMethod.javaMethodName = getMethodName(serviceMatcher.group(serviceMatcher.groupCount()));
            apiMethod.httpMethod = serviceMatcher.group(groupCount - 2);
            apiMethod.path = moduleRoot + serviceMatcher.group(groupCount - 1);
            apiMethod.description = serviceMatcher.group(1).replaceAll("## ", "");
            apiMethod.brief = serviceMatcher.group(3);
            apiMethod.apiService = apiService;
            apiMethod.alert = "<b>Note:</b> Hosted on HTTPS port 443";
            apiMethod.xmlExample = ExampleLoader.loadExample(apiMethod.getXmlExampleFilename());
            apiMethod.jsonExample = ExampleLoader.loadExample(apiMethod.getJsonExampleFilename());
            addParameterInfo(serviceMatcher.group(0), apiMethod);
            apiService.addMethod(apiMethod);
        }
    }
}
Also used : Matcher(java.util.regex.Matcher) ApiService(com.emc.apidocs.model.ApiService) ApiMethod(com.emc.apidocs.model.ApiMethod) FileInputStream(java.io.FileInputStream)

Example 5 with ApiMethod

use of com.emc.apidocs.model.ApiMethod in project coprhd-controller by CoprHD.

the class MethodProcessor method processMethod.

/**
 * Create an APIMethod from a standard Method
 */
public static ApiMethod processMethod(ApiService apiService, MethodDoc method, String baseURL, boolean isDataService) {
    try {
        ApiMethod apiMethodDesc = new ApiMethod();
        apiMethodDesc.javaMethodName = method.name();
        apiMethodDesc.apiService = apiService;
        apiMethodDesc.isDataService = isDataService;
        addPath(method, apiMethodDesc, baseURL);
        addHttpMethod(method, apiMethodDesc);
        addDescription(method, apiMethodDesc);
        addBriefDescription(method, apiMethodDesc);
        addResponseDescription(method, apiMethodDesc);
        addPrerequisites(method, apiMethodDesc);
        addSecurity(method, apiMethodDesc);
        if (isDataService) {
            addDataServiceInformation(method, apiMethodDesc);
        } else {
            addInputs(method, apiMethodDesc);
        }
        addOutput(method, apiMethodDesc);
        addQueryParameters(method, apiMethodDesc);
        addPathParameters(method, apiMethodDesc);
        addExamples(apiMethodDesc);
        addDeprecated(method, apiMethodDesc);
        return apiMethodDesc;
    } catch (Exception e) {
        throw new RuntimeException("Error processing " + apiService.getFqJavaClassName() + "::" + method.name(), e);
    }
}
Also used : ApiMethod(com.emc.apidocs.model.ApiMethod)

Aggregations

ApiMethod (com.emc.apidocs.model.ApiMethod)10 ApiService (com.emc.apidocs.model.ApiService)8 ApiReferenceTocOrganizer (com.emc.apidocs.generating.ApiReferenceTocOrganizer)2 List (java.util.List)2 EnunciateFileReader (com.emc.apidocs.differencing.EnunciateFileReader)1 ApiClass (com.emc.apidocs.model.ApiClass)1 ApiDifferences (com.emc.apidocs.model.ApiDifferences)1 ApiServiceChanges (com.emc.apidocs.model.ApiServiceChanges)1 ImmutableList (com.google.common.collect.ImmutableList)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 JavaFile (com.squareup.javapoet.JavaFile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 Matcher (java.util.regex.Matcher)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1