[GO] Add assert constraints checks for complex types in the model template (#18654)

* [GO] Add assert constraints checks for complex types in the model template

* [GO] Update samples

* [GO] revert AssertRecurseInterface naming
This commit is contained in:
Aviv Levitski
2024-05-15 11:59:35 +03:00
committed by GitHub
parent a9b1f93d65
commit affb6bc1f7
10 changed files with 139 additions and 0 deletions

View File

@@ -37,5 +37,13 @@ func AssertAnObjectRequired(obj AnObject) error {
// AssertAnObjectConstraints checks if the values respects the defined constraints
func AssertAnObjectConstraints(obj AnObject) error {
if err := AssertTagConstraints(obj.Tag); err != nil {
return err
}
for _, el := range obj.Pet {
if err := AssertPetConstraints(el); err != nil {
return err
}
}
return nil
}

View File

@@ -60,5 +60,17 @@ func AssertPetRequired(obj Pet) error {
// AssertPetConstraints checks if the values respects the defined constraints
func AssertPetConstraints(obj Pet) error {
if obj.Category != nil {
if err := AssertCategoryConstraints(*obj.Category); err != nil {
return err
}
}
if obj.Tags != nil {
for _, el := range *obj.Tags {
if err := AssertTagConstraints(el); err != nil {
return err
}
}
}
return nil
}

View File

@@ -64,5 +64,13 @@ func AssertUserRequired(obj User) error {
// AssertUserConstraints checks if the values respects the defined constraints
func AssertUserConstraints(obj User) error {
if obj.DeepSliceModel != nil {
if err := AssertRecurseInterfaceRequired(*obj.DeepSliceModel, AssertTagConstraints); err != nil {
return err
}
}
if err := AssertRecurseInterfaceRequired(obj.DeepSliceMap, AssertAnObjectConstraints); err != nil {
return err
}
return nil
}