From a8c3191fe0a8768646299e28971529001676a97d Mon Sep 17 00:00:00 2001 From: Devin Avery Date: Thu, 3 Jul 2014 06:04:07 -0400 Subject: [PATCH] Bug 1290 - Swagger Documentation is failing to load - java script exception Fixed how we generated the json model representing yang union types Fixed json model naming for nested container types. To validate: 1) deploy fix, and load http://localhost:8080/apidoc/explorer. 2) Verify the page loads and you can expand opendaylight-inventory:nodes. 3) Search for "node-connector" and expand a node-connector definition. Verify that the "port-number" type says "integer or string". Change-Id: I8aae18ba4805c3ee57cbb655807af4f15ee61756 Signed-off-by: Devin Avery --- .../sal/rest/doc/impl/ModelGenerator.java | 22 ++++++++++++------- .../src/main/resources/explorer/index.html | 1 - .../rest/doc/impl/ApiDocGeneratorTest.java | 20 +++++++++++++++++ 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java b/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java index 0e929afc84..755ca75015 100644 --- a/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java +++ b/opendaylight/md-sal/sal-rest-docgen/src/main/java/org/opendaylight/controller/sal/rest/doc/impl/ModelGenerator.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.commons.lang3.BooleanUtils; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -249,7 +250,7 @@ public class ModelGenerator { if (node instanceof LeafSchemaNode) { property = processLeafNode((LeafSchemaNode) node); } else if (node instanceof ListSchemaNode) { - property = processListSchemaNode((ListSchemaNode) node, moduleName, models); + property = processListSchemaNode((ListSchemaNode) node, moduleName, models, isConfig); } else if (node instanceof LeafListSchemaNode) { property = processLeafListNode((LeafListSchemaNode) node); @@ -354,15 +355,17 @@ public class ModelGenerator { * * @param listNode * @param moduleName + * @param isConfig * @return * @throws JSONException * @throws IOException */ private JSONObject processListSchemaNode(ListSchemaNode listNode, String moduleName, - JSONObject models) throws JSONException, IOException { + JSONObject models, Boolean isConfig) throws JSONException, IOException { Set listChildren = listNode.getChildNodes(); - String fileName = listNode.getQName().getLocalName(); + String fileName = (BooleanUtils.isNotFalse(isConfig)?OperationBuilder.CONFIG:OperationBuilder.OPERATIONAL) + + listNode.getQName().getLocalName(); JSONObject childSchemaProperties = processChildren(listChildren, moduleName, models); JSONObject childSchema = getSchemaTemplate(); @@ -541,12 +544,15 @@ public class ModelGenerator { private void processUnionType(UnionTypeDefinition unionType, JSONObject property) throws JSONException { - List> unionTypes = unionType.getTypes(); - JSONArray unionArray = new JSONArray(); - for (TypeDefinition typeDef : unionTypes) { - unionArray.put(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass())); + StringBuilder type = new StringBuilder(); + for (TypeDefinition typeDef : unionType.getTypes() ) { + if( type.length() > 0 ){ + type.append( " or " ); + } + type.append(YANG_TYPE_TO_JSON_TYPE_MAPPING.get(typeDef.getClass())); } - property.put(TYPE_KEY, unionArray); + + property.put(TYPE_KEY, type ); } /** diff --git a/opendaylight/md-sal/sal-rest-docgen/src/main/resources/explorer/index.html b/opendaylight/md-sal/sal-rest-docgen/src/main/resources/explorer/index.html index 2816f79e24..05a76a4cb7 100644 --- a/opendaylight/md-sal/sal-rest-docgen/src/main/resources/explorer/index.html +++ b/opendaylight/md-sal/sal-rest-docgen/src/main/resources/explorer/index.html @@ -24,7 +24,6 @@ -