forked from lazada/swgui
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from swaggest/v3-dev
Swagger UI v3
- Loading branch information
Showing
73 changed files
with
1,533 additions
and
1,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package swgui | ||
|
||
// Config is used for Swagger UI handler configuration | ||
type Config struct { | ||
Title string `json:"title"` // title of index file | ||
SwaggerJSON string `json:"swaggerJsonUrl"` // url to swagger.json document specification | ||
BasePath string `json:"basePath"` // base url to docs | ||
|
||
ShowTopBar bool `json:"showTopBar"` // Show navigation top bar, hidden by default | ||
JsonEditor bool `json:"jsonEditor"` // Enable visual json editor support (experimental, can fail with complex schemas) | ||
PreAuthorizeApiKey map[string]string `json:"preAuthorizeApiKey"` // Map of security name to key value | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,14 @@ | ||
// Package swgui provide a http FileSystem handler for swagger UI interface | ||
// | ||
// File `bindata_assetfs.go` is generated by go-bindata-assetfs (https://github.com/elazarl/go-bindata-assetfs) tool, | ||
// which help to embed all static files into a go source file. | ||
// | ||
// How to generate file: | ||
// | ||
// NOTE: | ||
// * File `bindata_assetfs.go` ONLY need to re-generate file again when we update swagger-ui (swagger/ui/static) | ||
// How to generate asset files: | ||
// | ||
// 1. Install tools: | ||
// | ||
// go get -u github.com/jteeuwen/go-bindata/... | ||
// go get -u github.com/elazarl/go-bindata-assetfs/... | ||
// go get -u github.com/shurcooL/vfsgen | ||
// | ||
// 2. Generate file: | ||
// | ||
// At root folder, run command: | ||
// | ||
// go-bindata-assetfs -pkg=swgui static/... | ||
// gofmt -w bindata_assetfs.go | ||
// | ||
// Or just run: `go generate` | ||
// | ||
// Enjoy it ;) | ||
// go generate | ||
// | ||
package swgui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package swgui | ||
|
||
//go:generate go-bindata-assetfs -pkg $GOPACKAGE static/... | ||
//go:generate gofmt -w bindata_assetfs.go | ||
//go:generate go run ./v2/gen/gen.go | ||
//go:generate go run ./v3/gen/gen.go |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
|
||
"github.com/shurcooL/vfsgen" | ||
) | ||
|
||
func main() { | ||
var fs http.FileSystem = http.Dir("./v2/static") | ||
|
||
err := vfsgen.Generate(fs, vfsgen.Options{ | ||
PackageName: "v2", | ||
Filename: "v2/static.go", | ||
}) | ||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package v2 | ||
|
||
import ( | ||
"encoding/json" | ||
"html/template" | ||
"net/http" | ||
|
||
"github.com/swaggest/swgui" | ||
) | ||
|
||
var staticServer = http.FileServer(assets) | ||
|
||
// Handler handle swagger UI request | ||
type Handler struct { | ||
swgui.Config | ||
|
||
ConfigJson template.JS | ||
|
||
tpl *template.Template | ||
staticServer http.Handler | ||
} | ||
|
||
// NewHandler returns a HTTP handler for swagger UI | ||
func NewHandler(title, swaggerJSONPath string, basePath string) *Handler { | ||
h := &Handler{} | ||
h.Title = title | ||
h.SwaggerJSON = swaggerJSONPath | ||
h.BasePath = basePath | ||
|
||
j, _ := json.Marshal(h.Config) | ||
h.ConfigJson = template.JS(j) | ||
h.tpl, _ = template.New("index").Parse(indexTpl) | ||
h.staticServer = http.StripPrefix(basePath, staticServer) | ||
return h | ||
} | ||
|
||
// NewHandlerWithConfig returns a HTTP handler for swagger UI | ||
func NewHandlerWithConfig(config swgui.Config) *Handler { | ||
h := &Handler{ | ||
Config: config, | ||
} | ||
j, _ := json.Marshal(h.Config) | ||
h.ConfigJson = template.JS(j) | ||
h.tpl, _ = template.New("index").Parse(indexTpl) | ||
h.staticServer = http.StripPrefix(h.BasePath, staticServer) | ||
return h | ||
} | ||
|
||
// ServeHTTP implement http.Handler interface, to handle swagger UI request | ||
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Path != h.BasePath { | ||
h.staticServer.ServeHTTP(w, r) | ||
return | ||
} | ||
|
||
if err := h.tpl.Execute(w, h); err != nil { | ||
http.NotFound(w, r) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.