Aviv Levitski affb6bc1f7
[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
2024-05-15 16:59:35 +08:00

77 lines
1.6 KiB
Go

// Code generated by OpenAPI Generator (https://openapi-generator.tech); DO NOT EDIT.
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* API version: 1.0.0
*/
package petstoreserver
// Pet - A pet for sale in the pet store
type Pet struct {
Id int64 `json:"id,omitempty"`
Category *Category `json:"category,omitempty"`
Name string `json:"name"`
PhotoUrls *[]string `json:"photoUrls"`
Tags *[]Tag `json:"tags,omitempty"`
// pet status in the store
// Deprecated
Status string `json:"status,omitempty"`
}
// AssertPetRequired checks if the required fields are not zero-ed
func AssertPetRequired(obj Pet) error {
elements := map[string]interface{}{
"name": obj.Name,
"photoUrls": obj.PhotoUrls,
}
for name, el := range elements {
if isZero := IsZeroValue(el); isZero {
return &RequiredError{Field: name}
}
}
if obj.Category != nil {
if err := AssertCategoryRequired(*obj.Category); err != nil {
return err
}
}
if obj.Tags != nil {
for _, el := range *obj.Tags {
if err := AssertTagRequired(el); err != nil {
return err
}
}
}
return nil
}
// 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
}