mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Swagger: Show k8s APIs (#78091)
This commit is contained in:
@@ -79,4 +79,4 @@ 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-ui` and `/openapi3` respectively.
|
||||
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`.
|
||||
|
||||
@@ -213,8 +213,8 @@ func (hs *HTTPServer) registerRoutes() {
|
||||
// expose plugin file system assets
|
||||
r.Get("/public/plugins/:pluginId/*", hs.getPluginAssets)
|
||||
|
||||
r.Get("/swagger-ui", swaggerUI)
|
||||
r.Get("/openapi3", openapi3)
|
||||
// add swagger support
|
||||
registerSwaggerUI(r)
|
||||
|
||||
if hs.Features.IsEnabledGlobally(featuremgmt.FlagClientTokenRotation) {
|
||||
r.Post("/api/user/auth-tokens/rotate", routing.Wrap(hs.RotateUserAuthToken))
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
func openapi3(c *contextmodel.ReqContext) {
|
||||
data := map[string]any{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "openapi3", data)
|
||||
}
|
||||
@@ -4,19 +4,31 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/api/routing"
|
||||
contextmodel "github.com/grafana/grafana/pkg/services/contexthandler/model"
|
||||
)
|
||||
|
||||
func swaggerUI(c *contextmodel.ReqContext) {
|
||||
data := map[string]any{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
func registerSwaggerUI(r routing.RouteRegister) {
|
||||
// Deprecated
|
||||
r.Get("/swagger-ui", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "swagger", http.StatusMovedPermanently)
|
||||
})
|
||||
// Deprecated
|
||||
r.Get("/openapi3", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "swagger?show=v3", http.StatusMovedPermanently)
|
||||
})
|
||||
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
r.Get("/swagger", func(c *contextmodel.ReqContext) {
|
||||
data := map[string]any{
|
||||
"Nonce": c.RequestNonce,
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "swagger", data)
|
||||
// Add CSP for unpkg.com to allow loading of Swagger UI assets
|
||||
if existingCSP := c.Resp.Header().Get("Content-Security-Policy"); existingCSP != "" {
|
||||
newCSP := strings.Replace(existingCSP, "style-src", "style-src https://unpkg.com/", 1)
|
||||
c.Resp.Header().Set("Content-Security-Policy", newCSP)
|
||||
}
|
||||
|
||||
c.HTML(http.StatusOK, "swagger", data)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user