diff --git a/api/v2/models/integration.go b/api/v2/models/integration.go index b3f8f2a9a8..46f903826d 100644 --- a/api/v2/models/integration.go +++ b/api/v2/models/integration.go @@ -20,6 +20,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "context" + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" @@ -73,7 +75,6 @@ func (m *Integration) Validate(formats strfmt.Registry) error { } func (m *Integration) validateLastNotifyAttempt(formats strfmt.Registry) error { - if swag.IsZero(m.LastNotifyAttempt) { // not required return nil } @@ -103,6 +104,11 @@ func (m *Integration) validateSendResolved(formats strfmt.Registry) error { return nil } +// ContextValidate validates this integration based on context it is used +func (m *Integration) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + return nil +} + // MarshalBinary interface implementation func (m *Integration) MarshalBinary() ([]byte, error) { if m == nil { diff --git a/api/v2/models/receiver.go b/api/v2/models/receiver.go index bc089bd12f..8c248ea737 100644 --- a/api/v2/models/receiver.go +++ b/api/v2/models/receiver.go @@ -20,8 +20,8 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( - "strconv" "context" + "strconv" "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" @@ -93,6 +93,8 @@ func (m *Receiver) validateIntegrations(formats strfmt.Registry) error { if err := m.Integrations[i].Validate(formats); err != nil { if ve, ok := err.(*errors.Validation); ok { return ve.ValidateName("integrations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("integrations" + "." + strconv.Itoa(i)) } return err } @@ -112,8 +114,42 @@ func (m *Receiver) validateName(formats strfmt.Registry) error { return nil } -// ContextValidate validates this receiver based on context it is used +// ContextValidate validate this receiver based on the context it is used func (m *Receiver) ContextValidate(ctx context.Context, formats strfmt.Registry) error { + var res []error + + if err := m.contextValidateIntegrations(ctx, formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *Receiver) contextValidateIntegrations(ctx context.Context, formats strfmt.Registry) error { + + for i := 0; i < len(m.Integrations); i++ { + + if m.Integrations[i] != nil { + + if swag.IsZero(m.Integrations[i]) { // not required + return nil + } + + if err := m.Integrations[i].ContextValidate(ctx, formats); err != nil { + if ve, ok := err.(*errors.Validation); ok { + return ve.ValidateName("integrations" + "." + strconv.Itoa(i)) + } else if ce, ok := err.(*errors.CompositeError); ok { + return ce.ValidateName("integrations" + "." + strconv.Itoa(i)) + } + return err + } + } + + } + return nil }