Fix wrong path reference - schema for actions 25/109825/7
authorlubos-cicut <lubos.cicut@pantheon.tech>
Wed, 17 Jan 2024 16:53:30 +0000 (17:53 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 26 Jan 2024 09:31:18 +0000 (09:31 +0000)
After rewrite we lost reference to parent node in some of actions
paths. This patch repairs it.

JIRA: NETCONF-938
Change-Id: I90d048a3157e0cf07b52621eee351ee6119790af
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/impl/PathsStream.java
restconf/restconf-openapi/src/main/java/org/opendaylight/restconf/openapi/model/PostEntity.java

index 61b3e37983f55cd58a6e2c2a963fd9eb8f025301..514f992fdfee08668735b4e4dafaa0257859c2d6 100644 (file)
@@ -146,7 +146,7 @@ public final class PathsStream extends InputStream {
                     final var localName = moduleName + ":" + nodeLocalName;
                     final var path = urlPrefix + "/" + processPath(node, pathParams, localName);
                     processChildNode(node, pathParams, moduleName, result, path, nodeLocalName, isConfig, schemaContext,
-                        deviceName, basePath);
+                        deviceName, basePath, node);
                 }
             }
         }
@@ -156,7 +156,7 @@ public final class PathsStream extends InputStream {
     private static void processChildNode(final DataSchemaNode node, final List<ParameterEntity> pathParams,
             final String moduleName, final Deque<PathEntity> result, final String path, final String refPath,
             final boolean isConfig, final EffectiveModelContext schemaContext, final String deviceName,
-            final String basePath) {
+            final String basePath, final SchemaNode parentNode) {
         final var resourcePath = basePath + DATA + path;
         final var fullName = resolveFullNameFromNode(node.getQName(), schemaContext);
         final var firstChild = getListOrContainerChildNode((DataNodeContainer) node);
@@ -175,7 +175,7 @@ public final class PathsStream extends InputStream {
                     node.getQName(), schemaContext);
                 final var childPath = basePath + OPERATIONS + resourceActionPath;
                 result.add(processRootAndActionPathEntity(actionDef, childPath, actionParams, moduleName,
-                    refPath, deviceName));
+                    refPath, deviceName, parentNode));
             });
         }
         for (final var childNode : childNodes) {
@@ -186,7 +186,7 @@ public final class PathsStream extends InputStream {
                 final var resourceDataPath = path + "/" + processPath(childNode, childParams, localName);
                 final var newConfig = isConfig && childNode.isConfiguration();
                 processChildNode(childNode, childParams, moduleName, result, resourceDataPath, newRefPath, newConfig,
-                    schemaContext, deviceName, basePath);
+                    schemaContext, deviceName, basePath, node);
             }
         }
     }
@@ -234,9 +234,9 @@ public final class PathsStream extends InputStream {
 
     private static PathEntity processRootAndActionPathEntity(final SchemaNode node, final String resourcePath,
             final List<ParameterEntity> pathParams, final String moduleName, final String refPath,
-            final String deviceName) {
+            final String deviceName, final SchemaNode parentNode) {
         return new PathEntity(resourcePath,
-            new PostEntity(node, deviceName, moduleName, pathParams, refPath, null),
+            new PostEntity(node, deviceName, moduleName, pathParams, refPath, parentNode),
             null, null, null, null);
     }
 
index 11172bfd5709e5996e0dce2710ebc607133c572c..7dceda734f168a9a4f561fb17c2c1a268fa307fc 100644 (file)
@@ -18,6 +18,7 @@ import javax.ws.rs.HttpMethod;
 import javax.ws.rs.core.MediaType;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
+import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -53,7 +54,7 @@ public final class PostEntity extends OperationEntity {
         if (parentNode instanceof Module) {
             return SUMMARY_TEMPLATE.formatted(HttpMethod.POST, deviceName(), moduleName(), moduleName());
         }
-        if (parentNode != null) {
+        if (parentNode != null && !(schema() instanceof OperationDefinition)) {
             return SUMMARY_TEMPLATE.formatted(HttpMethod.POST, deviceName(), moduleName(),
                 ((DataSchemaNode) parentNode).getQName().getLocalName());
         }
@@ -68,7 +69,7 @@ public final class PostEntity extends OperationEntity {
             final var operationName = rpc.getQName().getLocalName();
             if (!output.getChildNodes().isEmpty()) {
                 // TODO: add proper discriminator from DefinitionNames when schemas re-implementation is done
-                final var ref = COMPONENTS_PREFIX + moduleName() + "_" + operationName + "_output";
+                final var ref = processOperationsRef(rpc, operationName, "_output");
                 generator.writeObjectFieldStart(String.valueOf(OK.getStatusCode()));
                 generator.writeStringField(DESCRIPTION, String.format("RPC %s success", operationName));
 
@@ -103,7 +104,7 @@ public final class PostEntity extends OperationEntity {
             generator.writeObjectFieldStart(CONTENT);
             if (!input.getChildNodes().isEmpty()) {
                 // TODO: add proper discriminator from DefinitionNames when schemas re-implementation is done
-                final var ref = COMPONENTS_PREFIX + moduleName() + "_" + operationName + INPUT_SUFFIX;
+                final var ref = processOperationsRef(rpc, operationName, INPUT_SUFFIX);
                 generator.writeObjectFieldStart(MediaType.APPLICATION_JSON);
                 generator.writeObjectFieldStart(SCHEMA);
                 generator.writeObjectFieldStart("properties");
@@ -202,10 +203,21 @@ public final class PostEntity extends OperationEntity {
 
     @Override
     @Nullable String description() {
-        if (parentNode != null) {
+        if (parentNode != null && !(schema() instanceof OperationDefinition)) {
             return parentNode.getDescription().orElse("");
         } else {
             return super.description();
         }
     }
+
+    private String processOperationsRef(final OperationDefinition def, final String operationName, final String suf) {
+        final var ref = COMPONENTS_PREFIX + moduleName() + "_" + operationName + suf;
+        if (def instanceof ActionDefinition && parentNode != null) {
+            final var parentName = ((DataSchemaNode) parentNode).getQName().getLocalName();
+            if (!operationName.contains(parentName)) {
+                return COMPONENTS_PREFIX + moduleName() + "_" + parentName + "_" + operationName + suf;
+            }
+        }
+        return ref;
+    }
 }