Fix bug 5810, 5812: 15/39815/2
authorNafee Chan <nafee.chan@gmail.com>
Fri, 3 Jun 2016 01:21:37 +0000 (09:21 +0800)
committerNafee Chan <nafee.chan@gmail.com>
Mon, 13 Jun 2016 08:02:45 +0000 (08:02 +0000)
1. only when node's config statement is true, such apis as
GET/PUT/POST/DELETE config are added for this node;
2. when there are two or more top container/list nodes whose config
statement is true in module, make sure that only one root post link is added for this module.

Change-Id: I96d0b485c5943ad9bee63327c5d10e3cd0e5cb77
Signed-off-by: Nafee Chan <nafee.chan@gmail.com>
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);