From: Ivan Hrasko Date: Fri, 11 Feb 2022 19:57:19 +0000 (+0100) Subject: Replace #getPath in processInstanceIdentifierType X-Git-Tag: v3.0.0~104 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F99699%2F3;p=netconf.git Replace #getPath in processInstanceIdentifierType DefinitionGenerator#processInstanceIdentifierType method was used to create an example of the instance-identifier leaf node's value. For this purpose SchemaPath#getPath method was used to search for 'root' container. In fact, this approach leads to incorrect results because it can for example find an RPC definition as 'root' container. RPC definition cannot be used as instance-identifier value because its not a data node. We have reworked this method to use as an example the first container child of the node's model. This way we can also get-rid of deprecated SchemaPath#getPath method. Signed-off-by: Ivan Hrasko Change-Id: I2a4f1dc2e76ae9117bc826e45b0d9c0379cb5213 --- diff --git a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java index 939eaf6f53..4b73091054 100644 --- a/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java +++ b/restconf/sal-rest-docgen/src/main/java/org/opendaylight/netconf/sal/rest/doc/impl/DefinitionGenerator.java @@ -56,7 +56,6 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.OperationDefinition; import org.opendaylight.yangtools.yang.model.api.RpcDefinition; import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; @@ -895,16 +894,16 @@ public class DefinitionGenerator { private static String processInstanceIdentifierType(final DataSchemaNode node, final ObjectNode property, final EffectiveModelContext schemaContext) { - SchemaPath path = node.getPath(); - - while (path.getParent() != null && path.getParent().getPathFromRoot().iterator().hasNext()) { - path = path.getParent(); + // create example instance-identifier to the first container of node's module if exists or leave it empty + final var module = schemaContext.findModule(node.getQName().getModule()); + if (module.isPresent()) { + final var container = module.get().getChildNodes().stream() + .filter(n -> n instanceof ContainerSchemaNode) + .findFirst(); + container.ifPresent(c -> setDefaultValue(property, String.format("/%s:%s", module.get().getPrefix(), + c.getQName().getLocalName()))); } - final QName rootContainer = path.getLastComponent(); - final String rootContainerName = rootContainer.getLocalName(); - final String prefix = schemaContext.findModule(rootContainer.getModule()).get().getPrefix(); - setDefaultValue(property, String.format("/%s:%s", prefix, rootContainerName)); return STRING_TYPE; }