diff --git a/go/models/database_compute_settings_request.go b/go/models/database_compute_settings_request.go index 35d2f3f3..8ff462cc 100644 --- a/go/models/database_compute_settings_request.go +++ b/go/models/database_compute_settings_request.go @@ -6,8 +6,10 @@ package models // Editing this file might prove futile when you re-run the swagger generate command import ( + "github.com/go-openapi/errors" "github.com/go-openapi/strfmt" "github.com/go-openapi/swag" + "github.com/go-openapi/validate" ) // DatabaseComputeSettingsRequest Request body for setting compute settings. All fields are optional; only provided fields are updated. @@ -16,17 +18,86 @@ import ( type DatabaseComputeSettingsRequest struct { // Maximum compute units (0.25 to 16.0). Must be greater than or equal to min_cu. max_cu - min_cu must not exceed 8.0. - MaxCu float64 `json:"max_cu,omitempty"` + // Maximum: 16 + // Minimum: 0.25 + MaxCu *float64 `json:"max_cu,omitempty"` // Minimum compute units (0.25 to 16.0). Must be less than or equal to max_cu. - MinCu float64 `json:"min_cu,omitempty"` + // Maximum: 16 + // Minimum: 0.25 + MinCu *float64 `json:"min_cu,omitempty"` // Seconds of inactivity before the compute endpoint is suspended. Use -1 for always on, or a non-negative value. - SleepTimeoutSeconds int64 `json:"sleep_timeout_seconds,omitempty"` + // Minimum: -1 + SleepTimeoutSeconds *int64 `json:"sleep_timeout_seconds,omitempty"` } // Validate validates this database compute settings request func (m *DatabaseComputeSettingsRequest) Validate(formats strfmt.Registry) error { + var res []error + + if err := m.validateMaxCu(formats); err != nil { + res = append(res, err) + } + + if err := m.validateMinCu(formats); err != nil { + res = append(res, err) + } + + if err := m.validateSleepTimeoutSeconds(formats); err != nil { + res = append(res, err) + } + + if len(res) > 0 { + return errors.CompositeValidationError(res...) + } + return nil +} + +func (m *DatabaseComputeSettingsRequest) validateMaxCu(formats strfmt.Registry) error { + + if swag.IsZero(m.MaxCu) { // not required + return nil + } + + if err := validate.Minimum("max_cu", "body", float64(*m.MaxCu), 0.25, false); err != nil { + return err + } + + if err := validate.Maximum("max_cu", "body", float64(*m.MaxCu), 16, false); err != nil { + return err + } + + return nil +} + +func (m *DatabaseComputeSettingsRequest) validateMinCu(formats strfmt.Registry) error { + + if swag.IsZero(m.MinCu) { // not required + return nil + } + + if err := validate.Minimum("min_cu", "body", float64(*m.MinCu), 0.25, false); err != nil { + return err + } + + if err := validate.Maximum("min_cu", "body", float64(*m.MinCu), 16, false); err != nil { + return err + } + + return nil +} + +func (m *DatabaseComputeSettingsRequest) validateSleepTimeoutSeconds(formats strfmt.Registry) error { + + if swag.IsZero(m.SleepTimeoutSeconds) { // not required + return nil + } + + if err := validate.MinimumInt("sleep_timeout_seconds", "body", int64(*m.SleepTimeoutSeconds), -1, false); err != nil { + return err + } + return nil } diff --git a/go/models/database_compute_settings_request_validate.go b/go/models/database_compute_settings_request_validate.go new file mode 100644 index 00000000..f160bd98 --- /dev/null +++ b/go/models/database_compute_settings_request_validate.go @@ -0,0 +1,26 @@ +package models + +import "fmt" + +// ValidateCrossFieldConstraints checks cross-field invariants that cannot be +// expressed in the OpenAPI 2.0 schema and are therefore not covered by the +// generated Validate method. Callers should invoke this after Validate. +// +// Rules enforced: +// - When both min_cu and max_cu are provided, max_cu >= min_cu. +// - When both min_cu and max_cu are provided, max_cu - min_cu <= 8.0. +func (m *DatabaseComputeSettingsRequest) ValidateCrossFieldConstraints() error { + if m.MinCu == nil || m.MaxCu == nil { + return nil + } + + if *m.MaxCu < *m.MinCu { + return fmt.Errorf("max_cu (%g) must be greater than or equal to min_cu (%g)", *m.MaxCu, *m.MinCu) + } + + if *m.MaxCu-*m.MinCu > 8.0 { + return fmt.Errorf("max_cu - min_cu must not exceed 8.0 (got %g)", *m.MaxCu-*m.MinCu) + } + + return nil +} diff --git a/swagger.yml b/swagger.yml index c36eb86a..ac8768a9 100644 --- a/swagger.yml +++ b/swagger.yml @@ -3908,12 +3908,18 @@ definitions: min_cu: type: number format: double + minimum: 0.25 + maximum: 16 + x-nullable: true description: >- Minimum compute units (0.25 to 16.0). Must be less than or equal to max_cu. max_cu: type: number format: double + minimum: 0.25 + maximum: 16 + x-nullable: true description: >- Maximum compute units (0.25 to 16.0). Must be greater than or equal to min_cu. @@ -3921,6 +3927,8 @@ definitions: sleep_timeout_seconds: type: integer format: int64 + minimum: -1 + x-nullable: true description: >- Seconds of inactivity before the compute endpoint is suspended. Use -1 for always on, or a non-negative value.