From: Robert Varga Date: Wed, 23 Jun 2021 13:44:30 +0000 (+0200) Subject: Remove sal-rest-docgen-maven X-Git-Tag: v2.0.0~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=2bc2f62fe76a0d0ad001581d1fb66022a047b908;p=netconf.git Remove sal-rest-docgen-maven Static generator for swagger documentation is not used anywhere and it is an utter mess. Remove it. JIRA: MDSAL-232 Change-Id: I8a131f22f7f5d01aa0d66116413ded822fda1341 Signed-off-by: Robert Varga --- diff --git a/artifacts/pom.xml b/artifacts/pom.xml index 3a1adc3df6..3971558942 100644 --- a/artifacts/pom.xml +++ b/artifacts/pom.xml @@ -518,11 +518,6 @@ sal-rest-docgen ${project.version} - - ${project.groupId} - sal-rest-docgen-maven - ${project.version} - ${project.groupId} sal-restconf-broker diff --git a/restconf/pom.xml b/restconf/pom.xml index d35762429a..ef55c0ec92 100644 --- a/restconf/pom.xml +++ b/restconf/pom.xml @@ -35,7 +35,6 @@ restconf-nb-rfc8040 sal-rest-connector-config sal-rest-docgen - sal-rest-docgen-maven wadl-generator websocket-client - - - 4.0.0 - - org.opendaylight.netconf - netconf-parent - 2.0.0-SNAPSHOT - ../../parent - - - sal-rest-docgen-maven - jar - - - - - org.apache.maven - maven-core - 3.2.5 - provided - - - - - - - com.fasterxml.jackson.core - jackson-databind - - - org.apache.maven - maven-core - - - org.opendaylight.yangtools - yang-maven-plugin-spi - - - ${project.groupId} - sal-rest-docgen - - - diff --git a/restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java b/restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java deleted file mode 100644 index beb3db6b84..0000000000 --- a/restconf/sal-rest-docgen-maven/src/main/java/org/opendaylight/netconf/sal/rest/doc/maven/StaticDocGenerator.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.netconf.sal.rest.doc.maven; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import javax.ws.rs.core.UriInfo; -import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl; -import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocServiceImpl.URIType; -import org.opendaylight.netconf.sal.rest.doc.impl.BaseYangSwaggerGeneratorDraft02; -import org.opendaylight.netconf.sal.rest.doc.swagger.Resource; -import org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList; -import org.opendaylight.netconf.sal.rest.doc.swagger.SwaggerObject; -import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang2sources.spi.BasicCodeGenerator; -import org.opendaylight.yangtools.yang2sources.spi.ModuleResourceResolver; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class gathers all yang defined {@link Module}s and generates Swagger compliant documentation. - */ -public class StaticDocGenerator extends BaseYangSwaggerGeneratorDraft02 - implements BasicCodeGenerator { - private static final Logger LOG = LoggerFactory.getLogger(StaticDocGenerator.class); - - private static final String DEFAULT_OUTPUT_BASE_DIR_PATH = "target" + File.separator + "generated-resources" - + File.separator + "swagger-api-documentation"; - - public StaticDocGenerator() { - super(Optional.empty()); - } - - @Override - @SuppressFBWarnings("DM_DEFAULT_ENCODING") - public Collection generateSources(final EffectiveModelContext context, final File outputBaseDir, - final Set currentModules, final ModuleResourceResolver moduleResourcePathResolver) - throws IOException { - final List result = new ArrayList<>(); - - // Create Base Directory - final File outputDir; - if (outputBaseDir == null) { - outputDir = new File(DEFAULT_OUTPUT_BASE_DIR_PATH); - } else { - outputDir = outputBaseDir; - } - - if (!outputDir.mkdirs()) { - throw new IOException("Could not create directory " + outputDir); - } - - // Create Resources directory - final File resourcesDir = new File(outputDir, "resources"); - if (!resourcesDir.mkdirs()) { - throw new IOException("Could not create directory " + resourcesDir); - } - - // Create JS file - final File resourcesJsFile = new File(outputDir, "resources.js"); - if (!resourcesJsFile.createNewFile()) { - LOG.info("File {} already exists.", resourcesJsFile); - } - - try (BufferedWriter bufferedWriter = - new BufferedWriter(new FileWriter(resourcesJsFile, StandardCharsets.UTF_8))) { - final ObjectMapper mapper = new ObjectMapper(); - mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false); - - // Write resource listing to JS file - final ResourceList resourceList = super.getResourceListing(null, context, "", URIType.DRAFT02, - ApiDocServiceImpl.OAversion.V2_0); - String resourceListJson = mapper.writeValueAsString(resourceList); - resourceListJson = resourceListJson.replace("\'", "\\\'").replace("\\n", "\\\\n"); - bufferedWriter.write("function getSpec() {\n\treturn \'" + resourceListJson + "\';\n}\n\n"); - - // Write resources/APIs to JS file and to disk - bufferedWriter.write("function jsonFor(resource) {\n\tswitch(resource) {\n"); - for (final Resource resource : resourceList.getApis()) { - final int revisionIndex = resource.getPath().indexOf('('); - final String name = resource.getPath().substring(0, revisionIndex); - final String revision = - resource.getPath().substring(revisionIndex + 1, resource.getPath().length() - 1); - final SwaggerObject swaggerObject = super.getApiDeclaration(name, revision, null, context, "", - URIType.DRAFT02, ApiDocServiceImpl.OAversion.V2_0); - String json = mapper.writeValueAsString(swaggerObject); - // Manually insert models because org.json.JSONObject cannot be serialized by ObjectMapper - json = json.replace( - "\"models\":{}", "\"models\":" - + swaggerObject.getDefinitions().toString().replace("\\\"", "\"")); - // Escape single quotes and new lines - json = json.replace("\'", "\\\'").replace("\\n", "\\\\n"); - bufferedWriter.write("\t\tcase \"" + name + "(" + revision + ")\": return \'" + json + "\';\n"); - - final File resourceFile = new File(resourcesDir, name + "(" + revision + ").json"); - - try (BufferedWriter resourceFileWriter = - new BufferedWriter(new FileWriter(resourceFile, StandardCharsets.UTF_8))) { - resourceFileWriter.write(json); - } - - result.add(resourceFile); - } - bufferedWriter.write("\t}\n\treturn \"\";\n}"); - } - - result.add(resourcesJsFile); - return result; - } - - @Override - public String generatePath(final UriInfo uriInfo, final String name, final String revision) { - if (uriInfo == null) { - return name + "(" + revision + ")"; - } - return super.generatePath(uriInfo, name, revision); - } - - @Override - public void setAdditionalConfig(final Map additionalConfig) { - // No-op, although it should not be - } - - @Override - public void setResourceBaseDir(final File resourceBaseDir) { - // No-op, although it should not be - } -}