grafana/pkg/api
Denis Vodopianov 0e460a267e
chore : Deprecating FeatureToggles.IsEnabled (#113062)
* Deprecating features.IsEnabled

* add one more nolint

* add one more nolint

* Give better hints to devs in the deprecation message of IsEnabledGlobally

* adding more doc strings

* fix linter after rebase

* Extend deprecation message
2025-11-21 18:43:42 +01:00
..
apierrors fix: improve api error handling for dashboards and folders (#111831) 2025-10-01 09:54:14 +02:00
avatar
datasource MSSQL: Minor refactor (#113976) 2025-11-20 11:09:09 +00:00
dtos EchoSrv: Enable auto route tracking for Azure App Insights (#113354) 2025-11-11 16:33:46 +00:00
frontendlogging
pluginproxy chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
response chore(deps): Switch to maintained gopkg.in/yaml fork (#114131) 2025-11-19 15:20:32 -05:00
routing
static Apply security patch security-patch-202505051005.patch (#105754) 2025-05-21 21:34:05 +03:00
webassets FS: Get CDN prefix from configuration (#110615) 2025-09-08 15:57:03 +00:00
accesscontrol.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
admin.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
admin_encryption.go admin api: Fix reencryption of private_key in signing_key table, introduce test for reencryption (#105010) 2025-05-15 09:51:25 +02:00
admin_provisioning.go
admin_provisioning_test.go
admin_test.go
admin_users.go Preferences: Support Create+Update+Delete over apiserver (#111715) 2025-10-02 21:58:08 +03:00
admin_users_test.go
alerting.go Alerting: Migrate to integration schema (#111643) 2025-09-26 09:31:50 -04:00
annotations.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
annotations_test.go Folders: Split legacy out of folder.Service (and remove folder.FolderStore) (#110734) 2025-09-08 18:27:49 +03:00
api.go DashboardLibrary: Fix 404 not found error when browsing the page (#114094) 2025-11-18 15:43:25 -03:00
api_test.go
basic_auth.go
basic_auth_test.go
common_test.go Fix: Return auth labels from /api/users/lookup (#113584) 2025-11-07 16:51:41 +01:00
dashboard.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
dashboard_permission.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
dashboard_permission_test.go
dashboard_snapshot.go chore : Deprecating FeatureToggles.IsEnabledGlobally (#112885) 2025-10-24 12:02:53 -04:00
dashboard_snapshot_test.go RBAC: Remove dashboard guardians pt 3 (#102558) 2025-03-21 10:44:16 +00:00
dashboard_test.go LibraryPanel: Cleanup service calls (#113277) 2025-11-06 15:31:02 +01:00
dataproxy.go
datasources.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
datasources_test.go LBAC for data sources: Refactor for readablitity (#112371) 2025-10-14 15:39:55 -05:00
ds_query.go log: added debug-log (#113156) 2025-10-29 14:19:24 +01:00
ds_query_test.go log: added debug-log (#113156) 2025-10-29 14:19:24 +01:00
fakes.go
folder.go fix: delete subfolder dangling panels (#113419) 2025-11-06 13:56:32 +01:00
folder_bench_test.go Folders: Split legacy out of folder.Service (and remove folder.FolderStore) (#110734) 2025-09-08 18:27:49 +03:00
folder_permission.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
folder_permission_test.go
folder_test.go chore: move enable search to US configuration (#114070) 2025-11-18 17:32:25 +01:00
frontend_logging.go
frontend_logging_test.go
frontend_metrics.go
frontendsettings.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
frontendsettings_test.go Plugins: Replace CDN class with FS CDN type (#113968) 2025-11-20 14:03:24 +00:00
grafana_com_proxy.go
health.go Spanner-related fixes (#102376) 2025-03-19 12:34:44 +01:00
health_test.go
http_server.go Chore: Add html_handler_requests metric (#113991) 2025-11-19 16:40:54 -05:00
http_server_test.go
index.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
login.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
login_oauth.go chore : Deprecating FeatureToggles.IsEnabledGlobally (#112885) 2025-10-24 12:02:53 -04:00
login_oauth_test.go Replace usage of http.DefaultClient and http.DefaultTransport (#104135) 2025-05-09 13:26:39 -04:00
login_test.go Chore: Add html_handler_requests metric (#113991) 2025-11-19 16:40:54 -05:00
org.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
org_invite.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
org_invite_test.go
org_test.go
org_users.go Fix: Return auth labels from /api/users/lookup (#113584) 2025-11-07 16:51:41 +01:00
org_users_test.go Replace check for integration tests. (#110707) 2025-09-08 15:49:49 +02:00
password.go
playlist.go Chore: Use Kind().GroupVersionResource() (#113133) 2025-10-28 14:54:10 -07:00
plugin_checks.go
plugin_checks_test.go
plugin_dashboards.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
plugin_dashboards_test.go
plugin_metrics.go
plugin_metrics_test.go
plugin_proxy.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
plugin_proxy_test.go
plugin_resource.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
plugin_resource_test.go QueryCaching: Use CachingServiceClient for query caching (#112128) 2025-10-28 11:41:46 -03:00
plugins.go chore : Deprecating FeatureToggles.IsEnabled (#113062) 2025-11-21 18:43:42 +01:00
plugins_test.go Plugins: API sync (#112452) 2025-10-24 08:09:26 -04:00
preferences.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
preferences_test.go Preferences: Use dashboard uid for the home dashboard (#106666) 2025-06-13 07:10:44 -05:00
quota.go docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
quota_test.go
README.md Chore: Remove Bingo as Drone is removed (#110020) 2025-08-22 13:49:44 +02:00
render.go Rendering: Add support for rate limiter (#103987) 2025-04-24 15:31:19 +02:00
search.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
short_url.go ShortURL: Graduate api v1alpha1 to v1beta1 (#113597) 2025-11-10 07:29:33 -03:00
short_url_test.go ShortURL: Use UpdateStatus client (#111170) 2025-10-30 15:57:03 +03:00
signup.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
swagger.go Revert "Build swagger ui in seperate webpack build" (#104580) 2025-04-25 22:07:43 +01:00
swagger_responses.go K8s: Schema v2: Return 406 in /api (#101842) 2025-03-07 18:20:02 -06:00
swagger_tags.json docs(openapi): Cleanup tag usage and minor fixes (#105546) 2025-08-28 01:51:04 +04:00
user.go Fix: Return auth labels from /api/users/lookup (#113584) 2025-11-07 16:51:41 +01:00
user_test.go Fix: Return auth labels from /api/users/lookup (#113584) 2025-11-07 16:51:41 +01:00
user_token.go CI: Bump golangci-lint to 2.0.2 (#103572) 2025-04-10 14:42:23 +02:00
user_token_test.go Forbid more redirect patterns (#110337) 2025-09-02 16:12:39 +02:00
utils.go

OpenAPI specifications

Since version 8.4, HTTP API details are specified using OpenAPI v2. Starting from version 9.1, there is also an OpenAPI v3 specification (generated by the v2 one using this script).

OpenAPI annotations

The OpenAPI v2 specification is generated automatically from the annotated Go code using go-swagger which scans the source code for annotation rules. Refer to this getting started guide for getting familiar with the toolkit.

Developers modifying the HTTP API endpoints need to make sure to add the necessary annotations so that their changes are reflected into the generated specifications.

Example of endpoint annotation

The following route defines a PATCH endpoint under the /serviceaccounts/{serviceAccountId} path with tag service_accounts (used for grouping together several routes) and operation ID updateServiceAccount (used for uniquely identifying routes and associate parameters and response with them).

For enterprise endpoints make sure you add the enterprise tag as well.


// swagger:route PATCH /serviceaccounts/{serviceAccountId} service_accounts updateServiceAccount
//
// # Update service account
//
// Required permissions (See note in the [introduction](https://grafana.com/docs/grafana/latest/developers/http_api/serviceaccount/#service-account-api) for an explanation):
// action: `serviceaccounts:write` scope: `serviceaccounts:id:1` (single service account)
//
// Responses:
// 200: updateServiceAccountResponse
// 400: badRequestError
// 401: unauthorisedError
// 403: forbiddenError
// 404: notFoundError
// 500: internalServerError

The go-swagger can discover such annotations by scanning any code imported by pkg/server but by convention we place the endpoint annotations above the endpoint definition.

Example of endpoint parameters

The following struct defines the route parameters for the updateServiceAccount endpoint. The route expects:

  • a path parameter denoting the service account identifier and
  • a body parameter with the new values for the specific service account

// swagger:parameters updateServiceAccount
type UpdateServiceAccountParams struct {
	// in:path
	ServiceAccountId int64 `json:"serviceAccountId"`
	// in:body
	Body serviceaccounts.UpdateServiceAccountForm
}

Example of endpoint response

The following struct defines the response for the updateServiceAccount endpoint in case of a successful 200 response.


// swagger:response updateServiceAccountResponse
type UpdateServiceAccountResponse struct {
	// in:body
	Body struct {
		Message        string                                    `json:"message"`
		ID             int64                                     `json:"id"`
		Name           string                                    `json:"name"`
		ServiceAccount *serviceaccounts.ServiceAccountProfileDTO `json:"serviceaccount"`
	}
}

OpenAPI generation

Developers can re-create the OpenAPI v2 and v3 specifications using the following command:

make swagger-clean && make openapi3-gen

They can observe its output into the public/api-merged.json and public/openapi3.json files.

Finally, they can browser and try out both the OpenAPI v2 and v3 via the Swagger UI editor (served by the grafana server) by navigating to /swagger.

If there are any issues generating the specifications (e.g., diff containing unrelated changes to your PR or unusually large diff), please run the following command to ensure your Swagger version is up to date, then re-run the make commands.

  • go tool github.com/go-swagger/go-swagger/cmd/swagger@v0.30.6