add more required fields in models

This commit is contained in:
Sebastien Blot 2024-04-23 13:22:54 +02:00
parent e36d2cb6b8
commit 12ce5e3fc1
No known key found for this signature in database
GPG key ID: DFC2902F40449F6A
2 changed files with 50 additions and 3 deletions

View file

@ -1142,6 +1142,10 @@ definitions:
labels:
$ref: '#/definitions/MetricsLabels'
description: labels of the metric
required:
- name
- value
- unit
MetricsMeta:
title: MetricsMeta
type: object

View file

@ -11,6 +11,7 @@ import (
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
"github.com/go-openapi/validate"
)
// MetricsDetailItem MetricsDetailItem
@ -22,13 +23,16 @@ type MetricsDetailItem struct {
Labels MetricsLabels `json:"labels,omitempty"`
// name of the metric
Name string `json:"name,omitempty"`
// Required: true
Name *string `json:"name"`
// unit of the metric
Unit string `json:"unit,omitempty"`
// Required: true
Unit *string `json:"unit"`
// value of the metric
Value float64 `json:"value,omitempty"`
// Required: true
Value *float64 `json:"value"`
}
// Validate validates this metrics detail item
@ -39,6 +43,18 @@ func (m *MetricsDetailItem) Validate(formats strfmt.Registry) error {
res = append(res, err)
}
if err := m.validateName(formats); err != nil {
res = append(res, err)
}
if err := m.validateUnit(formats); err != nil {
res = append(res, err)
}
if err := m.validateValue(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
@ -64,6 +80,33 @@ func (m *MetricsDetailItem) validateLabels(formats strfmt.Registry) error {
return nil
}
func (m *MetricsDetailItem) validateName(formats strfmt.Registry) error {
if err := validate.Required("name", "body", m.Name); err != nil {
return err
}
return nil
}
func (m *MetricsDetailItem) validateUnit(formats strfmt.Registry) error {
if err := validate.Required("unit", "body", m.Unit); err != nil {
return err
}
return nil
}
func (m *MetricsDetailItem) validateValue(formats strfmt.Registry) error {
if err := validate.Required("value", "body", m.Value); err != nil {
return err
}
return nil
}
// ContextValidate validate this metrics detail item based on the context it is used
func (m *MetricsDetailItem) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
var res []error