Error validating Juniper policy-options configuration: JSON contains unexpected field exact
When attempting to unmarshal a valid Juniper policy-options configuration (retrieved from device using show configuration | display json) to the generated struct using https://github.com/Juniper/yang/blob/master/23.4/23.4R2/native/conf-and-rpcs/junos/conf/models/junos-conf-policy-options%402023-01-01.yang I am getting this error:
parent container prefix-list-filter (type *policyoptions.JunosConfRoot_Configuration_PolicyOptions_PolicyStatement_Term_From_PrefixListFilter): JSON contains unexpected field exact
Looking at the model definition for prefix-list-filter it uses control_prefix_list_filter_type which shows that exact is a valid choice:
list prefix-list-filter {
key "list_name choice-ident choice-value";
ordered-by user;
description "List of prefix-list-filters to match";
uses control_prefix_list_filter_type;
}
grouping control_prefix_list_filter_type {
leaf list_name {
description "Name of prefix-list of routes to match";
type string;
}
leaf choice-ident {
type enumeration {
enum "exact" {
}
enum "longer" {
}
enum "orlonger" {
}
}
}
Here is the command I am using to generate:
go run ../generator/generator.go -generate_simple_unions -path='yang,ietf' -package_name=policyoptions -generate_fakeroot -fakeroot_name=device -output_file=pkg/junos/policyoptions.go yang/[email protected]
The relevant code I am using to validate the config is this (it works for other config sections: snmp, system, firewall, interfaces):
// previously loaded the json configuration into jsonData
d := &policyoptions.Device{}
if err := policyoptions.Unmarshal(jsonData, d); err != nil {
log.Fatal(err)
}
Am I doing something wrong when generating the struct, or is there an issue with juniper's yang model or how the generator parses it?
What is the JSON that you're inputting? If you're using exact as a field name -- the model snippet that you pasted shows that this is a value within the leaf choice-ident, so I'd expect to see "choice-ident": "exact" in the input JSON, whereas it sounds like you have "exact": <>.
r.
This is a problem on the Juniper side. They can't currently parse choice-ident/choice-value fields in JSON/YANG payloads (only works for XML). We opened a PR to get it fixed.
Thanks Nicolas! I'll close this given that information.