diff --git a/power/models/network_create.go b/power/models/network_create.go index 2ce0a90a..d0c06040 100644 --- a/power/models/network_create.go +++ b/power/models/network_create.go @@ -46,6 +46,7 @@ type NetworkCreate struct { Mtu *int64 `json:"mtu,omitempty"` // Network Name + // Max Length: 255 Name string `json:"name,omitempty"` // Type of Network - 'vlan' (private network) 'pub-vlan' (public network) 'dhcp-vlan' (for satellite locations only) @@ -83,6 +84,10 @@ func (m *NetworkCreate) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateName(formats); err != nil { + res = append(res, err) + } + if err := m.validateType(formats); err != nil { res = append(res, err) } @@ -152,6 +157,18 @@ func (m *NetworkCreate) validateMtu(formats strfmt.Registry) error { return nil } +func (m *NetworkCreate) validateName(formats strfmt.Registry) error { + if swag.IsZero(m.Name) { // not required + return nil + } + + if err := validate.MaxLength("name", "body", m.Name, 255); err != nil { + return err + } + + return nil +} + var networkCreateTypeTypePropEnum []interface{} func init() { diff --git a/power/models/network_update.go b/power/models/network_update.go index b8924c7f..642b474b 100644 --- a/power/models/network_update.go +++ b/power/models/network_update.go @@ -12,6 +12,7 @@ import ( "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // NetworkUpdate network update @@ -29,6 +30,7 @@ type NetworkUpdate struct { IPAddressRanges []*IPAddressRange `json:"ipAddressRanges"` // Replaces the current Network Name + // Max Length: 255 Name *string `json:"name,omitempty"` } @@ -40,6 +42,10 @@ func (m *NetworkUpdate) Validate(formats strfmt.Registry) error { res = append(res, err) } + if err := m.validateName(formats); err != nil { + res = append(res, err) + } + if len(res) > 0 { return errors.CompositeValidationError(res...) } @@ -72,6 +78,18 @@ func (m *NetworkUpdate) validateIPAddressRanges(formats strfmt.Registry) error { return nil } +func (m *NetworkUpdate) validateName(formats strfmt.Registry) error { + if swag.IsZero(m.Name) { // not required + return nil + } + + if err := validate.MaxLength("name", "body", *m.Name, 255); err != nil { + return err + } + + return nil +} + // ContextValidate validate this network update based on the context it is used func (m *NetworkUpdate) ContextValidate(ctx context.Context, formats strfmt.Registry) error { var res []error