Bug 8311 - Apidoc: Incomprehensible 500 id model is wrong 00/56700/1
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Tue, 2 May 2017 13:05:11 +0000 (15:05 +0200)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Tue, 9 May 2017 07:02:05 +0000 (07:02 +0000)
Bug 8266 - Apidoc explorer is broken after installing Boron SR3

Depending on path if it is relative or absolute module has to be
resolved different ways. If it is relative path it will have to
be resolved through DataSchemaNote which returns namespace and
revision of module in which node is situated. If it is absolute
path we need TypeDefinition which returns a namespace and
revision of original module.

Change-Id: I522ea66383ba1d65e6674d5e8ff67ec31e019303
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
(cherry picked from commit 5ee44740e99f60768f488b7c8fb00873ed758a79)

restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/ModelGenerator.java

index a0e07adaf03726ad447965007d0a53ae39a39e16..75bfe75d0cd3d5ca00c586851690dd91f031633b 100644 (file)
@@ -12,9 +12,7 @@ import static org.opendaylight.netconf.sal.rest.doc.util.RestDocgenUtil.resolveN
 import com.google.common.base.Optional;
 import com.mifmif.common.regex.Generex;
 import java.io.IOException;
-import java.net.URI;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 import java.util.Set;
 import java.util.regex.Pattern;
@@ -24,6 +22,7 @@ import org.json.JSONException;
 import org.json.JSONObject;
 import org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder;
 import org.opendaylight.netconf.sal.rest.doc.model.builder.OperationBuilder.Post;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
@@ -506,23 +505,27 @@ public class ModelGenerator {
     private String processLeafRef(final DataSchemaNode node, final JSONObject property, final SchemaContext schemaContext,
                                   final TypeDefinition<?> leafTypeDef) {
         RevisionAwareXPath xPath = ((LeafrefTypeDefinition) leafTypeDef).getPathStatement();
-        final URI namespace = leafTypeDef.getQName().getNamespace();
-        final Date revision = leafTypeDef.getQName().getRevision();
-        final Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
         final SchemaNode schemaNode;
 
         final String xPathString = STRIP_PATTERN.matcher(xPath.toString()).replaceAll("");
         xPath = new RevisionAwareXPathImpl(xPathString, xPath.isAbsolute());
 
+        final Module module;
         if (xPath.isAbsolute()) {
+            module = findModule(schemaContext, leafTypeDef.getQName());
             schemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, module, xPath);
         } else {
+            module = findModule(schemaContext, node.getQName());
             schemaNode = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(schemaContext, module, node, xPath);
         }
 
         return processTypeDef(((TypedSchemaNode) schemaNode).getType(), (DataSchemaNode) schemaNode, property, schemaContext);
     }
 
+    private static Module findModule(final SchemaContext schemaContext, final QName qName) {
+        return schemaContext.findModuleByNamespaceAndRevision(qName.getNamespace(), qName.getRevision());
+    }
+
     private static String processBinaryType(final JSONObject property) throws JSONException {
         final JSONObject media = new JSONObject();
         media.put(BINARY_ENCODING_KEY, BASE_64);