ygot icon indicating copy to clipboard operation
ygot copied to clipboard

YANG statement "must" is not validated by GO structs Validate function

Open oleg8000 opened this issue 1 year ago • 1 comments

YANG model:

module my-module {
	namespace "my-module";
	prefix my;

	container configuration {
		container values {
			leaf val {
				type int32;
			}
			must '. >= (../res-values/minimum) and . <= (../res-values/maximum)';
		}

		container res-values {
			leaf minimum {
				type int32;
			}
			leaf maximum {
				type int32;
			}
		}
	}
}

Code:

func main() {
	v := int32(50)
	minimum := int32(0)
	maximum := int32(10)
	resValues := schema.MyModule_Configuration_ResValues{Minimum: &minimum, Maximum: &maximum}
	values := schema.MyModule_Configuration_Values{Val: &v}
	config := schema.MyModule_Configuration{ResValues: &resValues, Values: &values}
	err := config.Validate()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Validation successful")
	}
}

Output is "Validation successful".

ygot version: github.com/openconfig/ygot v0.29.20

Thank you for attention!

oleg8000 avatar Jan 14 '25 20:01 oleg8000

This is correct, we do not currently validate any must statement. If you'd like to make a contribution here, that'd be very welcome. We can also help review a design proposal.

robshakir avatar Mar 07 '25 05:03 robshakir