Fixes bug 2114 88/11688/1
authorAbhishek Kumar <abhishk2@cisco.com>
Wed, 1 Oct 2014 05:16:08 +0000 (22:16 -0700)
committerAbhishek Kumar <abhishk2@cisco.com>
Wed, 1 Oct 2014 05:44:13 +0000 (22:44 -0700)
Adds handling of "leaf" node at the module level.

Change-Id: I55efb47b57d2f33b136b0dae8c82effe04ad706b
Signed-off-by: Abhishek Kumar <abhishk2@cisco.com>
opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java
opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGeneratorTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-rest-docgen/src/test/resources/yang/opflex.yang [new file with mode: 0644]
opendaylight/md-sal/sal-rest-docgen/src/test/resources/yang/toaster.yang

index f4274870c9305d84f1ee53798bb934f8721748a4..3b503ebba35c016382d390ad695c4bda7c553ef2 100644 (file)
@@ -146,8 +146,10 @@ public class ModelGenerator {
 
         for (DataSchemaNode childNode : module.getChildNodes()) {
             // For every container and list in the module
-            processDataNodeContainer((DataNodeContainer) childNode, moduleName, models, true, schemaContext);
-            processDataNodeContainer((DataNodeContainer) childNode, moduleName, models, false, schemaContext);
+            if (childNode instanceof ContainerSchemaNode || childNode instanceof ListSchemaNode) {
+                processDataNodeContainer((DataNodeContainer) childNode, moduleName, models, true, schemaContext);
+                processDataNodeContainer((DataNodeContainer) childNode, moduleName, models, false, schemaContext);
+            }
         }
 
     }
@@ -306,6 +308,9 @@ public class ModelGenerator {
                 property.put(TYPE_KEY, childNode instanceof ListSchemaNode ? ARRAY_TYPE : OBJECT_TYPE);
                 property.put(ITEMS_KEY, items);
                 properties.put(childNode.getQName().getLocalName(), property);
+            } else if (childNode instanceof LeafSchemaNode){
+                JSONObject property = processLeafNode((LeafSchemaNode)childNode);
+                properties.put(childNode.getQName().getLocalName(), property);
             }
         }
         return properties;
