robshakir / pyangbind

A plugin for pyang that creates Python bindings for a YANG model.
Other
204 stars 121 forks source link

openconfig-acl.yang ietf json dumps sequence-id key as string #268

Closed AbhishekGtHub closed 1 year ago

AbhishekGtHub commented 4 years ago

I am trying to generate IETF json for openconfig-acl and using dumps method as follows

Python 2.7.17 (default, Nov 19 2019, 22:13:04) 
[GCC 9.1.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import openconfig_acl   
>>> from pyangbind.lib import pybindJSON
>>> base = openconfig_acl.openconfig_acl()
>>> acl = base.acl.acl_sets.acl_set.add("Test ACL_IPV4")
>>> entry100 = acl.acl_entries.acl_entry.add(100)
>>> entry100.config.sequence_id = 100
>>> print(pybindJSON.dumps(base, mode='ietf', indent=2))
{
  "openconfig-acl:acl": {
    "acl-sets": {
      "acl-set": [
        {
          "acl-entries": {
            "acl-entry": [
              {
                "config": {
                  "sequence-id": 100  <<<<<<<<<< Integer
                }, 
                "sequence-id": "100"  <<<<<<<<< String. Leafref to config/sequence-id
              }
            ]
          }, 
          "type": "ACL_IPV4", 
          "name": "Test"
        }
      ]
    }
  }
}

Sequence ID is a integer as per openconfig-acl.yang model https://github.com/openconfig/public/blob/master/release/models/acl/openconfig-acl.yang#L379 https://github.com/openconfig/public/blob/master/release/models/acl/openconfig-acl.yang#L337

and Integers are used for add API when creating the entry100 object but when dumps is called its in string format. Is this expected? Is there any option to generate the json such that the leafref sequence-id is also integer? Thanks.

mike-albano commented 4 years ago

Duplicate of Issue #139

xavier-contreras commented 1 year ago

Closing as duplicate of https://github.com/robshakir/pyangbind/issues/139 -- will try to look into this soon.