forked from loafle/openapi-generator-original
[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:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user