Skip to content

LYD_PARSE_ANYDATA_STRICT does not enforce mandatory leafs inside anydata #2548

Open

Description

@rodonile

yanglint -A (LYD_PARSE_ANYDATA_STRICT): data missing a mandatory
leaf inside anydata validates successfully, while the identical data
fails correctly when it's not wrapped in anydata.
An invalid value for that same leaf is still correctly rejected inside anydata
too.

yanglint version: 6.1.5

Repro example

bug.yang

module bug {
  yang-version 1.1;
  namespace "urn:bug";
  prefix b;

  import ietf-yang-types { prefix yang; }

  list item {
    key "name";
    leaf name { type string; }
    leaf value { type yang:date-and-time; mandatory true; }
  }

  container top {
    anydata payload;
  }
}

1) value present but malformed, inside anydata → correctly fails

$ cat data-invalid-value.json
{
  "bug:top": {
    "payload": {
      "bug:item": [ { "name": "x", "value": "not-a-date" } ]
    }
  }
}
$ yanglint -A -e -p . bug.yang data-invalid-value.json -f json
libyang err : Unsatisfied pattern - "not-a-date" does not match "...". (/bug:top/payload/item[name='x']/value)
YANGLINT[E]: Failed to parse input data file "data-invalid-value.json".
$ echo $?
1

2) value (mandatory) missing entirely, inside anydata → BUG: passes

$ cat data-wrong.json
{
  "bug:top": {
    "payload": {
      "bug:item": [ { "name": "x" } ]
    }
  }
}
$ yanglint -A -e -p . bug.yang data-wrong.json -f json
{
  "bug:top": {
    "payload": {
      "item": [
        {
          "name": "x"
        }
      ]
    }
  }
}
$ echo $?
0

Expected: an error like Mandatory node "value" instance does not exist.

3) Control — same missing leaf, not inside anydata → fails as expected

$ cat control.json
{ "bug:item": [ { "name": "x" } ] }
$ yanglint -A -e -p . bug.yang control.json -f json
libyang err : Mandatory node "value" instance does not exist. (/bug:item[name='x'])
YANGLINT[E]: Failed to parse input data file "control.json".
$ echo $?
1

Activity

  1. michalvasko commented on Aug 7, 2026

    @michalvasko
    Member

    Should the data be fully validated? Strict parsing does not mean validation so the current functionality is not incorrect. Until a proper specification of anydata validation is out, I am not sure it makes sense to make any changes.

  2. added
    is:enhancementRequest for adding new feature or enahncing functionality.
    on Aug 7, 2026
  3. rodonile commented on Sep 8, 2026

    @rodonile
    Author

    @michalvasko this is also happening for sx:structure

    module bug-structure {
      yang-version 1.1;
      namespace "urn:bug-structure";
      prefix b;
    
      import ietf-yang-types { prefix yang; }
      import ietf-yang-structure-ext { prefix sx; }
    
      sx:structure top {
        list item {
          key "name";
          leaf name { type string; }
          leaf value { type yang:date-and-time; mandatory true; }
        }
      }
    }

    Json without mandatory value leaf.

    {
      "bug-structure:top": {
        "item": [
          {
            "name": "x"
          }
        ]
      }
    }
    yanglint -e -p . bug-structure.yang example.json
    $ echo $?
    0

    Let me know if I should open another issue.

    Cheers,
    Leonardo

  4. michalvasko commented on Sep 15, 2026

    @michalvasko
    Member

    Right, that was caused by a bug, fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:enhancementRequest for adding new feature or enahncing functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions