libyang icon indicating copy to clipboard operation
libyang copied to clipboard

lyd_parse_data_mem ignore subsequent data after a data without matching schema node definition, is this the expectation?

Open lyzliyuzhi91 opened this issue 2 years ago • 5 comments

module

module xxx-ifm {
  namespace "urn:xxx:yang:xxx-ifm";
  prefix ifm;

  container ifm {
      .....
  }
}
module xxx-aaa{
  namespace "urn:xxx:yang:xxx-aaa";
  prefix aaa;

  container aaa {
      .....
  }
}

rpc_message_1:

"{\"huawei-ifm:ifm\":{},\"xxx:inexisted\":{\"tcp-global\":{\"tcp-max-mss\":1460}},\"huawei-aaa:aaa\":{}}"

rpc_message_2:

"{\"xxx:inexisted\":{\"tcp-global\":{\"tcp-max-mss\":1460}},\"huawei-ifm:ifm\":{}}"

In which xxx:inexisted is a data that cannot match a schema. when I call lyd_parse_data_mem:

LY_ERR err = lyd_parse_data_mem(ly_ctx, <rpc_message_n>, LYD_JSON, LYD_PARSE_WHEN_TRUE | LYD_PARSE_NO_STATE | LYD_PARSE_ONLY, 0, &ly_data);

for rpc_message_1, the ly_data only contain ifm and not contain inexisted and aaa, for rpc_message_2, the ly_data is null pointer. It seems that libyang once encounter a data that cannot match schema, libyang will drop the remaing data. Is this the expection when design ?

version 2.1.30

thanks

lyzliyuzhi91 avatar Aug 18 '23 06:08 lyzliyuzhi91

Is this the expection when design ?

Yes, if LYD_PARSE_STRICT is not used when parsing the data.

michalvasko avatar Aug 18 '23 10:08 michalvasko

Fine...I though it would just ignore the mere data that cannot match schema and would go to parse the remain data 🤣

lyzliyuzhi91 avatar Aug 18 '23 10:08 lyzliyuzhi91

I should start reading the issues more carefully, I have not understood what is the actual problem you are having, sorry. In any case, I have tried your use-cases and it worked for me as expected meaning only the unknown node with all the descendants was ignored and all the known containers parsed normally.

michalvasko avatar Aug 18 '23 11:08 michalvasko

For example,

"{\"huawei-ifm:ifm\":{},\"xxx:inexisted\":{\"tcp-global\":{\"tcp-max-mss\":1460}},\"huawei-aaa:aaa\":{}}"

there is three top node, ifm, inexisted and aaa. When the parser process inexisted, because it has no schema matched, and it is ignored, and I think it is ok. But the next sibling aaa will be ignore too, I think the parser should not ignore the remaining siblings.

lyzliyuzhi91 avatar Aug 24 '23 07:08 lyzliyuzhi91

Please provide the exact YANG modules and data to reproduce, it worked fine for me with your JSON data and small modules I have written based on them, only the non-existing node has been skipped.

michalvasko avatar Aug 24 '23 09:08 michalvasko