Alerting: Fix swagger generation (#106106)

This commit is contained in:
Alexander Akhmetov
2025-05-28 10:15:11 +02:00
committed by GitHub
parent 6f3b0e95b4
commit b51d70aad9
7 changed files with 28 additions and 7 deletions

View File

@ -1,3 +1,5 @@
include ../../../../../.citools/Variables.mk
.DEFAULT_GOAL := openapi
API_DIR = definitions
@ -6,8 +8,7 @@ GO_PKG_FILES = $(shell find $(API_DIR) -name *.go -print)
PATH_DOWN = pkg/services/ngalert/api/tooling
PATH_UP = ../../../../..
GO ?= $(shell which go)
SWAGGER = GODEBUG=gotypesalias=0 $(GO) tool swagger
SWAGGER = GODEBUG=gotypesalias=0 $(swagger)
.DEFAULT_GOAL := all
@ -29,6 +30,12 @@ endif
spec.json spec-stable.json: $(GO_PKG_FILES)
SWAGGER_GENERATE_EXTENSION=false $(SWAGGER) generate spec -m -w $(API_DIR) -o spec.json && SWAGGER_GENERATE_EXTENSION=false $(SWAGGER) generate spec -m --include-tag=stable -o spec-stable.json
# Prometheus URL type collides with the net/url.URL type, so we need to fix the spec if the descriptions are not correct
# to make the spec generation consistent.
fix-spec:
sed $(SED_INPLACE) -e 's/A URL represents a parsed URL (technically, a URI reference)./URL is a custom URL type that allows validation at configuration load time./' spec.json spec-stable.json
sed $(SED_INPLACE) -e '/The general form represented is:\\n\\n\[scheme:\]\[\/\/\[userinfo@\]host\]\[\/\]path\[?query\]\[#fragment\]/d' spec.json spec-stable.json
post.json: spec.json
go run cmd/clean-swagger/main.go -if $(<) -of $@
@ -76,4 +83,4 @@ serve-stable: api.json
gen: swagger-codegen-api fix copy-files clean-go
all: clean spec.json spec-stable.json post.json api.json gen
all: clean spec.json spec-stable.json fix-spec post.json api.json gen

View File

@ -4932,6 +4932,7 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/definitions/alertGroup",
"type": "object"
@ -5218,6 +5219,7 @@
"type": "object"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"items": {
"$ref": "#/definitions/gettableSilence",
"type": "object"

View File

@ -498,6 +498,8 @@ type PostSilencesOKBody struct { // vendored from "github.com/prometheus/alertma
SilenceID string `json:"silenceID,omitempty"`
}
// GettableSilences gettable silences
//
// swagger:model gettableSilences
type GettableSilences = amv2.GettableSilences
@ -552,11 +554,15 @@ func (s GettableGrafanaSilence) MarshalJSON() ([]byte, error) {
// swagger:model gettableGrafanaSilences
type GettableGrafanaSilences []*GettableGrafanaSilence
// GettableAlerts gettable alerts
//
// swagger:model gettableAlerts
type GettableAlerts = amv2.GettableAlerts
type GettableAlert = amv2.GettableAlert
// AlertGroups alert groups
//
// swagger:model alertGroups
type AlertGroups = amv2.AlertGroups

View File

@ -4636,7 +4636,6 @@
"type": "object"
},
"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\nThe Host field contains the host and port subcomponents of the URL.\nWhen the port is present, it is separated from the host with a colon.\nWhen the host is an IPv6 address, it must be enclosed in square brackets:\n\"[fe80::1]:80\". The [net.JoinHostPort] function combines a host and port\ninto a string suitable for the Host field, adding square brackets to\nthe host when necessary.\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 the [URL.EscapedPath] method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.",
"properties": {
"ForceQuery": {
"type": "boolean"
@ -4672,7 +4671,7 @@
"$ref": "#/definitions/Userinfo"
}
},
"title": "A URL represents a parsed URL (technically, a URI reference).",
"title": "URL is a custom URL type that allows validation at configuration load time.",
"type": "object"
},
"UpdateNamespaceRulesRequest": {
@ -4933,6 +4932,7 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/definitions/alertGroup",
"type": "object"
@ -5094,6 +5094,7 @@
"type": "object"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": {
"$ref": "#/definitions/gettableAlert",
"type": "object"

View File

@ -8809,9 +8809,8 @@
}
},
"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\nThe Host field contains the host and port subcomponents of the URL.\nWhen the port is present, it is separated from the host with a colon.\nWhen the host is an IPv6 address, it must be enclosed in square brackets:\n\"[fe80::1]:80\". The [net.JoinHostPort] function combines a host and port\ninto a string suitable for the Host field, adding square brackets to\nthe host when necessary.\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 the [URL.EscapedPath] method, which preserves\nthe original encoding of Path.\n\nThe RawPath field is an optional field which is only set when the default\nencoding of Path is different from the escaped path. See the EscapedPath method\nfor more details.\n\nURL's String method uses the EscapedPath method to obtain the path.",
"type": "object",
"title": "A URL represents a parsed URL (technically, a URI reference).",
"title": "URL is a custom URL type that allows validation at configuration load time.",
"properties": {
"ForceQuery": {
"type": "boolean"
@ -9106,6 +9105,7 @@
}
},
"alertGroups": {
"description": "AlertGroups alert groups",
"type": "array",
"items": {
"type": "object",
@ -9267,6 +9267,7 @@
}
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array",
"items": {
"type": "object",

View File

@ -22999,6 +22999,7 @@
}
},
"alertGroups": {
"description": "AlertGroups alert groups",
"type": "array",
"items": {
"type": "object",
@ -23328,6 +23329,7 @@
}
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"type": "array",
"items": {
"type": "object",

View File

@ -12974,6 +12974,7 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/components/schemas/alertGroup"
},
@ -13301,6 +13302,7 @@
"type": "object"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"items": {
"$ref": "#/components/schemas/gettableSilence"
},