Closed
Description
Hi,
Parsing a data tree with obsolete container in the schema gives a warning
even if the container is not present in the data tree.
Is it expected ?
Should we look inside the container if something is present before returning the warning?
This is an example:
#include <libyang.h>
#include <stdio.h>
#include <stdlib.h>
/* gcc -o libyang_test libyang_test.c -I /usr/local/include/libyang -lyang */
#define UTEST_ADD_MODULE(DATA, FORMAT, FEATURES, MOD) \
ly_in_new_memory(DATA, &in); \
{ \
LY_ERR __r = lys_parse(ctx, in, FORMAT, FEATURES, MOD); \
if (__r != LY_SUCCESS) { \
printf("[ MSG ] Module parsing failed:\n"); \
for (const struct ly_err_item *e = ly_err_first(ctx); e; e = e->next) { \
printf("[ MSG ] \t%s Schema path %s\n", e->msg, e->schema_path); \
} \
exit(-1); \
} \
} \
ly_in_free(in, 0); \
in = NULL
#define CHECK_PARSE_LYD_PARAM(INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, RET, OUT_NODE) \
{ \
LY_ERR _r = lyd_parse_data_mem(ctx, INPUT, INPUT_FORMAT, PARSE_OPTIONS, VALIDATE_OPTIONS, &OUT_NODE); \
if (_r != RET) { \
if (_r) { \
printf("%s != 0x%d; MSG: %s", #RET, _r, ly_err_last(ctx)->msg); \
} else { \
printf("%s != 0x%d", #RET, _r); \
} \
} \
}
#define LYD_TREE_CREATE(INPUT, MODEL) \
CHECK_PARSE_LYD_PARAM(INPUT, LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_SUCCESS, MODEL)
int main(int argc, char *argv[])
{
struct lyd_node *tree;
struct ly_ctx *ctx; /**< libyang context */
struct ly_in *in; /**< Input handler */
const char *schema =
"module a {\n"
" namespace urn:tests:a;\n"
" prefix a;\n"
" yang-version 1.1;\n"
"\n"
" container cont {\n"
" leaf a {\n"
" type string;\n"
" }\n"
" leaf b {\n"
" type string;\n"
" }\n"
" container cont2 {\n"
" leaf b {\n"
" type string;\n"
" }\n"
" status obsolete;\n"
" }\n"
" }\n"
"}";
ly_ctx_new(NULL, 0, &ctx);
UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
LYD_TREE_CREATE("<cont xmlns=\"urn:tests:a\"><b>val_b</b></cont>", tree);
lyd_free_all(tree);
}
It gives:
"Obsolete schema node "cont2" instantiated in data."
Whereas cont2 is not in the data tree.
Thank you.
Best regards.