diff --git a/opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGeneratorTest.java b/opendaylight/md-sal/sal-rest-docgen/src/test/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGeneratorTest.java
new file mode 100644 (file)
index 0000000..5918a0e
--- /dev/null
@@ -0,0 +1,45 @@
+package org.opendaylight.controller.sal.rest.doc.impl;
+
+import com.google.common.base.Preconditions;
+import org.json.JSONObject;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Map;
+
+
+public class ModelGeneratorTest {
+
+    private DocGenTestHelper helper;
+    private SchemaContext schemaContext;
+
+    @Before
+    public void setUp() throws Exception {
+        helper = new DocGenTestHelper();
+        helper.setUp();
+        schemaContext = new YangParserImpl().resolveSchemaContext(new HashSet<Module>(helper.getModules().values()));
+    }
+
+    @Test
+    public void testConvertToJsonSchema() throws Exception {
+
+        Preconditions.checkArgument(helper.getModules() != null, "No modules found");
+
+        ModelGenerator generator = new ModelGenerator();
+
+        for (Map.Entry<File, Module> m : helper.getModules().entrySet()) {
+            if (m.getKey().getAbsolutePath().endsWith("opflex.yang")) {
+
+                JSONObject jsonObject = generator.convertToJsonSchema(m.getValue(), schemaContext);
+                Assert.assertNotNull(jsonObject);
+            }
+        }
+
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-rest-docgen/src/test/resources/yang/opflex.yang b/opendaylight/md-sal/sal-rest-docgen/src/test/resources/yang/opflex.yang
new file mode 100644 (file)
index 0000000..8e598dd
--- /dev/null
@@ -0,0 +1,50 @@
+module opflex {
+    yang-version 1;
+
+    namespace "urn:opendaylight:groupbasedpolicy:opflex";
+    prefix "opflex";
+
+
+
+
+
+    description
+        "This module defines the group-based policy OpFlex renderer model.";
+
+    revision "2014-05-28" {
+        description
+            "Initial revision.";
+    }
+
+    typedef serialization {
+        description
+            "The serialization to use for OpFlex messages.";
+
+        type enumeration {
+            enum json {
+                description
+                "JSON 1.0 serialization.";
+            }
+            enum xml {
+                description
+                "XML serialization.";
+            }
+            enum binary {
+                description
+                "OpFlex binary serialization.";
+            }
+        }
+    }
+
+    // ******************
+    // Configuration Data
+    // ******************
+    leaf domain {
+        description
+            "The OpFlex administrative domain.";
+
+        config true;
+
+        type string;
+    }
+}
\ No newline at end of file
index 20bbd78622eb839d9679e3909769ed188ebd3c22..ffddc8c3daa0f36f8ea51a2e4e39000b44438fe6 100644 (file)
@@ -20,11 +20,19 @@ module toaster {
         "Toaster module in progress.";
     }
 
+    leaf domain {
+        description
+            "Toaster domain.";
+
+        config true;
+
+        type string;
+    }
 
     identity toast-type {
       description
           "Base for all bread types supported by the toaster.
-           New bread types not listed here nay be added in the 
+           New bread types not listed here nay be added in the
            future.";
     }
 
@@ -72,7 +80,7 @@ module toaster {
         "Indicates the toaster service is available";
       description
         "Top-level container for all toaster database objects.";
-        
+
       leaf testToasterBits {
          type bits {
              bit testbit1 {
@@ -84,21 +92,21 @@ module toaster {
          }
          default "testbit2";
      }
-     
+
      leaf testUnion {
         type union {
          type int32;
          type string;
         }
-        
-     } 
-     
+
+     }
+
      leaf-list allow-user  {
           type string;
           description "A list of user name patterns to allow";
-        
+
         }
-        
+
         choice how {
              default interval;
              case interval {
@@ -123,14 +131,14 @@ module toaster {
                      type string;
                  }
              }
-         } 
-        
+         }
+
       leaf toasterManufacturer {
         type DisplayString;
         config false;
         mandatory true;
         description
-          "The name of the toaster's manufacturer. For instance, 
+          "The name of the toaster's manufacturer. For instance,
                 Microsoft Toaster.";
       }
 
@@ -161,7 +169,7 @@ module toaster {
         config false;
         mandatory true;
         description
-          "This variable indicates the current state of 
+          "This variable indicates the current state of
                the toaster.";
       }
     }
@@ -169,11 +177,11 @@ module toaster {
     rpc make-toast {
       description
         "Make some toast.
-           The toastDone notification will be sent when 
+           The toastDone notification will be sent when
            the toast is finished.
            An 'in-use' error will be returned if toast
            is already being made.
-           A 'resource-denied' error will be returned 
+           A 'resource-denied' error will be returned
            if the toaster service is disabled.";
       input {
         leaf toasterDoneness {
@@ -182,10 +190,10 @@ module toaster {
           }
           default '5';
           description
-            "This variable controls how well-done is the 
+            "This variable controls how well-done is the
                    ensuing toast. It should be on a scale of 1 to 10.
-                   Toast made at 10 generally is considered unfit 
-                   for human consumption; toast made at 1 is warmed 
+                   Toast made at 10 generally is considered unfit
+                   for human consumption; toast made at 1 is warmed
                    lightly.";
         }
 
@@ -195,23 +203,23 @@ module toaster {
           }
           default 'wheat-bread';
           description
-            "This variable informs the toaster of the type of 
-                   material that is being toasted. The toaster 
-                   uses this information, combined with 
-                   toasterDoneness, to compute for how 
-                   long the material must be toasted to achieve 
+            "This variable informs the toaster of the type of
+                   material that is being toasted. The toaster
+                   uses this information, combined with
+                   toasterDoneness, to compute for how
+                   long the material must be toasted to achieve
                    the required doneness.";
         }
       }
-    }  
+    }
 
     rpc cancel-toast {
       description
         "Stop making toast, if any is being made.
-           A 'resource-denied' error will be returned 
+           A 'resource-denied' error will be returned
            if the toaster service is disabled.";
-    }  
-    
+    }
+
     notification toastDone {
       description
         "Indicates that the toast in progress has completed.";
@@ -236,5 +244,5 @@ module toaster {
         description
           "Indicates the final toast status";
       }
-    }  
-  }  
+    }
+  }