mirror of https://github.com/grafana/grafana
Swagger: Show k8s APIs (#78091)
parent
e4d41e878f
commit
b8e8d84ef7
@ -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) |
||||
} |
||||
@ -1,63 +0,0 @@ |
||||
<!-- HTML for static distribution bundle build --> |
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<title>Swagger UI</title> |
||||
<link rel="stylesheet" type="text/css" href="https://unpkg.com/swagger-ui-dist@4.3.0/swagger-ui.css" integrity="sha384-pzdBB6iZwPIzBHgXle+9cgvKuMgtWNrBopXkjrWnKCi3m4uJsPPdLQ4IPMqRDirS" crossorigin="anonymous" referrerpolicy="no-referrer" /> |
||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" /> |
||||
<link rel="icon" type="image/png" href="./favicon-16x16.png" sizes="16x16" /> |
||||
<style> |
||||
html |
||||
{ |
||||
box-sizing: border-box; |
||||
overflow: -moz-scrollbars-vertical; |
||||
overflow-y: scroll; |
||||
} |
||||
|
||||
*, |
||||
*:before, |
||||
*:after |
||||
{ |
||||
box-sizing: inherit; |
||||
} |
||||
|
||||
body |
||||
{ |
||||
margin:0; |
||||
background: #fafafa; |
||||
} |
||||
</style> |
||||
</head> |
||||
|
||||
<body> |
||||
<div id="swagger-ui"></div> |
||||
|
||||
<script nonce="[[.Nonce]]" src="https://unpkg.com/swagger-ui-dist@4.3.0/swagger-ui-bundle.js" charset="UTF-8" integrity="sha384-BGJ5JzR5LEl4ETmxXXlZtXtMWj3uQ9jj9/OHe3yrn5rrtAyLOz1SyyzwMfuwZgPc" crossorigin="anonymous" referrerpolicy="no-referrer"></script> |
||||
<script nonce="[[.Nonce]]" src="https://unpkg.com/swagger-ui-dist@4.3.0/swagger-ui-standalone-preset.js" charset="UTF-8" integrity="sha384-AWSfISmlS8fS336GXRkpL0Uv6EbCpsFfXDUwmklhbb3SctGSuvXWBcbjERjgf/e4" crossorigin="anonymous" referrerpolicy="no-referrer"></script> |
||||
<script nonce="[[.Nonce]]"> |
||||
window.onload = function() { |
||||
// Begin Swagger UI call region |
||||
const ui = SwaggerUIBundle({ |
||||
url: "/public/openapi3.json", |
||||
dom_id: '#swagger-ui', |
||||
deepLinking: true, |
||||
presets: [ |
||||
SwaggerUIBundle.presets.apis, |
||||
SwaggerUIStandalonePreset |
||||
], |
||||
plugins: [ |
||||
SwaggerUIBundle.plugins.DownloadUrl |
||||
], |
||||
layout: "StandaloneLayout", |
||||
filter: true, |
||||
tagsSorter: "alpha", |
||||
tryItOutEnabled: true |
||||
}); |
||||
// End Swagger UI call region |
||||
|
||||
window.ui = ui; |
||||
}; |
||||
</script> |
||||
</body> |
||||
</html> |
||||
Loading…
Reference in new issue