-
Notifications
You must be signed in to change notification settings - Fork 120
Description
Consider a yang file:
`
module file {
yang-version 1.1;
namespace "urn:config:yang:interfaces";
prefix "dns-config";
import ietf-inet-types {
prefix inet;
}
// import ietf-yang-types {
// prefix yang;
// }
organization "ABC";
description "YANG module for DNS configuration";
revision 2021-03-03 {
description "Initial version";
}
container dnsconfig {
leaf DNSFwdSelection {
type string {
length "1";
pattern "[0-3]";
}
default "0";
}
leaf rdodhcpserver {
type string {
length "1";
pattern "[0-3]";
}
default "0";
}
leaf dns1 {
type inet:ipv4-address;
mandatory true;
}
}
}
`
When I validate this Yang file using go yang, I get the output below:
`
(ENV) IN-GN-53202:config_managment kashif.ali$ ./bin/goyang src/file.yang
2021/04/05 12:17:03 Registering default
2021/04/05 12:17:03 Registering default
// YANG module for DNS configuration
rw: dns-config:file {
rw: dns-config:dnsconfig {
rw: string dns-config:DNSFwdSelection
rw: ipv4-address dns-config:dns1
rw: string dns-config:rdodhcpserver
}
}
`
Now I used this file to generate a GO Struct using the Ygot package. I use that generated file to unmarshal the incoming JSON data against the generated GO struct, now when I validate that struct, in case if the dns1 field is missing. The validation doesn't throw any error as such for mandatory field missing.
Is there anything am I missing or is this the desired behavior?
In case if this is desired, then how do we enforce mandatory field at the time of validation?
Also when I validate the same yang file using pyang, I get a clear indication of which fields are mandatory(Highlighted in bold below). However, This is not the case with goyang.
(ENV) IN-GN-53202:config_managment kashif.ali$ pyang src/file.yang -f tree module: file +--rw dnsconfig +--rw DNSFwdSelection? string +--rw rdodhcpserver? string **+--rw dns1 inet:ipv4-address**