forked from loafle/openapi-generator-original
* Add RequiredError * Add IsZeroValue helper * Add AssertRequired method to all models * Add AssertRequired call for body param * Regenerate files * Add DisallowUnknownFields * Regenerate samples * Use hasRequired in model to remove unnecessary code * Revert disallowUnknownFields * Use isAdditionalPropertiesTrue for disallowing unknown fields * Updated samples * Fix indent * Add require checks for nested slices * Add new tests * Regenerate samples * Regenerate samples after merging
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
/*
|
|
* 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
|
|
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
|
|
*/
|
|
|
|
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 err := AssertCategoryRequired(obj.Category); err != nil {
|
|
return err
|
|
}
|
|
for _, el := range obj.Tags {
|
|
if err := AssertTagRequired(el); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// AssertRecursePetRequired recursively checks if required fields are not zero-ed in a nested slice.
|
|
// Accepts only nested slice of Pet (e.g. [][]Pet), otherwise ErrTypeAssertionError is thrown.
|
|
func AssertRecursePetRequired(objSlice interface{}) error {
|
|
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
|
|
aPet, ok := obj.(Pet)
|
|
if !ok {
|
|
return ErrTypeAssertionError
|
|
}
|
|
return AssertPetRequired(aPet)
|
|
})
|
|
}
|