+ public static @NonNull Data normalizeSubResource(final Data resource, final ApiPath subResource) {
+ // If subResource is empty just return the resource
+ final var urlPath = resource.instance();
+ if (subResource.steps().isEmpty()) {
+ return resource;
+ }
+ final var normalizer = new ApiPathNormalizer(resource.databind());
+ if (urlPath.isEmpty()) {
+ // URL indicates the datastore resource, let's just normalize targetPath
+ return normalizer.normalizeDataPath(subResource);
+ }
+
+ // FIXME: We are re-parsing the concatenation. We should provide enough context for the bottom half of
+ // normalizePath() logic instead
+ final String targetUrl = normalizer.canonicalize(urlPath).toString() + "/" + subResource.toString();
+ try {
+ return normalizer.normalizeDataPath(ApiPath.parse(targetUrl));
+ } catch (ParseException e) {
+ throw new RestconfDocumentedException("Failed to parse target " + targetUrl,
+ ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE, e);
+ }
+ }
+