Skip to content

Commit

Permalink
feat: modify swagger-UI
Browse files Browse the repository at this point in the history
  • Loading branch information
starcharles committed Jul 22, 2023
1 parent 236cae1 commit cbc2bc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
// Config stores echoSwagger configuration variables.
type Config struct {
// The url pointing to API definition (normally swagger.json or swagger.yaml). Default is `mockedSwag.json`.
URL string
URLs []string
DocExpansion string
DomID string
InstanceName string
Expand Down Expand Up @@ -43,7 +43,7 @@ type OAuthConfig struct {
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
func URL(url string) func(*Config) {
return func(c *Config) {
c.URL = url
c.URLs = append(c.URLs, url)
}
}

Expand Down Expand Up @@ -98,7 +98,7 @@ func OAuth(config *OAuthConfig) func(*Config) {

func newConfig(configFns ...func(*Config)) *Config {
config := Config{
URL: "doc.json",
URLs: []string{"doc.json", "doc.yaml"},
DocExpansion: "list",
DomID: "swagger-ui",
InstanceName: "swagger",
Expand Down Expand Up @@ -270,7 +270,14 @@ const indexTemplate = `<!-- HTML for static distribution bundle build -->
window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "{{.URL}}",
urls: [
{{range $index, $url := .URLs}}
{
name: "{{$url}}",
url: "{{$url}}",
},
{{end}}
],
syntaxHighlight: {{.SyntaxHighlight}},
deepLinking: {{.DeepLinking}},
docExpansion: "{{.DocExpansion}}",
Expand Down
2 changes: 1 addition & 1 deletion swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func TestURL(t *testing.T) {
var cfg Config
expected := "https://github.com/swaggo/http-swagger"
URL(expected)(&cfg)
assert.Equal(t, expected, cfg.URL)
assert.Equal(t, expected, cfg.URLs[0])
}

func TestDeepLinking(t *testing.T) {
Expand Down

0 comments on commit cbc2bc0

Please sign in to comment.