Skip to content

tree schema FEATURE emit paths suitable for key search #2394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/tree_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ lysc_path_until(const struct lysc_node *node, const struct lysc_node *parent, LY
buffer[0] = '\0';
}

if ((pathtype == LYSC_PATH_DATA) || (pathtype == LYSC_PATH_DATA_PATTERN)) {
if ((pathtype == LYSC_PATH_DATA) || (pathtype == LYSC_PATH_DATA_PATTERN) || (pathtype == LYSC_PATH_KEY_PATTERN)) {
/* skip schema-only nodes */
skip_schema = 1;
} else {
Expand All @@ -711,11 +711,11 @@ lysc_path_until(const struct lysc_node *node, const struct lysc_node *parent, LY
continue;
}

if ((pathtype == LYSC_PATH_DATA_PATTERN) && (iter->nodetype == LYS_LIST)) {
if (((pathtype == LYSC_PATH_DATA_PATTERN) || (pathtype == LYSC_PATH_KEY_PATTERN)) && (iter->nodetype == LYS_LIST)) {
char *predicates = NULL;

key = NULL;
while ((key = lys_getnext(key, iter, NULL, 0)) && lysc_is_key(key)) {
while ((key = lys_getnext(key, iter, NULL, 0)) && lysc_is_key(key) && ((pathtype != LYSC_PATH_KEY_PATTERN) || (key != node))) {
s = predicates;

/* print key predicate */
Expand Down
6 changes: 4 additions & 2 deletions src/tree_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2114,8 +2114,10 @@ LIBYANG_API_DECL const struct lysc_node *lys_find_path(const struct ly_ctx *ctx,
typedef enum {
LYSC_PATH_LOG, /**< Descriptive path format used in log messages */
LYSC_PATH_DATA, /**< Similar to ::LYSC_PATH_LOG except that schema-only nodes (choice, case) are skipped */
LYSC_PATH_DATA_PATTERN /**< Similar to ::LYSC_PATH_DATA but there are predicates for all list keys added with
"%s" where their values should be so that they can be printed there */
LYSC_PATH_DATA_PATTERN, /**< Similar to ::LYSC_PATH_DATA but there are predicates for all list keys added with
"%s" where their values should be so that they can be printed there */
LYSC_PATH_KEY_PATTERN /**< Similar to ::LYSC_PATH_DATA_PATTERN but if target node is a list key predicates
for this and subsequent keys are not emitted */
} LYSC_PATH_TYPE;

/**
Expand Down
8 changes: 8 additions & 0 deletions tests/utests/schema/test_schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -1896,6 +1896,14 @@ test_lysc_path(void **state)
path = lysc_path(node, LYSC_PATH_DATA_PATTERN, NULL, 0);
assert_string_equal(path, "/b:a/l[k='%s'][l='%s'][m='%s']/n");
free(path);
/* node is the same as in previous test */
path = lysc_path(node, LYSC_PATH_KEY_PATTERN, NULL, 0);
assert_string_equal(path, "/b:a/l[k='%s'][l='%s'][m='%s']/n");
free(path);
node = lys_find_path(UTEST_LYCTX, NULL, "/b:a/l/l", 0);
path = lysc_path(node, LYSC_PATH_KEY_PATTERN, NULL, 0);
assert_string_equal(path, "/b:a/l[k='%s']/l");
free(path);
}

/* TEST */
Expand Down