Merge "Fix bug 5810, 5812: 1. only when node's config statement is true, such apis...
authorTomas Cere <tcere@cisco.com>
Mon, 13 Jun 2016 13:22:19 +0000 (13:22 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 13 Jun 2016 13:22:19 +0000 (13:22 +0000)
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/BaseYangSwaggerGenerator.java

index 75a1644e42990be3d123a35354eae180f5be450f..9eb5b9c61d918e1f48b2471b903ed299877f4f1b 100644 (file)
@@ -172,18 +172,36 @@ public class BaseYangSwaggerGenerator {
         ApiDeclaration doc = createApiDeclaration(basePath);
 
         List<Api> apis = new ArrayList<>();
+        boolean hasAddRootPostLink = false;
 
         Collection<DataSchemaNode> dataSchemaNodes = m.getChildNodes();
         LOG.debug("child nodes size [{}]", dataSchemaNodes.size());
         for (DataSchemaNode node : dataSchemaNodes) {
             if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
-
                 LOG.debug("Is Configuration node [{}] [{}]", node.isConfiguration(), node.getQName().getLocalName());
 
                 List<Parameter> pathParams = new ArrayList<>();
-                String resourcePath = getDataStorePath("/config/", context);
-                addRootPostLink(m, (DataNodeContainer) node, pathParams, resourcePath, apis);
-                addApis(node, apis, resourcePath, pathParams, schemaContext, true);
+                String resourcePath;
+
+                /*
+                 * Only when the node's config statement is true, such apis as GET/PUT/POST/DELETE config
+                 * are added for this node.
+                 */
+                if (node.isConfiguration()) { // This node's config statement is true.
+                    resourcePath = getDataStorePath("/config/", context);
+
+                    /*
+                     * When there are two or more top container or list nodes whose config statement is true in module,
+                     * make sure that only one root post link is added for this module.
+                     */
+                    if (!hasAddRootPostLink) {
+                        LOG.debug("Has added root post link for module {}", m.getName());
+                        addRootPostLink(m, (DataNodeContainer) node, pathParams, resourcePath, apis);
+                        hasAddRootPostLink = true;
+                    }
+
+                    addApis(node, apis, resourcePath, pathParams, schemaContext, true);
+                }
 
                 pathParams = new ArrayList<>();
                 resourcePath = getDataStorePath("/operational/", context);