ygot
ygot copied to clipboard
RFC7951 compliant JSON for protoc-gen-go structs
The JSON representation proto.Messages for protoc-gen-go structs generated using jsonpb.Marshaler, looks different than the corresponding yang/proto definitions. Is there any mechanism to generate a RFC7951 compliant JSON output for these structs ?
Per conversation I had in regards to #110, I have looked at means to convert between GoStructs and Proto based structs and corresponding design pointed there in, but ran into few obstacles like
i. Structs like ygot.*Value types introduce additional nesting, which do not correspond to yang/proto definitions.
ii. Additionally, *Key structs makes it to difficult to match the paths in yangs as it introduces a hierarchy, which do not correspond to yang/proto e.g.
"interfaces" : {
"interface" : [
{ "name": "0/1"
"interface": { ...}
},
{ "name": "0/2"
"interface": { ...}
},
]
}
iii. the schemaPath is not reflected in the generated go structs; I could see this in proto definitions. I can see that the fields are annotated with protobuf & json tags. This will contain only the last token and in case the Yang element contains '-', then it may not match correctly as its annotated as "_". Not sure, whether such can be substituted; if so, it could break when yang tokens actually contain a "_". iv. the way enums are treated..
Faced with such obstacles , I started looking to convert protoc structs to RFC7951, but could not find it.
@robshakir : Just wanted to understand, the code experimental/yangproto in the experimental-yangproto branch of ygot GitHub repository, would generate the protoc structs in different manner for YangLists; i.e., does it avoid *Key struct generation for the YangList types? If not, then will the path recorded at various levels be in-line with that of corresponding YANG definition?
As I skimmed through the code, I could not find any easy mechanism to achieve this; perhaps, I might be overlooking.
One option (brute force? ) I could think of is to move the child attributes of a node to its parent, when the names of both nodes are same. This may work in simple scenarios; But, may fail when dealing with other scenarios. Also, will need to deal with naming differences when the YANG elements are containing '-' (hyphen) so that they are correctly translated.
@robshakir we are also looking for similar feature. Is there any way to generate the openconfig schema compliant json from protoc-gen-go structs.
See #415 for current update regarding this.