diff --git a/Makefile b/Makefile index 86bb368b062..8ec0e88b4ea 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ GO_PKG_FILES = $(shell find $(PKG_DIR) -name *.go -print) spec.json: $(GO_PKG_FILES) - swagger generate spec -m -w $(PKG_DIR) -o $@ + swagger generate spec -m -w $(PKG_DIR) | jq 'del(.definitions.ApiAlertingConfig.properties.route)' > $@ + .PHONY: openapi openapi: spec.json diff --git a/README.md b/README.md index f1a5f567006..b47529aff8c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [view api](https://grafana.github.io/alerting-api/) -This repo aims to define the unified alerting API as code. It generates OpenAPI definitions from go structs, initially pulled from +This repo aims to define the unified alerting API as code. It generates OpenAPI definitions from go structs ## Running @@ -11,3 +11,4 @@ This repo aims to define the unified alerting API as code. It generates OpenAPI ## Requires - [go-swagger](https://github.com/go-swagger/go-swagger) + - [jq](https://stedolan.github.io/jq/) diff --git a/pkg/api/alertmanager.go b/pkg/api/alertmanager.go index 89f2cf63e4c..3803f85812b 100644 --- a/pkg/api/alertmanager.go +++ b/pkg/api/alertmanager.go @@ -174,8 +174,8 @@ type AlertingConfigResponse struct { type ApiAlertingConfig struct { config.Config - // Override/eliminate Routes tree in AM config - we'll set it via new fields - Route struct{} `yaml:"route,omitempty" json:"route,omitempty"` + // TODO: PR a followup to https://github.com/go-swagger/go-swagger/pull/1527 in order to allow + // explicitly ignoring embedded fields. In the meantime, these are hackily removed in our make targets via `jq` AlertManagerRoute *config.Route `yaml:"alertmanager_route,omitempty" json:"alertmanager_route,omitempty"` GrafanaManagedRoute *config.Route `yaml:"grafana_managed_route,omitempty" json:"grafana_managed_route,omitempty"` diff --git a/spec.json b/spec.json index 78f7280390d..65ee2767eac 100644 --- a/spec.json +++ b/spec.json @@ -949,9 +949,15 @@ "ApiAlertingConfig": { "type": "object", "properties": { + "alertmanager_route": { + "$ref": "#/definitions/Route" + }, "global": { "$ref": "#/definitions/GlobalConfig" }, + "grafana_managed_route": { + "$ref": "#/definitions/Route" + }, "inhibit_rules": { "type": "array", "items": { @@ -967,9 +973,6 @@ }, "x-go-name": "Receivers" }, - "route": { - "$ref": "#/definitions/Route" - }, "templates": { "type": "array", "items": { @@ -1533,6 +1536,19 @@ "GrafanaReceiver": { "$ref": "#/definitions/CreateAlertNotificationCommand" }, + "GrafanaReceivers": { + "type": "object", + "properties": { + "grafana_managed_receiver_configs": { + "type": "array", + "items": { + "$ref": "#/definitions/GrafanaReceiver" + }, + "x-go-name": "GrafanaManagedReceivers" + } + }, + "x-go-package": "github.com/grafana/alerting-api/pkg/api" + }, "HTTPClientConfig": { "type": "object", "title": "HTTPClientConfig configures an HTTP client.", @@ -1648,7 +1664,7 @@ "properties": { "Expr": { "type": "string", - "example": "(node_filesystem_avail_bytes{fstype!=\"\",job=\"integrations/node_exporter\"} node_filesystem_size_bytes{fstype!=\"\",job=\"integrations/node_exporter\"} * 100 \u003c 5 and node_filesystem_readonly{fstype!=\"\",job=\"integrations/node_exporter\"} == 0)" + "example": "(node_filesystem_avail_bytes{fstype!=\"\",job=\"integrations/node_exporter\"} node_filesystem_size_bytes{fstype!=\"\",job=\"integrations/node_exporter\"} * 100 < 5 and node_filesystem_readonly{fstype!=\"\",job=\"integrations/node_exporter\"} == 0)" }, "datasourceUid": { "description": "DatasourceUID is required if the query will be sent to grafana to be executed", @@ -2615,8 +2631,9 @@ "x-go-package": "github.com/grafana/alerting-api/pkg/api" }, "URL": { + "description": "The general form represented is:\n\n[scheme:][//[userinfo@]host][/]path[?query][#fragment]\n\nURLs that do not start with a slash after the scheme are interpreted as:\n\nscheme:opaque[?query][#fragment]\n\nNote that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/.\nA consequence is that it is impossible to tell which slashes in the Path were\nslashes in the raw URL and which were %2f. This distinction is rarely important,\nbut when it is, the code should use RawPath, an optional field which only gets\nset if the default encoding is different from Path.\n\nURL's String method uses the EscapedPath method to obtain the path. See the\nEscapedPath method for more details.", "type": "object", - "title": "URL is a custom URL type that allows validation at configuration load time.", + "title": "A URL represents a parsed URL (technically, a URI reference).", "properties": { "ForceQuery": { "type": "boolean" @@ -2649,7 +2666,7 @@ "$ref": "#/definitions/Userinfo" } }, - "x-go-package": "github.com/prometheus/common/config" + "x-go-package": "net/url" }, "UpdateDashboardAclCommand": { "type": "object", @@ -3473,4 +3490,4 @@ "type": "basic" } } -} \ No newline at end of file +}