Fix patch target parsing
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / utils / parser / ParserIdentifier.java
index 305b93ff7a95829daa5c8f34ea992eee13158842..9bfd60b3e69a4af2052736853f383fc70364e723 100644 (file)
@@ -270,6 +270,20 @@ public final class ParserIdentifier {
         }
     }
 
+    public static YangInstanceIdentifier parserPatchTarget(final InstanceIdentifierContext<?> context,
+            final String target) {
+        final var schemaContext = context.getSchemaContext();
+        final var urlPath = context.getInstanceIdentifier();
+        final String targetUrl;
+        if (urlPath.isEmpty()) {
+            targetUrl = target.startsWith("/") ? target.substring(1) : target;
+        } else {
+            targetUrl = stringFromYangInstanceIdentifier(urlPath, schemaContext) + target;
+        }
+
+        return toInstanceIdentifier(targetUrl, schemaContext, Optional.empty()).getInstanceIdentifier();
+    }
+
     /**
      * Validation and parsing of revision.
      *