-
Notifications
You must be signed in to change notification settings - Fork 153
[Feature] scalar alternative to swagger ui #1283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
9a06f36
09b202b
063a95f
8658b33
211c73d
3bf792d
0e3bff6
5d916ed
4694c45
9616299
63b258d
4ecfb54
d6e6ab2
ecc461f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| --- | ||
| id: scalar | ||
| title: Scalar | ||
| --- | ||
|
|
||
| # Scalar | ||
|
|
||
| Scalar middleware for [Fiber](https://github.com/gofiber/fiber). The middleware handles Scalar UI. | ||
|
|
||
| **Note: Requires Go 1.23.0 and above** | ||
|
|
||
| ### Table of Contents | ||
| - [Signatures](#signatures) | ||
| - [Installation](#installation) | ||
| - [Examples](#examples) | ||
| - [Config](#config) | ||
| - [Default Config](#default-config) | ||
|
|
||
| ### Signatures | ||
| ```go | ||
| func New(config ...scalar.Config) fiber.Handler | ||
| ``` | ||
|
|
||
| ### Installation | ||
| Scalar is tested on the latest [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet: | ||
| ```bash | ||
| go mod init github.com/<user>/<repo> | ||
| ``` | ||
| And then install the Scalar middleware: | ||
| ```bash | ||
| go get github.com/gofiber/contrib/scalar | ||
| ``` | ||
|
|
||
| ### Examples | ||
| Import the middleware package | ||
| ```go | ||
| import ( | ||
| "github.com/gofiber/fiber/v2" | ||
| "github.com/gofiber/contrib/scalar" | ||
| ) | ||
| ``` | ||
|
|
||
| Using swaggo to generate documents default output path is `(root)/docs`: | ||
| ```bash | ||
| swag init -v3.1 | ||
| ``` | ||
|
|
||
| Using the default config: | ||
| ```go | ||
| app.Use(scalar.New()) | ||
| ``` | ||
|
|
||
| Using a custom config: | ||
| ```go | ||
| cfg := scalar.Config{ | ||
| BasePath: "/", | ||
| FilePath: "./docs/swagger.json", | ||
| Path: "swagger", | ||
| Title: "Swagger API Docs", | ||
| } | ||
|
|
||
| app.Use(scalar.New(cfg)) | ||
| ``` | ||
|
|
||
| Use program data for Swagger content: | ||
| ```go | ||
| cfg := scalar.Config{ | ||
| BasePath: "/", | ||
| FilePath: "./docs/swagger.json", | ||
| FileContent: mySwaggerByteSlice, | ||
| Path: "swagger", | ||
| Title: "Swagger API Docs", | ||
| } | ||
|
|
||
| app.Use(scalar.New(cfg)) | ||
| ``` | ||
|
|
||
| ### Config | ||
| ```go | ||
| type Config struct { | ||
| // Next defines a function to skip this middleware when returned true. | ||
| // | ||
| // Optional. Default: nil | ||
| Next func(c *fiber.Ctx) bool | ||
|
|
||
| // BasePath for the UI path | ||
| // | ||
| // Optional. Default: / | ||
| BasePath string | ||
|
|
||
| // FilePath for the swagger.json or swagger.yaml file | ||
| // | ||
| // Optional. Default: ./docs/swagger.json | ||
| FilePath string | ||
|
|
||
| // FileContent for the content of the swagger.json or swagger.yaml file. | ||
| // If provided, FilePath will not be read. | ||
| // | ||
| // Optional. Default: nil | ||
| FileContent []byte | ||
|
|
||
| // Path combines with BasePath for the full UI path | ||
| // | ||
| // Optional. Default: docs | ||
| Path string | ||
|
|
||
| // Title for the documentation site | ||
| // | ||
| // Optional. Default: Fiber API documentation | ||
| Title string | ||
|
|
||
| // CacheAge defines the max-age for the Cache-Control header in seconds. | ||
| // | ||
| // Optional. Default: 0 (no cache) | ||
| CacheAge int | ||
| } | ||
yokeTH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### Default Config | ||
| ```go | ||
| var ConfigDefault = Config{ | ||
| Next: nil, | ||
| BasePath: "/", | ||
| FilePath: "./docs/swagger.json", | ||
| Path: "docs", | ||
| Title: "Fiber API documentation", | ||
| CacheAge: 0, | ||
| } | ||
yokeTH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
yokeTH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package scalar | ||
|
|
||
| import ( | ||
| "html/template" | ||
|
|
||
| "github.com/gofiber/fiber/v2" | ||
| ) | ||
|
|
||
| // Config defines the config for middleware. | ||
| type Config struct { | ||
| // Next defines a function to skip this middleware when returned true. | ||
| // | ||
| // Optional. Default: nil | ||
| Next func(c *fiber.Ctx) bool | ||
|
|
||
| // BasePath for the UI path | ||
| // | ||
| // Optional. Default: / | ||
| BasePath string | ||
|
|
||
| // FilePath for the swagger.json or swagger.yaml file | ||
| // | ||
| // Optional. Default: ./docs/swagger.json | ||
| FilePath string | ||
|
|
||
| // FileContent for the content of the swagger.json or swagger.yaml file. | ||
| // If provided, FilePath will not be read. | ||
| // | ||
| // Optional. Default: nil | ||
| FileContent []byte | ||
|
|
||
| // FileContent for the content of the swagger.json or swagger.yaml file. | ||
| // If provided, FilePath will not be read. | ||
| // | ||
| // Optional. Default: nil | ||
| FileContentString string | ||
|
|
||
| // Path combines with BasePath for the full UI path | ||
| // | ||
| // Optional. Default: docs | ||
| Path string | ||
|
|
||
| // Title for the documentation site | ||
| // | ||
| // Optional. Default: Fiber API documentation | ||
| Title string | ||
|
|
||
| // Custom Scalar Style | ||
| // Ref: https://github.com/scalar/scalar/blob/main/packages/themes/src/variables.css | ||
| // Optional. Default: "" | ||
| CustomStyle template.CSS | ||
|
|
||
| // Proxy to avoid CORS issues | ||
| // Optional. Default: "https://proxy.scalar.com" | ||
| ProxyUrl string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix URL field naming to follow Go conventions. The field names // Proxy to avoid CORS issues
// Optional. Default: "https://proxy.scalar.com"
-ProxyUrl string
+ProxyURL string
// Raw Space Url
// Optional. Default: doc.json
-RawSpecUrl string
+RawSpecURL stringDon't forget to update all references to these fields in scalar.go and the README.md file. Also applies to: 52-52 🤖 Prompt for AI Agents (early access)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Apply this change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain@gaby I'll apply this change to rename the struct fields to follow Go naming conventions for acronyms. flowchart TB
A[Task: Rename URL fields to follow Go conventions]
A --> B[Search for all references to ProxyUrl and RawSpecUrl]
A --> C[Update field names in scalar/config.go]
A --> D[Update all references in scalar.go]
A --> E[Update any references in README.md]
B --> F[Find usages with rg command]
C --> G[Change ProxyUrl to ProxyURL]
C --> H[Change RawSpecUrl to RawSpecURL]
D --> I[Update struct field access]
E --> J[Update documentation references]
🏁 Script executed: Length of output: 2776 🏁 Script executed: Length of output: 379 Perfect! I found all the references and there are no README updates needed. Now I can provide all the necessary code changes: flowchart TB
A["Task: Rename URL fields to follow Go conventions"]
A --o B["Update field names in scalar/config.go"]
A --o C["Update references in scalar/scalar.go"]
A --o D["Update template in scalar/index.go"]
A --o E["Update test files in scalar/scalar_test.go"]
B --o F["ProxyUrl → ProxyURL"]
B --o G["RawSpecUrl → RawSpecURL"]
B --o H["Update configDefault"]
C --o I["Update field access in logic"]
D --o J["Update template variables"]
E --o K["Update test configurations"]
The changes will rename ⏳ Preparing changes... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A summary of the edits CodeRabbit can apply:
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets): 📄 .In scalar/config.go, update the struct definition and default values as follows: --- a/scalar/config.go
+++ b/scalar/config.go
@@ type Config struct {
- // Proxy to avoid CORS issues
- // Optional.
- ProxyUrl string
+ // Proxy to avoid CORS issues
+ // Optional. Default: ""
+ ProxyURL string
- // Raw Space Url
- // Optional. Default: doc.json
- RawSpecUrl string
+ // Raw Space Url
+ // Optional. Default: doc.json
+ RawSpecURL string
@@ var configDefault = Config{
- RawSpecUrl: "doc.json",
+ RawSpecURL: "doc.json",
}In scalar/scalar.go, update all references to RawSpecUrl to RawSpecURL: --- a/scalar/scalar.go
+++ b/scalar/scalar.go
@@ if len(cfg.RawSpecUrl) == 0 {
- if len(cfg.RawSpecUrl) == 0 {
- cfg.RawSpecUrl = configDefault.RawSpecUrl
+ if len(cfg.RawSpecURL) == 0 {
+ cfg.RawSpecURL = configDefault.RawSpecURL
}
@@
- specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
+ specURL := path.Join(scalarUIPath, cfg.RawSpecURL)In scalar/index.go, update the template to use ProxyURL instead of ProxyUrl: --- a/scalar/index.go
+++ b/scalar/index.go
@@ Scalar.createApiReference('#app', {
- {{- if .ProxyUrl}}
- proxyUrl: "{{.ProxyUrl}}",
+ {{- if .ProxyURL}}
+ proxyUrl: "{{.ProxyURL}}",
{{ end }}In scalar/scalar_test.go, update test configurations to use RawSpecURL: --- a/scalar/scalar_test.go
+++ b/scalar/scalar_test.go
@@ app.Use(New(Config{
- RawSpecUrl: "swagger.json",
+ RawSpecURL: "swagger.json",
@@
- RawSpecUrl: "openapi.json",
+ RawSpecURL: "openapi.json",Run a final search to verify no leftover references in documentation: rg --include="*.md" "ProxyUrl|RawSpecUrl" .Since this returns no matches, no README.md updates are required. A summary of the context that CodeRabbit is considering across the codebase:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A summary of the edits CodeRabbit can apply:
A plan of each step that CodeRabbit will take in order to execute the edits for each file (with inline rough draft snippets): ✏️ scalar/config.goIn scalar/config.go, update the Config struct definition. Replace the ProxyUrl and RawSpecUrl declarations as follows: // Proxy to avoid CORS issues
- // Optional.
+ // Optional. Default: ""
- ProxyUrl string
+ ProxyURL string
// Raw Space Url
// Optional. Default: doc.json
- RawSpecUrl string
+ RawSpecURL stringAlso in scalar/config.go, update the configDefault block to use RawSpecURL: var configDefault = Config{
Next: nil,
BasePath: "/",
Path: "docs",
Title: "Fiber API documentation",
CacheAge: 60,
- RawSpecUrl: "doc.json",
+ RawSpecURL: "doc.json",
ForceOffline: true,
FallbackCacheAge: 86400,
}In scalar/scalar.go, update all references to RawSpecUrl to RawSpecURL: - if len(cfg.RawSpecUrl) == 0 {
- cfg.RawSpecUrl = configDefault.RawSpecUrl
+ if len(cfg.RawSpecURL) == 0 {
+ cfg.RawSpecURL = configDefault.RawSpecURL
}
scalarUIPath := path.Join(cfg.BasePath, cfg.Path)
- specURL := path.Join(scalarUIPath, cfg.RawSpecUrl)
+ specURL := path.Join(scalarUIPath, cfg.RawSpecURL)In scalar/index.go, update the template variable ProxyUrl to ProxyURL: Scalar.createApiReference('#app', {
content: {{.FileContentString}},
- {{- if .ProxyUrl}}
- proxyUrl: "{{.ProxyUrl}}",
+ {{- if .ProxyURL}}
+ proxyUrl: "{{.ProxyURL}}",
{{ end }}
});In scalar/scalar_test.go, rename RawSpecUrl to RawSpecURL in all Config initializations: app := setupApp()
app.Use(New(Config{
- RawSpecUrl: "swagger.json",
+ RawSpecURL: "swagger.json",
}))
BasePath: "/api",
Path: "swagger",
- RawSpecUrl: "openapi.json",
+ RawSpecURL: "openapi.json",
CacheAge: 3600,
}))Run a final search to ensure no old field names remain: rg -n "ProxyUrl|RawSpecUrl" .✏️ scalar/index.goChange the conditional check from Update the property line from Save the file and run A summary of the context that CodeRabbit is considering across the codebase:
|
||
| } | ||
|
|
||
| var ConfigDefault = Config{ | ||
| Next: nil, | ||
| BasePath: "/", | ||
| FilePath: "./docs/swagger.json", | ||
| Path: "docs", | ||
| Title: "Fiber API documentation", | ||
| ProxyUrl: "https://proxy.scalar.com", | ||
| } | ||
yokeTH marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| module github.com/gofiber/contrib/scalar | ||
|
|
||
| go 1.23.0 | ||
|
|
||
| require ( | ||
| github.com/gofiber/fiber/v2 v2.52.6 | ||
| gopkg.in/yaml.v2 v2.4.0 | ||
| ) | ||
|
|
||
| require ( | ||
| github.com/andybalholm/brotli v1.1.0 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/klauspost/compress v1.17.9 // indirect | ||
| github.com/kr/pretty v0.3.1 // indirect | ||
| github.com/mattn/go-colorable v0.1.13 // indirect | ||
| github.com/mattn/go-isatty v0.0.20 // indirect | ||
| github.com/mattn/go-runewidth v0.0.16 // indirect | ||
| github.com/rivo/uniseg v0.2.0 // indirect | ||
| github.com/rogpeppe/go-internal v1.11.0 // indirect | ||
| github.com/valyala/bytebufferpool v1.0.0 // indirect | ||
| github.com/valyala/fasthttp v1.51.0 // indirect | ||
| github.com/valyala/tcplisten v1.0.0 // indirect | ||
| golang.org/x/sys v0.28.0 // indirect | ||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= | ||
| github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= | ||
| github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= | ||
| github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI= | ||
| github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw= | ||
| github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
| github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
| github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA= | ||
| github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= | ||
| github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= | ||
| github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= | ||
| github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= | ||
| github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
| github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
| github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||
| github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||
| github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= | ||
| github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= | ||
| github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= | ||
| github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= | ||
| github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= | ||
| github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= | ||
| github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= | ||
| github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= | ||
| github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= | ||
| github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= | ||
| github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= | ||
| github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= | ||
| github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= | ||
| github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= | ||
| github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= | ||
| github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA= | ||
| github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g= | ||
| github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= | ||
| github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= | ||
| golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
| golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
| golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= | ||
| golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= | ||
| gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= | ||
| gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= | ||
| gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package scalar | ||
|
|
||
| const templateHTML = ` | ||
| <!doctype html> | ||
| <html> | ||
| <head> | ||
| <title>{{.Title}}</title> | ||
| <meta charset="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
|
|
||
| {{- if .CustomStyle }} | ||
| <style> | ||
| :root { | ||
| {{ .CustomStyle }} | ||
| } | ||
| </style> | ||
| {{ end }} | ||
| </head> | ||
|
|
||
| <body> | ||
| <div id="app"></div> | ||
|
|
||
| <script> | ||
| if (!navigator.onLine) { | ||
| var script = document.createElement('script'); | ||
| script.src = '/js/scalar.min.js'; | ||
| script.onload = initScalar; | ||
| document.head.appendChild(script); | ||
| } else { | ||
| var cdn = document.createElement('script'); | ||
| cdn.src = 'https://cdn.jsdelivr.net/npm/@scalar/api-reference'; | ||
| cdn.onload = initScalar; | ||
| cdn.onerror = function () { | ||
| var fallback = document.createElement('script'); | ||
| fallback.src = '/js/api-reference.min.js'; | ||
| fallback.onload = initScalar; | ||
| document.head.appendChild(fallback); | ||
| }; | ||
| document.head.appendChild(cdn); | ||
| } | ||
|
|
||
| function initScalar() { | ||
| if (typeof Scalar !== 'undefined') { | ||
| Scalar.createApiReference('#app', { | ||
| content: {{.FileContentString}}, | ||
| {{- if .ProxyUrl}} | ||
| proxyUrl: "{{.ProxyUrl}}", | ||
| {{ end }} | ||
| }); | ||
| } | ||
| } | ||
| </script> | ||
| </body> | ||
| </html>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add badges
https://github.com/gofiber/contrib/blob/main/casbin/README.md?plain=1#L7-L9