Search in sources :

Example 1 with ApiService

use of com.emc.apidocs.model.ApiService 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 ApiService

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

the class PrimitiveDoclet method start.

public static boolean start(RootDoc root) {
    KnownPaths.init(contentDirectory, outputDirectory);
    final List<ApiService> services = ApiDoclet.findApiServices(root.classes());
    final Path readMe = new File(outputDirectory + README).toPath();
    final Iterable<JavaFile> files = ApiPrimitiveMaker.makePrimitives(services);
    ImmutableList.Builder<String> lines = ImmutableList.<String>builder();
    lines.add(ReadMePreamble);
    for (final JavaFile file : files) {
        try {
            lines.add("<value>" + file.packageName + "." + file.typeSpec.name + "</value>");
            file.writeTo(new File(outputDirectory + SOURCE_DIR));
        } catch (IOException e) {
            throw new RuntimeException("Failed to write to output folder", e);
        }
    }
    try {
        Files.createDirectories(readMe.getParent());
        Files.write(readMe, lines.build(), Charset.forName("UTF-8"));
    } catch (IOException e) {
        throw new RuntimeException("Failed to write README", e);
    }
    return true;
}
Also used : Path(java.nio.file.Path) ApiService(com.emc.apidocs.model.ApiService) ImmutableList(com.google.common.collect.ImmutableList) JavaFile(com.squareup.javapoet.JavaFile) IOException(java.io.IOException) File(java.io.File) JavaFile(com.squareup.javapoet.JavaFile)

Example 3 with ApiService

use of com.emc.apidocs.model.ApiService 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 4 with ApiService

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

the class ApiDoclet method calculateDifferences.

private static synchronized ApiDifferences calculateDifferences(List<ApiService> apiServices) {
    Properties prop = new Properties();
    try {
        FileInputStream fileInput = new FileInputStream(rootDirectory + "gradle.properties");
        prop.load(fileInput);
    } catch (IOException e) {
        throw new RuntimeException("Unable to load Gradle properties file", e);
    }
    String docsMetaVersion = prop.getProperty("apidocsComparisionVersion");
    List<ApiService> oldServices = MetaData.load(KnownPaths.getMetaDataFile("MetaData-" + docsMetaVersion + ".json"));
    DifferenceEngine differenceEngine = new DifferenceEngine();
    return differenceEngine.calculateDifferences(oldServices, apiServices);
}
Also used : ApiService(com.emc.apidocs.model.ApiService) DifferenceEngine(com.emc.apidocs.differencing.DifferenceEngine) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 5 with ApiService

use of com.emc.apidocs.model.ApiService 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)

Aggregations

ApiService (com.emc.apidocs.model.ApiService)14 ApiMethod (com.emc.apidocs.model.ApiMethod)8 File (java.io.File)3 List (java.util.List)3 ApiReferenceTocOrganizer (com.emc.apidocs.generating.ApiReferenceTocOrganizer)2 ApiDifferences (com.emc.apidocs.model.ApiDifferences)2 ImmutableList (com.google.common.collect.ImmutableList)2 JavaFile (com.squareup.javapoet.JavaFile)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 DifferenceEngine (com.emc.apidocs.differencing.DifferenceEngine)1 EnunciateFileReader (com.emc.apidocs.differencing.EnunciateFileReader)1 ApiClass (com.emc.apidocs.model.ApiClass)1 ApiErrorCode (com.emc.apidocs.model.ApiErrorCode)1 ApiServiceChanges (com.emc.apidocs.model.ApiServiceChanges)1 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 Map (java.util.Map)1