forked from loafle/openapi-generator-original
[go-server] Feat: add required assertions to models (#10068)
* 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
This commit is contained in:
@@ -29,3 +29,20 @@ type User struct {
|
||||
// User Status
|
||||
UserStatus int32 `json:"userStatus,omitempty"`
|
||||
}
|
||||
|
||||
// AssertUserRequired checks if the required fields are not zero-ed
|
||||
func AssertUserRequired(obj User) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AssertRecurseUserRequired recursively checks if required fields are not zero-ed in a nested slice.
|
||||
// Accepts only nested slice of User (e.g. [][]User), otherwise ErrTypeAssertionError is thrown.
|
||||
func AssertRecurseUserRequired(objSlice interface{}) error {
|
||||
return AssertRecurseInterfaceRequired(objSlice, func(obj interface{}) error {
|
||||
aUser, ok := obj.(User)
|
||||
if !ok {
|
||||
return ErrTypeAssertionError
|
||||
}
|
||||
return AssertUserRequired(aUser)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user