Adds handling of "leaf" node at the module level.
Change-Id: I55efb47b57d2f33b136b0dae8c82effe04ad706b
Signed-off-by: Abhishek Kumar <abhishk2@cisco.com>
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);
+ }
}
}
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;
--- /dev/null
+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
--- /dev/null
+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
"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.";
}
"Indicates the toaster service is available";
description
"Top-level container for all toaster database objects.";
-
+
leaf testToasterBits {
type bits {
bit testbit1 {
}
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 {
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.";
}
config false;
mandatory true;
description
- "This variable indicates the current state of
+ "This variable indicates the current state of
the 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 {
}
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.";
}
}
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.";
description
"Indicates the final toast status";
}
- }
- }
+ }
+ }