openconfig / ygot

A YANG-centric Go toolkit - Go/Protobuf Code Generation; Validation; Marshaling/Unmarshaling
Apache License 2.0
286 stars 107 forks source link

func EmitJSON is broken due to backwards compatability issue #721

Open CmeRR4 opened 2 years ago

CmeRR4 commented 2 years ago

Hi, I got a new version of YGOT and now EmitJSON functionality is broken. You changed Validate() to ΛValidate(). So now if I have 100s of these Validate calls I have to modify all of them? And not just modify but have both ΛValidate and Validate to support old version and the newest of YGOT?

In fact I do not even use this Validate() API at all, I do not need to, the JSON input and output is getting validated outside of YGOT library in my case, but the you forcing to use this API.

There is skipValidation flag that is useless if there is no ΛValidate() defined.

I want to propose to use this flag to ignore this Validate APIs completely. If this skipValidationis set then skip any checking for ΛValidate or Validate existence at all.

`
func EmitJSON(gs GoStruct, opts *EmitJSONConfig) (string, error) {

.... if !skipValidation { s, ok := gs.(validatedGoStruct) if !ok { return "", fmt.Errorf("input GoStruct does not have ΛValidate() method") } if err := s.ΛValidate(vopts...); err != nil { return "", fmt.Errorf("validation err: %v", err) } } `

Please do not just break API that are working. Now I need to fix hundreds of lines of code for now reason and add thousands of line of dead code to make one api call happy

Thanks

wenovus commented 2 years ago

Hi, so my guess is you've upgraded your ygot processing code to a later version than the generated ygot code. ygot versions v0.20.0 and later should be generating both Validate() and ΛValidate() by default, and should therefore not experience this problem. We've explicitly avoided considering compatibility between older generated ygot structs and a newer ygot for marshalling/unmarshalling.

If re-generating the structs can't fix your issue, please let me know more details (e.g. the versions of the generated ygot structs and ygot itself).