CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
364 stars 291 forks source link

Unnecessary namespaces and prefixes for identityref values #1792

Closed pfeige closed 2 years ago

pfeige commented 2 years ago

Hi,

it seems that identityref values always have explicit namespaces with prefix when printed in printer_xml.c. Please consider the following schema modules:

module issue-namespace {
  namespace "urn:issue:namespace";
  prefix ins;

  identity char;
  identity a { base char; }
  identity b { base char; }
  identity c { base char; }

  container root {
    leaf my-char {
      type identityref { base char; }
    }
  }
}

module issue-namespace-aug {
  namespace "urn:issue:namespace:aug";
  prefix insa;

  import issue-namespace {
    prefix ins;
  }

  identity color;
  identity red   { base color; }
  identity green { base color; }
  identity blue  { base color; }

  augment "/ins:root" {
    leaf my-color {
      type identityref { base color; }
    }
  }
}

When the following XML snippet is imported with sysrepocfg

<root xmlns="urn:issue:namespace">
  <my-char>a</my-char>
  <my-color xmlns="urn:issue:namespace:aug">green</my-color>
</root>

and then exported again it looks like this

<root xmlns="urn:issue:namespace">
  <my-char xmlns:ins="urn:issue:namespace">ins:a</my-char>
  <my-color xmlns="urn:issue:namespace:aug" xmlns:insa="urn:issue:namespace:aug">insa:green</my-color>
</root>

Would it be feasible to omit these unnecessary prefixes and namespaces?

BR, Peter

michalvasko commented 2 years ago

This is not currently possible because it would require the printer callbacks to be aware of the module of their node, which they are not. The advantage of the current approach is also that a value is always printed the same way (assuming the prefixes of the same modules are the same) so you have something akin to a canonical value and that it differentiates an identity from other kinds of values such as enum. So I am not sure it is worth changing it.

pfeige commented 2 years ago

This is not really a problem for me. I only wanted to get some tests passed which issue an edit-config and then check the response of the get-config. Now I will modify the expected response accordingly. Thanks!