corenova / yang-js

YANG parser and composer
Apache License 2.0
56 stars 18 forks source link

toString() issue #109

Closed majakizic closed 4 years ago

majakizic commented 4 years ago

Hi

There is an issue in toString() method when printing a module that includes a submodule. The issue is that the printout contains an entire schema , for example:

file ex1.yang:

module ex1 {
    namespace "http://ex.com/ex1";
    prefix ex1; 
   include ex1-sub;     
    revision 2018-09-24;
    container cont1 {
        leaf a1 {
            type string;
        }
    }
}

file ex1-sub.yang:

submodule ex1-sub {
    belongs-to ex1 {
        prefix ex1;
    }
    revision 2019-07-22;
    typedef atype {
        type string;
    }
}

console.log(Yang.import('ex1.yang').toString()); console.log(Yang.import('ex1-sub.yang').toString());

results in following:

module ex1 {
  namespace 'http://ex.com/ex1';
  prefix 'ex1';
  include ex1-sub;
  revision 2018-09-24;
  container cont1 {
    leaf a1 {
      type string;
    }
  }
  typedef atype {
    type string;
  }
}
submodule ex1-sub {
  belongs-to ex1 {
    prefix 'ex1';
  }
  revision 2019-07-22;
}

Is it possible to tag submodule element so that the toString matches the original module?

sekur commented 4 years ago

Hi @majakijic, can you elaborate on what you'd like to see as expected toString output? Is the issue that the sub statements for the submodule is no longer present after being included by the main module?

majakizic commented 4 years ago

Hi, thanks for the reply. yes, I think that is the issue. What I would expect to see from the toString is the original module content without submodule’s elements and the original content of the submodule as well.

The schema is still valid but it would be useful to tag submodule’s elements in the yang object so that it is possible to associate those with the included submodule.

There is also an another issue with the toString that I just noticed, the multiple keys in a list are comma separated
list bar { key 'b1,b2'; leaf b1 { type uint16; } leaf b2 { type uint16; } }

sekur commented 4 years ago

Hi @majakizic I think for your use case, perhaps what you want to do is import YANG schema without compiling?

Yang.import('ex-1.yang', { compile: false });

When you use Yang.import it will compile the schema, which will modify the schema during the process such as attaching definitions and such from include statements.

The issue with key being serialized with commas is definitely a bug and I will address that one.

majakizic commented 4 years ago

ok, thanks so much for your help.