Skip to content

Commit

Permalink
fix(api): add int64 annotations in swaggo (#901)
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf authored Aug 23, 2023
1 parent 0e6fb14 commit 4e9751c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion api/dto/event_history_item.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dto
import "net/http"

type ContactEventItem struct {
TimeStamp int64 `json:"timestamp"`
TimeStamp int64 `json:"timestamp" format:"int64"`
Metric string `json:"metric"`
State string `json:"state"`
OldState string `json:"old_state"`
Expand Down
6 changes: 3 additions & 3 deletions api/dto/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type EventsList struct {
Page int64 `json:"page" example:"0"`
Size int64 `json:"size" example:"100"`
Total int64 `json:"total" example:"10"`
Page int64 `json:"page" example:"0" format:"int64"`
Size int64 `json:"size" example:"100" format:"int64"`
Total int64 `json:"total" example:"10" format:"int64"`
List []moira.NotificationEvent `json:"list"`
}

Expand Down
4 changes: 2 additions & 2 deletions api/dto/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type NotificationsList struct {
Total int64 `json:"total" example:"0"`
Total int64 `json:"total" example:"0" format:"int64"`
List []*moira.ScheduledNotification `json:"list"`
}

Expand All @@ -17,7 +17,7 @@ func (*NotificationsList) Render(w http.ResponseWriter, r *http.Request) error {
}

type NotificationDeleteResponse struct {
Result int64 `json:"result" example:"0"`
Result int64 `json:"result" example:"0" format:"int64"`
}

func (*NotificationDeleteResponse) Render(w http.ResponseWriter, r *http.Request) error {
Expand Down
14 changes: 7 additions & 7 deletions api/dto/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ var targetNameRegex = regexp.MustCompile("t(\\d+)")
var asteriskPattern = "*"

type TriggersList struct {
Page *int64 `json:"page,omitempty"`
Size *int64 `json:"size,omitempty"`
Total *int64 `json:"total,omitempty"`
Page *int64 `json:"page,omitempty" format:"int64"`
Size *int64 `json:"size,omitempty" format:"int64"`
Total *int64 `json:"total,omitempty" format:"int64"`
Pager *string `json:"pager,omitempty"`
List []moira.TriggerCheck `json:"list"`
}
Expand All @@ -36,7 +36,7 @@ func (*TriggersList) Render(http.ResponseWriter, *http.Request) error {

type Trigger struct {
TriggerModel
Throttling int64 `json:"throttling" example:"0"`
Throttling int64 `json:"throttling" example:"0" format:"int64"`
}

// TriggerModel is moira.Trigger api representation
Expand All @@ -60,7 +60,7 @@ type TriggerModel struct {
// When there are no metrics for trigger, Moira will switch metric to TTLState state after TTL seconds
TTLState *moira.TTLState `json:"ttl_state,omitempty" example:"NODATA"`
// When there are no metrics for trigger, Moira will switch metric to TTLState state after TTL seconds
TTL int64 `json:"ttl,omitempty" example:"600"`
TTL int64 `json:"ttl,omitempty" example:"600" format:"int64"`
// Determines when Moira should monitor trigger
Schedule *moira.ScheduleData `json:"sched,omitempty"`
// Used if you need more complex logic than provided by WARN/ERROR values
Expand Down Expand Up @@ -380,7 +380,7 @@ func (*MetricsMaintenance) Bind(*http.Request) error {
}

type TriggerMaintenance struct {
Trigger *int64 `json:"trigger" example:"1594225165"`
Trigger *int64 `json:"trigger" example:"1594225165" format:"int64"`
Metrics map[string]int64 `json:"metrics"`
}

Expand All @@ -389,7 +389,7 @@ func (*TriggerMaintenance) Bind(*http.Request) error {
}

type ThrottlingResponse struct {
Throttling int64 `json:"throttling" example:"0"`
Throttling int64 `json:"throttling" example:"0" format:"int64"`
}

func (*ThrottlingResponse) Render(http.ResponseWriter, *http.Request) error {
Expand Down
4 changes: 2 additions & 2 deletions api/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ func NewHandler(db moira.Database, log moira.Logger, index moira.Searcher, confi
// @title Moira Alert
// @version master
// @description This is an API description for [Moira Alert API](https://moira.readthedocs.io/en/latest/overview.html)
// @description Check us out on [Github](https://github.com/moira-alert) or look up our [guide on getting started with Moira](https://moira.readthedocs.io)
// @contact.name Contact Moira Team
// @description Check us out on [Github](https://github.com/moira-alert) or look up our [guide](https://moira.readthedocs.io) on getting started with Moira
// @contact.name Moira Team
// @contact.email [email protected]
// @license.name MIT
// @BasePath /api
Expand Down
46 changes: 23 additions & 23 deletions datatypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const (
// NotificationEvent represents trigger state changes event
type NotificationEvent struct {
IsTriggerEvent bool `json:"trigger_event,omitempty" example:"true"`
Timestamp int64 `json:"timestamp" example:"1590741878"`
Timestamp int64 `json:"timestamp" example:"1590741878" format:"int64"`
Metric string `json:"metric" example:"carbon.agents.*.metricsReceived"`
Value *float64 `json:"value,omitempty" example:"70"`
Values map[string]float64 `json:"values,omitempty"`
Expand All @@ -59,7 +59,7 @@ type NotificationEvent struct {
// NotificationEventHistoryItem is in use to store notifications history of channel
// (see database/redis/contact_notifications_history.go
type NotificationEventHistoryItem struct {
TimeStamp int64 `json:"timestamp"`
TimeStamp int64 `json:"timestamp" format:"int64"`
Metric string `json:"metric"`
State State `json:"state"`
OldState State `json:"old_state"`
Expand All @@ -70,7 +70,7 @@ type NotificationEventHistoryItem struct {
// EventInfo - a base for creating messages.
type EventInfo struct {
Maintenance *MaintenanceInfo `json:"maintenance,omitempty"`
Interval *int64 `json:"interval,omitempty" example:"0"`
Interval *int64 `json:"interval,omitempty" example:"0" format:"int64"`
}

// CreateMessage - creates a message based on EventInfo.
Expand Down Expand Up @@ -216,9 +216,9 @@ type PlottingData struct {
// ScheduleData represents subscription schedule
type ScheduleData struct {
Days []ScheduleDataDay `json:"days"`
TimezoneOffset int64 `json:"tzOffset" example:"-60"`
StartOffset int64 `json:"startOffset" example:"0"`
EndOffset int64 `json:"endOffset" example:"1439"`
TimezoneOffset int64 `json:"tzOffset" example:"-60" format:"int64"`
StartOffset int64 `json:"startOffset" example:"0" format:"int64"`
EndOffset int64 `json:"endOffset" example:"1439" format:"int64"`
}

// ScheduleDataDay represents week day of schedule
Expand All @@ -235,7 +235,7 @@ type ScheduledNotification struct {
Plotting PlottingData `json:"plotting"`
Throttled bool `json:"throttled" example:"false"`
SendFail int `json:"send_fail" example:"0"`
Timestamp int64 `json:"timestamp" example:"1594471927"`
Timestamp int64 `json:"timestamp" example:"1594471927" format:"int64"`
}

// MatchedMetric represents parsed and matched metric data
Expand All @@ -250,8 +250,8 @@ type MatchedMetric struct {

// MetricValue represents metric data
type MetricValue struct {
RetentionTimestamp int64 `json:"step,omitempty"`
Timestamp int64 `json:"ts"`
RetentionTimestamp int64 `json:"step,omitempty" format:"int64"`
Timestamp int64 `json:"ts" format:"int64"`
Value float64 `json:"value"`
}

Expand All @@ -275,24 +275,24 @@ type Trigger struct {
TriggerType string `json:"trigger_type" example:"rising"`
Tags []string `json:"tags" example:"server,disk"`
TTLState *TTLState `json:"ttl_state,omitempty" example:"NODATA"`
TTL int64 `json:"ttl,omitempty" example:"600"`
TTL int64 `json:"ttl,omitempty" example:"600" format:"int64"`
Schedule *ScheduleData `json:"sched,omitempty"`
Expression *string `json:"expression,omitempty" example:""`
PythonExpression *string `json:"python_expression,omitempty"`
Patterns []string `json:"patterns" example:""`
IsRemote bool `json:"is_remote" example:"false"`
MuteNewMetrics bool `json:"mute_new_metrics" example:"false"`
AloneMetrics map[string]bool `json:"alone_metrics" example:"t1:true"`
CreatedAt *int64 `json:"created_at"`
UpdatedAt *int64 `json:"updated_at"`
CreatedAt *int64 `json:"created_at" format:"int64"`
UpdatedAt *int64 `json:"updated_at" format:"int64"`
CreatedBy string `json:"created_by"`
UpdatedBy string `json:"updated_by"`
}

// TriggerCheck represents trigger data with last check data and check timestamp
type TriggerCheck struct {
Trigger
Throttling int64 `json:"throttling" example:"0"`
Throttling int64 `json:"throttling" example:"0" format:"int64"`
LastCheck CheckData `json:"last_check"`
Highlights map[string]string `json:"highlights"`
}
Expand All @@ -310,13 +310,13 @@ type CheckData struct {
// check and targets that fetched this metric
// {"t1": "metric.name.1", "t2": "metric.name.2"}
MetricsToTargetRelation map[string]string `json:"metrics_to_target_relation" example:"t1:metric.name.1,t2:metric.name.2"`
Score int64 `json:"score" example:"100"`
Score int64 `json:"score" example:"100" format:"int64"`
State State `json:"state" example:"OK"`
Maintenance int64 `json:"maintenance,omitempty" example:"0"`
Maintenance int64 `json:"maintenance,omitempty" example:"0" format:"int64"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
Timestamp int64 `json:"timestamp,omitempty" example:"1590741916"`
EventTimestamp int64 `json:"event_timestamp,omitempty" example:"1590741878"`
LastSuccessfulCheckTimestamp int64 `json:"last_successful_check_timestamp" example:"1590741916"`
Timestamp int64 `json:"timestamp,omitempty" example:"1590741916" format:"int64"`
EventTimestamp int64 `json:"event_timestamp,omitempty" example:"1590741878" format:"int64"`
LastSuccessfulCheckTimestamp int64 `json:"last_successful_check_timestamp" example:"1590741916" format:"int64"`
Suppressed bool `json:"suppressed,omitempty" example:"true"`
SuppressedState State `json:"suppressed_state,omitempty"`
Message string `json:"msg,omitempty"`
Expand All @@ -334,14 +334,14 @@ func (checkData *CheckData) RemoveMetricsToTargetRelation() {

// MetricState represents metric state data for given timestamp
type MetricState struct {
EventTimestamp int64 `json:"event_timestamp" example:"1590741878"`
EventTimestamp int64 `json:"event_timestamp" example:"1590741878" format:"int64"`
State State `json:"state" example:"OK"`
Suppressed bool `json:"suppressed" example:"false"`
SuppressedState State `json:"suppressed_state,omitempty"`
Timestamp int64 `json:"timestamp" example:"1590741878"`
Timestamp int64 `json:"timestamp" example:"1590741878" format:"int64"`
Value *float64 `json:"value,omitempty" example:"70"`
Values map[string]float64 `json:"values,omitempty"`
Maintenance int64 `json:"maintenance,omitempty" example:"0"`
Maintenance int64 `json:"maintenance,omitempty" example:"0" format:"int64"`
MaintenanceInfo MaintenanceInfo `json:"maintenance_info"`
// AloneMetrics map[string]string `json:"alone_metrics"` // represents a relation between name of alone metrics and their targets
}
Expand All @@ -360,9 +360,9 @@ func (metricState *MetricState) GetMaintenance() (MaintenanceInfo, int64) {
// MaintenanceInfo represents user and time set/unset maintenance
type MaintenanceInfo struct {
StartUser *string `json:"setup_user"`
StartTime *int64 `json:"setup_time" example:"0"`
StartTime *int64 `json:"setup_time" example:"0" format:"int64"`
StopUser *string `json:"remove_user"`
StopTime *int64 `json:"remove_time" example:"0"`
StopTime *int64 `json:"remove_time" example:"0" format:"int64"`
}

// Set maintanace start and stop users and times
Expand Down

0 comments on commit 4e9751c

Please sign in to comment.