mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PublicDashboards: Add swagger documentation (#75318)
This commit is contained in:
committed by
GitHub
parent
e1293af775
commit
16034ef062
@@ -56,8 +56,9 @@ func (api *Api) RegisterAPIEndpoints() {
|
||||
// circular dependency
|
||||
|
||||
api.RouteRegister.Get("/api/public/dashboards/:accessToken", routing.Wrap(api.ViewPublicDashboard))
|
||||
api.RouteRegister.Get("/api/public/dashboards/:accessToken/annotations", routing.Wrap(api.GetPublicAnnotations))
|
||||
|
||||
api.RouteRegister.Post("/api/public/dashboards/:accessToken/panels/:panelId/query", routing.Wrap(api.QueryPublicDashboard))
|
||||
api.RouteRegister.Get("/api/public/dashboards/:accessToken/annotations", routing.Wrap(api.GetAnnotations))
|
||||
|
||||
// Auth endpoints
|
||||
auth := accesscontrol.Middleware(api.AccessControl)
|
||||
@@ -87,8 +88,15 @@ func (api *Api) RegisterAPIEndpoints() {
|
||||
routing.Wrap(api.DeletePublicDashboard))
|
||||
}
|
||||
|
||||
// ListPublicDashboards Gets list of public dashboards by orgId
|
||||
// GET /api/dashboards/public-dashboards
|
||||
// swagger:route GET /dashboards/public-dashboards dashboard_public listPublicDashboards
|
||||
//
|
||||
// Get list of public dashboards
|
||||
//
|
||||
// Responses:
|
||||
// 200: listPublicDashboardsResponse
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) ListPublicDashboards(c *contextmodel.ReqContext) response.Response {
|
||||
perPage := c.QueryInt("perpage")
|
||||
if perPage <= 0 {
|
||||
@@ -114,8 +122,17 @@ func (api *Api) ListPublicDashboards(c *contextmodel.ReqContext) response.Respon
|
||||
return response.JSON(http.StatusOK, resp)
|
||||
}
|
||||
|
||||
// GetPublicDashboard Gets public dashboard for dashboard
|
||||
// GET /api/dashboards/uid/:dashboardUid/public-dashboards
|
||||
// swagger:route GET /dashboards/uid/{dashboardUid}/public-dashboards dashboard_public getPublicDashboard
|
||||
//
|
||||
// Get public dashboard by dashboardUid
|
||||
//
|
||||
// Responses:
|
||||
// 200: getPublicDashboardResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 404: notFoundPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) GetPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
@@ -135,8 +152,19 @@ func (api *Api) GetPublicDashboard(c *contextmodel.ReqContext) response.Response
|
||||
return response.JSON(http.StatusOK, pd)
|
||||
}
|
||||
|
||||
// CreatePublicDashboard Sets public dashboard for dashboard
|
||||
// POST /api/dashboards/uid/:dashboardUid/public-dashboards
|
||||
// swagger:route POST /dashboards/uid/{dashboardUid}/public-dashboards dashboard_public createPublicDashboard
|
||||
//
|
||||
// Create public dashboard for a dashboard
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
//
|
||||
// Responses:
|
||||
// 200: createPublicDashboardResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
@@ -178,8 +206,19 @@ func (api *Api) CreatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, pd)
|
||||
}
|
||||
|
||||
// UpdatePublicDashboard Sets public dashboard for dashboard
|
||||
// PATCH /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
||||
// swagger:route PATCH /dashboards/uid/{dashboardUid}/public-dashboards/{uid} dashboard_public updatePublicDashboard
|
||||
//
|
||||
// Update public dashboard for a dashboard
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
//
|
||||
// Responses:
|
||||
// 200: updatePublicDashboardResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
// exit if we don't have a valid dashboardUid
|
||||
dashboardUid := web.Params(c.Req)[":dashboardUid"]
|
||||
@@ -215,8 +254,16 @@ func (api *Api) UpdatePublicDashboard(c *contextmodel.ReqContext) response.Respo
|
||||
return response.JSON(http.StatusOK, pd)
|
||||
}
|
||||
|
||||
// Delete a public dashboard
|
||||
// DELETE /api/dashboards/uid/:dashboardUid/public-dashboards/:uid
|
||||
// swagger:route DELETE /dashboards/uid/{dashboardUid}/public-dashboards/{uid} dashboard_public deletePublicDashboard
|
||||
//
|
||||
// Delete public dashboard for a dashboard
|
||||
//
|
||||
// Responses:
|
||||
// 200: okResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) DeletePublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
uid := web.Params(c.Req)[":uid"]
|
||||
if !validation.IsValidShortUID(uid) {
|
||||
@@ -252,3 +299,66 @@ func toJsonStreamingResponse(features *featuremgmt.FeatureManager, qdr *backend.
|
||||
|
||||
return response.JSONStreaming(statusCode, qdr)
|
||||
}
|
||||
|
||||
// swagger:response listPublicDashboardsResponse
|
||||
type ListPublicDashboardsResponse struct {
|
||||
// in: body
|
||||
Body PublicDashboardListResponseWithPagination `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters getPublicDashboard
|
||||
type GetPublicDashboardParams struct {
|
||||
// in:path
|
||||
DashboardUid string `json:"dashboardUid"`
|
||||
}
|
||||
|
||||
// swagger:response getPublicDashboardResponse
|
||||
type GetPublicDashboardResponse struct {
|
||||
// in: body
|
||||
Body PublicDashboard `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters createPublicDashboard
|
||||
type CreatePublicDashboardParams struct {
|
||||
// in:path
|
||||
// required:true
|
||||
DashboardUid string `json:"dashboardUid"`
|
||||
// in:body
|
||||
// required:true
|
||||
Body PublicDashboardDTO
|
||||
}
|
||||
|
||||
// swagger:response createPublicDashboardResponse
|
||||
type CreatePublicDashboardResponse struct {
|
||||
// in: body
|
||||
Body PublicDashboard `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters updatePublicDashboard
|
||||
type UpdatePublicDashboardParams struct {
|
||||
// in:path
|
||||
// required:true
|
||||
DashboardUid string `json:"dashboardUid"`
|
||||
// in:path
|
||||
// required:true
|
||||
Uid string `json:"uid"`
|
||||
// in:body
|
||||
// required:true
|
||||
Body PublicDashboardDTO
|
||||
}
|
||||
|
||||
// swagger:response updatePublicDashboardResponse
|
||||
type UpdatePublicDashboardResponse struct {
|
||||
// in: body
|
||||
Body PublicDashboard `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters deletePublicDashboard
|
||||
type DeletePublicDashboardParams struct {
|
||||
// in:path
|
||||
// required:true
|
||||
DashboardUid string `json:"dashboardUid"`
|
||||
// in:path
|
||||
// required:true
|
||||
Uid string `json:"uid"`
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana/pkg/api/dtos"
|
||||
"github.com/grafana/grafana/pkg/api/response"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
. "github.com/grafana/grafana/pkg/services/publicdashboards/models"
|
||||
@@ -11,8 +13,17 @@ import (
|
||||
"github.com/grafana/grafana/pkg/web"
|
||||
)
|
||||
|
||||
// ViewPublicDashboard Gets public dashboard
|
||||
// GET /api/public/dashboards/:accessToken
|
||||
// swagger:route GET /public/dashboards/{accessToken} dashboard_public viewPublicDashboard
|
||||
//
|
||||
// Get public dashboard for view
|
||||
//
|
||||
// Responses:
|
||||
// 200: viewPublicDashboardResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 404: notFoundPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) ViewPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !validation.IsValidAccessToken(accessToken) {
|
||||
@@ -27,8 +38,18 @@ func (api *Api) ViewPublicDashboard(c *contextmodel.ReqContext) response.Respons
|
||||
return response.JSON(http.StatusOK, dto)
|
||||
}
|
||||
|
||||
// QueryPublicDashboard returns all results for a given panel on a public dashboard
|
||||
// POST /api/public/dashboard/:accessToken/panels/:panelId/query
|
||||
// swagger:route POST /public/dashboards/{accessToken}/panels/{panelId}/query dashboard_public queryPublicDashboard
|
||||
//
|
||||
// Get results for a given panel on a public dashboard
|
||||
//
|
||||
// Responses:
|
||||
// 200: queryPublicDashboardResponse
|
||||
// 400: badRequestPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 404: panelNotFoundPublicError
|
||||
// 404: notFoundPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) QueryPublicDashboard(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !validation.IsValidAccessToken(accessToken) {
|
||||
@@ -53,12 +74,21 @@ func (api *Api) QueryPublicDashboard(c *contextmodel.ReqContext) response.Respon
|
||||
return toJsonStreamingResponse(api.Features, resp)
|
||||
}
|
||||
|
||||
// GetAnnotations returns annotations for a public dashboard
|
||||
// GET /api/public/dashboards/:accessToken/annotations
|
||||
func (api *Api) GetAnnotations(c *contextmodel.ReqContext) response.Response {
|
||||
// swagger:route GET /public/dashboards/{accessToken}/annotations dashboard_public getPublicAnnotations
|
||||
//
|
||||
// Get annotations for a public dashboard
|
||||
//
|
||||
// Responses:
|
||||
// 200: getPublicAnnotationsResponse
|
||||
// 400: badRequestPublicError
|
||||
// 404: notFoundPublicError
|
||||
// 401: unauthorisedPublicError
|
||||
// 403: forbiddenPublicError
|
||||
// 500: internalServerPublicError
|
||||
func (api *Api) GetPublicAnnotations(c *contextmodel.ReqContext) response.Response {
|
||||
accessToken := web.Params(c.Req)[":accessToken"]
|
||||
if !validation.IsValidAccessToken(accessToken) {
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("GetAnnotations: invalid access token"))
|
||||
return response.Err(ErrInvalidAccessToken.Errorf("GetPublicAnnotations: invalid access token"))
|
||||
}
|
||||
|
||||
reqDTO := AnnotationsQueryDTO{
|
||||
@@ -73,3 +103,41 @@ func (api *Api) GetAnnotations(c *contextmodel.ReqContext) response.Response {
|
||||
|
||||
return response.JSON(http.StatusOK, annotations)
|
||||
}
|
||||
|
||||
// swagger:response viewPublicDashboardResponse
|
||||
type ViewPublicDashboardResponse struct {
|
||||
// in: body
|
||||
Body dtos.DashboardFullWithMeta `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters viewPublicDashboard
|
||||
type ViewPublicDashboardParams struct {
|
||||
// in: path
|
||||
AccessToken string `json:"accessToken"`
|
||||
}
|
||||
|
||||
// swagger:response queryPublicDashboardResponse
|
||||
type QueryPublicDashboardResponse struct {
|
||||
// in: body
|
||||
Body backend.QueryDataResponse `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters queryPublicDashboard
|
||||
type QueryPublicDashboardParams struct {
|
||||
// in: path
|
||||
AccessToken string `json:"accessToken"`
|
||||
// in: path
|
||||
PanelId int64 `json:"panelId"`
|
||||
}
|
||||
|
||||
// swagger:response getPublicAnnotationsResponse
|
||||
type GetPublicAnnotationsResponse struct {
|
||||
// in: body
|
||||
Body []AnnotationEvent `json:"body"`
|
||||
}
|
||||
|
||||
// swagger:parameters getPublicAnnotations
|
||||
type GetPublicAnnotationsParams struct {
|
||||
// in: path
|
||||
AccessToken string `json:"accessToken"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user