Fix docgen for action types 72/100672/3
authorPeter Suna <peter.suna@pantheon.tech>
Wed, 20 Apr 2022 13:10:07 +0000 (15:10 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 20 Apr 2022 17:40:22 +0000 (19:40 +0200)
When we are processing actions we need to adjust the stack to enter
each of them for the duration of traversal. Also add the corresponding
test.

JIRA: NETCONF-872
Change-Id: I5aae78380073c4d5c876b888b22cd41a2657db2d
Signed-off-by: Peter Suna <peter.suna@pantheon.tech>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java
restconf/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/SwaggerObjectTest.java
restconf/sal-rest-docgen/src/test/resources/yang/action-types.yang [new file with mode: 0644]

index f7817c0daf8c86132522c38e7ae9db7c3d9c682a..bd2ef8e83af1cf01349f1c2f8d742db3b2975100 100644 (file)
@@ -257,7 +257,9 @@ public class DefinitionGenerator {
                                             final SchemaInferenceStack stack, final OAversion oaversion)
             throws IOException {
         for (final ActionDefinition actionDef : ((ActionNodeContainer) childNode).getActions()) {
+            stack.enterSchemaTree(actionDef.getQName());
             processOperations(actionDef, moduleName, definitions, definitionNames, stack, oaversion);
+            stack.exit();
         }
     }
 
index 889606d7e6fe1777ee149fef15f70c820a1f2e80..f37b8ee692698b7a5f694bca6be2ac3894216f2e 100644 (file)
@@ -40,6 +40,16 @@ public final class SwaggerObjectTest {
         Assert.assertNotNull(jsonObject);
     }
 
+    @Test
+    public void testActionTypes() throws Exception {
+        final Optional<? extends Module> module = context.findModule("action-types");
+        assertTrue("Desired module not found", module.isPresent());
+        final DefinitionGenerator generator = new DefinitionGenerator();
+        final ObjectNode jsonObject = generator.convertToJsonSchema(module.get(), context,
+                new DefinitionNames(), ApiDocServiceImpl.OAversion.V2_0, true);
+        Assert.assertNotNull(jsonObject);
+    }
+
     @Test
     public void testStringTypes() throws Exception {
         final Optional<? extends Module> module = context.findModule("string-types");
diff --git a/restconf/sal-rest-docgen/src/test/resources/yang/action-types.yang b/restconf/sal-rest-docgen/src/test/resources/yang/action-types.yang
new file mode 100644 (file)
index 0000000..4d6d316
--- /dev/null
@@ -0,0 +1,50 @@
+module action-types {
+  yang-version 1.1;
+  namespace "urn:ietf:params:xml:ns:yang:test:action:types";
+  prefix "act-tp";
+
+  list list {
+    key name;
+    leaf name {
+      type string;
+    }
+    action list-action {
+      input {
+        leaf la-input {
+          type string;
+          mandatory true;
+        }
+      }
+      output {
+        leaf la-output {
+          type string;
+          mandatory true;
+        }
+      }
+    }
+  }
+
+  container container {
+    action container-action {
+      input {
+        leaf ca-input {
+          type string;
+          mandatory true;
+        }
+      }
+      output {
+        leaf ca-output {
+          type string;
+          mandatory true;
+        }
+      }
+    }
+  }
+
+  container multi-container {
+    container inner-container {
+      action action {
+      }
+    }
+  }
+}