api: Implement OpenAPI generated Alertmanager API V2
The current Alertmanager API v1 is undocumented and written by hand.
This patch introduces a new Alertmanager API - v2. The API is fully
generated via an OpenAPI 2.0 [1] specification (see
`api/v2/openapi.yaml`) with the exception of the http handlers itself.
Pros:
- Generated server code
- Ability to generate clients in all major languages
(Go, Java, JS, Python, Ruby, Haskell, *elm* [3] ...)
- Strict contract (OpenAPI spec) between server and clients.
- Instant feedback on frontend-breaking changes, due to strictly
typed frontend language elm.
- Generated documentation (See Alertmanager online Swagger UI [4])
Cons:
- Dependency on open api ecosystem including go-swagger [2]
In addition this patch includes the following changes.
- README.md: Add API section
- test: Duplicate acceptance test to API v1 & API v2 version
The Alertmanager acceptance test framework has a decent test coverage
on the Alertmanager API. Introducing the Alertmanager API v2 does not go
hand in hand with deprecating API v1. They should live alongside each
other for a couple of minor Alertmanager versions.
Instead of porting the acceptance test framework to use the new API v2,
this patch duplicates the acceptance tests, one using the API v1, the
other API v2.
Once API v1 is removed we can simply remove `test/with_api_v1` and bring
`test/with_api_v2` to `test/`.
[1]
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
[2] https://github.com/go-swagger/go-swagger/
[3] https://github.com/ahultgren/swagger-elm
[4]
http://petstore.swagger.io/?url=https://raw.githubusercontent.com/mxinden/alertmanager/apiv2/api/v2/openapi.yaml
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-04-26 06:12:49 +00:00
|
|
|
// Code generated by go-swagger; DO NOT EDIT.
|
|
|
|
|
|
|
|
package models
|
|
|
|
|
|
|
|
// This file was generated by the swagger tool.
|
|
|
|
// Editing this file might prove futile when you re-run the swagger generate command
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
strfmt "github.com/go-openapi/strfmt"
|
|
|
|
|
|
|
|
"github.com/go-openapi/errors"
|
|
|
|
"github.com/go-openapi/swag"
|
|
|
|
"github.com/go-openapi/validate"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Alert alert
|
|
|
|
// swagger:model alert
|
|
|
|
type Alert struct {
|
|
|
|
|
|
|
|
// annotations
|
|
|
|
Annotations LabelSet `json:"annotations,omitempty"`
|
|
|
|
|
|
|
|
// ends at
|
|
|
|
// Format: date-time
|
|
|
|
EndsAt strfmt.DateTime `json:"endsAt,omitempty"`
|
|
|
|
|
|
|
|
// fingerprint
|
|
|
|
Fingerprint string `json:"fingerprint,omitempty"`
|
|
|
|
|
|
|
|
// generator URL
|
|
|
|
// Format: uri
|
|
|
|
GeneratorURL strfmt.URI `json:"generatorURL,omitempty"`
|
|
|
|
|
|
|
|
// labels
|
2018-11-08 17:46:04 +00:00
|
|
|
// Required: true
|
|
|
|
Labels LabelSet `json:"labels"`
|
api: Implement OpenAPI generated Alertmanager API V2
The current Alertmanager API v1 is undocumented and written by hand.
This patch introduces a new Alertmanager API - v2. The API is fully
generated via an OpenAPI 2.0 [1] specification (see
`api/v2/openapi.yaml`) with the exception of the http handlers itself.
Pros:
- Generated server code
- Ability to generate clients in all major languages
(Go, Java, JS, Python, Ruby, Haskell, *elm* [3] ...)
- Strict contract (OpenAPI spec) between server and clients.
- Instant feedback on frontend-breaking changes, due to strictly
typed frontend language elm.
- Generated documentation (See Alertmanager online Swagger UI [4])
Cons:
- Dependency on open api ecosystem including go-swagger [2]
In addition this patch includes the following changes.
- README.md: Add API section
- test: Duplicate acceptance test to API v1 & API v2 version
The Alertmanager acceptance test framework has a decent test coverage
on the Alertmanager API. Introducing the Alertmanager API v2 does not go
hand in hand with deprecating API v1. They should live alongside each
other for a couple of minor Alertmanager versions.
Instead of porting the acceptance test framework to use the new API v2,
this patch duplicates the acceptance tests, one using the API v1, the
other API v2.
Once API v1 is removed we can simply remove `test/with_api_v1` and bring
`test/with_api_v2` to `test/`.
[1]
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
[2] https://github.com/go-swagger/go-swagger/
[3] https://github.com/ahultgren/swagger-elm
[4]
http://petstore.swagger.io/?url=https://raw.githubusercontent.com/mxinden/alertmanager/apiv2/api/v2/openapi.yaml
Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
2018-04-26 06:12:49 +00:00
|
|
|
|
|
|
|
// receivers
|
|
|
|
Receivers []*Receiver `json:"receivers"`
|
|
|
|
|
|
|
|
// starts at
|
|
|
|
// Format: date-time
|
|
|
|
StartsAt strfmt.DateTime `json:"startsAt,omitempty"`
|
|
|
|
|
|
|
|
// status
|
|
|
|
Status *AlertStatus `json:"status,omitempty"`
|
|
|
|
|
|
|
|
// updated at
|
|
|
|
// Format: date-time
|
|
|
|
UpdatedAt strfmt.DateTime `json:"updatedAt,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Validate validates this alert
|
|
|
|
func (m *Alert) Validate(formats strfmt.Registry) error {
|
|
|
|
var res []error
|
|
|
|
|
|
|
|
if err := m.validateAnnotations(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateEndsAt(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateGeneratorURL(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateLabels(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateReceivers(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateStartsAt(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateStatus(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.validateUpdatedAt(formats); err != nil {
|
|
|
|
res = append(res, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(res) > 0 {
|
|
|
|
return errors.CompositeValidationError(res...)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateAnnotations(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.Annotations) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := m.Annotations.Validate(formats); err != nil {
|
|
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
|
|
return ve.ValidateName("annotations")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateEndsAt(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.EndsAt) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validate.FormatOf("endsAt", "body", "date-time", m.EndsAt.String(), formats); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateGeneratorURL(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.GeneratorURL) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validate.FormatOf("generatorURL", "body", "uri", m.GeneratorURL.String(), formats); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateLabels(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if err := m.Labels.Validate(formats); err != nil {
|
|
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
|
|
return ve.ValidateName("labels")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateReceivers(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.Receivers) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := 0; i < len(m.Receivers); i++ {
|
|
|
|
if swag.IsZero(m.Receivers[i]) { // not required
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Receivers[i] != nil {
|
|
|
|
if err := m.Receivers[i].Validate(formats); err != nil {
|
|
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
|
|
return ve.ValidateName("receivers" + "." + strconv.Itoa(i))
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateStartsAt(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.StartsAt) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validate.FormatOf("startsAt", "body", "date-time", m.StartsAt.String(), formats); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateStatus(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.Status) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.Status != nil {
|
|
|
|
if err := m.Status.Validate(formats); err != nil {
|
|
|
|
if ve, ok := err.(*errors.Validation); ok {
|
|
|
|
return ve.ValidateName("status")
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *Alert) validateUpdatedAt(formats strfmt.Registry) error {
|
|
|
|
|
|
|
|
if swag.IsZero(m.UpdatedAt) { // not required
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := validate.FormatOf("updatedAt", "body", "date-time", m.UpdatedAt.String(), formats); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalBinary interface implementation
|
|
|
|
func (m *Alert) MarshalBinary() ([]byte, error) {
|
|
|
|
if m == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return swag.WriteJSON(m)
|
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalBinary interface implementation
|
|
|
|
func (m *Alert) UnmarshalBinary(b []byte) error {
|
|
|
|
var res Alert
|
|
|
|
if err := swag.ReadJSON(b, &res); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
*m = res
|
|
|
|
return nil
|
|
|
|
}
|