...

Source file src/github.com/prometheus/alertmanager/api/v2/models/gettable_alert.go

Documentation: github.com/prometheus/alertmanager/api/v2/models

     1  // Code generated by go-swagger; DO NOT EDIT.
     2  
     3  // Copyright Prometheus Team
     4  // Licensed under the Apache License, Version 2.0 (the "License");
     5  // you may not use this file except in compliance with the License.
     6  // You may obtain a copy of the License at
     7  //
     8  // http://www.apache.org/licenses/LICENSE-2.0
     9  //
    10  // Unless required by applicable law or agreed to in writing, software
    11  // distributed under the License is distributed on an "AS IS" BASIS,
    12  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  // See the License for the specific language governing permissions and
    14  // limitations under the License.
    15  //
    16  
    17  package models
    18  
    19  // This file was generated by the swagger tool.
    20  // Editing this file might prove futile when you re-run the swagger generate command
    21  
    22  import (
    23  	"context"
    24  	"strconv"
    25  
    26  	"github.com/go-openapi/errors"
    27  	"github.com/go-openapi/strfmt"
    28  	"github.com/go-openapi/swag"
    29  	"github.com/go-openapi/validate"
    30  )
    31  
    32  // GettableAlert gettable alert
    33  //
    34  // swagger:model gettableAlert
    35  type GettableAlert struct {
    36  
    37  	// annotations
    38  	// Required: true
    39  	Annotations LabelSet `json:"annotations"`
    40  
    41  	// ends at
    42  	// Required: true
    43  	// Format: date-time
    44  	EndsAt *strfmt.DateTime `json:"endsAt"`
    45  
    46  	// fingerprint
    47  	// Required: true
    48  	Fingerprint *string `json:"fingerprint"`
    49  
    50  	// receivers
    51  	// Required: true
    52  	Receivers []*Receiver `json:"receivers"`
    53  
    54  	// starts at
    55  	// Required: true
    56  	// Format: date-time
    57  	StartsAt *strfmt.DateTime `json:"startsAt"`
    58  
    59  	// status
    60  	// Required: true
    61  	Status *AlertStatus `json:"status"`
    62  
    63  	// updated at
    64  	// Required: true
    65  	// Format: date-time
    66  	UpdatedAt *strfmt.DateTime `json:"updatedAt"`
    67  
    68  	Alert
    69  }
    70  
    71  // UnmarshalJSON unmarshals this object from a JSON structure
    72  func (m *GettableAlert) UnmarshalJSON(raw []byte) error {
    73  	// AO0
    74  	var dataAO0 struct {
    75  		Annotations LabelSet `json:"annotations"`
    76  
    77  		EndsAt *strfmt.DateTime `json:"endsAt"`
    78  
    79  		Fingerprint *string `json:"fingerprint"`
    80  
    81  		Receivers []*Receiver `json:"receivers"`
    82  
    83  		StartsAt *strfmt.DateTime `json:"startsAt"`
    84  
    85  		Status *AlertStatus `json:"status"`
    86  
    87  		UpdatedAt *strfmt.DateTime `json:"updatedAt"`
    88  	}
    89  	if err := swag.ReadJSON(raw, &dataAO0); err != nil {
    90  		return err
    91  	}
    92  
    93  	m.Annotations = dataAO0.Annotations
    94  
    95  	m.EndsAt = dataAO0.EndsAt
    96  
    97  	m.Fingerprint = dataAO0.Fingerprint
    98  
    99  	m.Receivers = dataAO0.Receivers
   100  
   101  	m.StartsAt = dataAO0.StartsAt
   102  
   103  	m.Status = dataAO0.Status
   104  
   105  	m.UpdatedAt = dataAO0.UpdatedAt
   106  
   107  	// AO1
   108  	var aO1 Alert
   109  	if err := swag.ReadJSON(raw, &aO1); err != nil {
   110  		return err
   111  	}
   112  	m.Alert = aO1
   113  
   114  	return nil
   115  }
   116  
   117  // MarshalJSON marshals this object to a JSON structure
   118  func (m GettableAlert) MarshalJSON() ([]byte, error) {
   119  	_parts := make([][]byte, 0, 2)
   120  
   121  	var dataAO0 struct {
   122  		Annotations LabelSet `json:"annotations"`
   123  
   124  		EndsAt *strfmt.DateTime `json:"endsAt"`
   125  
   126  		Fingerprint *string `json:"fingerprint"`
   127  
   128  		Receivers []*Receiver `json:"receivers"`
   129  
   130  		StartsAt *strfmt.DateTime `json:"startsAt"`
   131  
   132  		Status *AlertStatus `json:"status"`
   133  
   134  		UpdatedAt *strfmt.DateTime `json:"updatedAt"`
   135  	}
   136  
   137  	dataAO0.Annotations = m.Annotations
   138  
   139  	dataAO0.EndsAt = m.EndsAt
   140  
   141  	dataAO0.Fingerprint = m.Fingerprint
   142  
   143  	dataAO0.Receivers = m.Receivers
   144  
   145  	dataAO0.StartsAt = m.StartsAt
   146  
   147  	dataAO0.Status = m.Status
   148  
   149  	dataAO0.UpdatedAt = m.UpdatedAt
   150  
   151  	jsonDataAO0, errAO0 := swag.WriteJSON(dataAO0)
   152  	if errAO0 != nil {
   153  		return nil, errAO0
   154  	}
   155  	_parts = append(_parts, jsonDataAO0)
   156  
   157  	aO1, err := swag.WriteJSON(m.Alert)
   158  	if err != nil {
   159  		return nil, err
   160  	}
   161  	_parts = append(_parts, aO1)
   162  	return swag.ConcatJSON(_parts...), nil
   163  }
   164  
   165  // Validate validates this gettable alert
   166  func (m *GettableAlert) Validate(formats strfmt.Registry) error {
   167  	var res []error
   168  
   169  	if err := m.validateAnnotations(formats); err != nil {
   170  		res = append(res, err)
   171  	}
   172  
   173  	if err := m.validateEndsAt(formats); err != nil {
   174  		res = append(res, err)
   175  	}
   176  
   177  	if err := m.validateFingerprint(formats); err != nil {
   178  		res = append(res, err)
   179  	}
   180  
   181  	if err := m.validateReceivers(formats); err != nil {
   182  		res = append(res, err)
   183  	}
   184  
   185  	if err := m.validateStartsAt(formats); err != nil {
   186  		res = append(res, err)
   187  	}
   188  
   189  	if err := m.validateStatus(formats); err != nil {
   190  		res = append(res, err)
   191  	}
   192  
   193  	if err := m.validateUpdatedAt(formats); err != nil {
   194  		res = append(res, err)
   195  	}
   196  
   197  	// validation for a type composition with Alert
   198  	if err := m.Alert.Validate(formats); err != nil {
   199  		res = append(res, err)
   200  	}
   201  
   202  	if len(res) > 0 {
   203  		return errors.CompositeValidationError(res...)
   204  	}
   205  	return nil
   206  }
   207  
   208  func (m *GettableAlert) validateAnnotations(formats strfmt.Registry) error {
   209  
   210  	if err := validate.Required("annotations", "body", m.Annotations); err != nil {
   211  		return err
   212  	}
   213  
   214  	if m.Annotations != nil {
   215  		if err := m.Annotations.Validate(formats); err != nil {
   216  			if ve, ok := err.(*errors.Validation); ok {
   217  				return ve.ValidateName("annotations")
   218  			} else if ce, ok := err.(*errors.CompositeError); ok {
   219  				return ce.ValidateName("annotations")
   220  			}
   221  			return err
   222  		}
   223  	}
   224  
   225  	return nil
   226  }
   227  
   228  func (m *GettableAlert) validateEndsAt(formats strfmt.Registry) error {
   229  
   230  	if err := validate.Required("endsAt", "body", m.EndsAt); err != nil {
   231  		return err
   232  	}
   233  
   234  	if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
   235  		return err
   236  	}
   237  
   238  	return nil
   239  }
   240  
   241  func (m *GettableAlert) validateFingerprint(formats strfmt.Registry) error {
   242  
   243  	if err := validate.Required("fingerprint", "body", m.Fingerprint); err != nil {
   244  		return err
   245  	}
   246  
   247  	return nil
   248  }
   249  
   250  func (m *GettableAlert) validateReceivers(formats strfmt.Registry) error {
   251  
   252  	if err := validate.Required("receivers", "body", m.Receivers); err != nil {
   253  		return err
   254  	}
   255  
   256  	for i := 0; i < len(m.Receivers); i++ {
   257  		if swag.IsZero(m.Receivers[i]) { // not required
   258  			continue
   259  		}
   260  
   261  		if m.Receivers[i] != nil {
   262  			if err := m.Receivers[i].Validate(formats); err != nil {
   263  				if ve, ok := err.(*errors.Validation); ok {
   264  					return ve.ValidateName("receivers" + "." + strconv.Itoa(i))
   265  				} else if ce, ok := err.(*errors.CompositeError); ok {
   266  					return ce.ValidateName("receivers" + "." + strconv.Itoa(i))
   267  				}
   268  				return err
   269  			}
   270  		}
   271  
   272  	}
   273  
   274  	return nil
   275  }
   276  
   277  func (m *GettableAlert) validateStartsAt(formats strfmt.Registry) error {
   278  
   279  	if err := validate.Required("startsAt", "body", m.StartsAt); err != nil {
   280  		return err
   281  	}
   282  
   283  	if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
   284  		return err
   285  	}
   286  
   287  	return nil
   288  }
   289  
   290  func (m *GettableAlert) validateStatus(formats strfmt.Registry) error {
   291  
   292  	if err := validate.Required("status", "body", m.Status); err != nil {
   293  		return err
   294  	}
   295  
   296  	if m.Status != nil {
   297  		if err := m.Status.Validate(formats); err != nil {
   298  			if ve, ok := err.(*errors.Validation); ok {
   299  				return ve.ValidateName("status")
   300  			} else if ce, ok := err.(*errors.CompositeError); ok {
   301  				return ce.ValidateName("status")
   302  			}
   303  			return err
   304  		}
   305  	}
   306  
   307  	return nil
   308  }
   309  
   310  func (m *GettableAlert) validateUpdatedAt(formats strfmt.Registry) error {
   311  
   312  	if err := validate.Required("updatedAt", "body", m.UpdatedAt); err != nil {
   313  		return err
   314  	}
   315  
   316  	if err := validate.FormatOf("updatedAt", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
   317  		return err
   318  	}
   319  
   320  	return nil
   321  }
   322  
   323  // ContextValidate validate this gettable alert based on the context it is used
   324  func (m *GettableAlert) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
   325  	var res []error
   326  
   327  	if err := m.contextValidateAnnotations(ctx, formats); err != nil {
   328  		res = append(res, err)
   329  	}
   330  
   331  	if err := m.contextValidateReceivers(ctx, formats); err != nil {
   332  		res = append(res, err)
   333  	}
   334  
   335  	if err := m.contextValidateStatus(ctx, formats); err != nil {
   336  		res = append(res, err)
   337  	}
   338  
   339  	// validation for a type composition with Alert
   340  	if err := m.Alert.ContextValidate(ctx, formats); err != nil {
   341  		res = append(res, err)
   342  	}
   343  
   344  	if len(res) > 0 {
   345  		return errors.CompositeValidationError(res...)
   346  	}
   347  	return nil
   348  }
   349  
   350  func (m *GettableAlert) contextValidateAnnotations(ctx context.Context, formats strfmt.Registry) error {
   351  
   352  	if err := m.Annotations.ContextValidate(ctx, formats); err != nil {
   353  		if ve, ok := err.(*errors.Validation); ok {
   354  			return ve.ValidateName("annotations")
   355  		} else if ce, ok := err.(*errors.CompositeError); ok {
   356  			return ce.ValidateName("annotations")
   357  		}
   358  		return err
   359  	}
   360  
   361  	return nil
   362  }
   363  
   364  func (m *GettableAlert) contextValidateReceivers(ctx context.Context, formats strfmt.Registry) error {
   365  
   366  	for i := 0; i < len(m.Receivers); i++ {
   367  
   368  		if m.Receivers[i] != nil {
   369  			if err := m.Receivers[i].ContextValidate(ctx, formats); err != nil {
   370  				if ve, ok := err.(*errors.Validation); ok {
   371  					return ve.ValidateName("receivers" + "." + strconv.Itoa(i))
   372  				} else if ce, ok := err.(*errors.CompositeError); ok {
   373  					return ce.ValidateName("receivers" + "." + strconv.Itoa(i))
   374  				}
   375  				return err
   376  			}
   377  		}
   378  
   379  	}
   380  
   381  	return nil
   382  }
   383  
   384  func (m *GettableAlert) contextValidateStatus(ctx context.Context, formats strfmt.Registry) error {
   385  
   386  	if m.Status != nil {
   387  		if err := m.Status.ContextValidate(ctx, formats); err != nil {
   388  			if ve, ok := err.(*errors.Validation); ok {
   389  				return ve.ValidateName("status")
   390  			} else if ce, ok := err.(*errors.CompositeError); ok {
   391  				return ce.ValidateName("status")
   392  			}
   393  			return err
   394  		}
   395  	}
   396  
   397  	return nil
   398  }
   399  
   400  // MarshalBinary interface implementation
   401  func (m *GettableAlert) MarshalBinary() ([]byte, error) {
   402  	if m == nil {
   403  		return nil, nil
   404  	}
   405  	return swag.WriteJSON(m)
   406  }
   407  
   408  // UnmarshalBinary interface implementation
   409  func (m *GettableAlert) UnmarshalBinary(b []byte) error {
   410  	var res GettableAlert
   411  	if err := swag.ReadJSON(b, &res); err != nil {
   412  		return err
   413  	}
   414  	*m = res
   415  	return nil
   416  }
   417  

View as plain text