Skip to content

Commit

Permalink
Merge pull request #3 from a-kataev/a-kataev/fix-baselayout-url
Browse files Browse the repository at this point in the history
fix baselayout url
  • Loading branch information
a-kataev authored Nov 13, 2022
2 parents 98e2fc5 + 68aaaea commit 27ce5ed
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
25 changes: 22 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ import (
"github.com/a-kataev/swagfs/tmpl"
)

type Layout string

const (
BaseLayout = "BaseLayout"
StandaloneLayout = "StandaloneLayout"
)

type URL struct {
URL string `json:"url"`
Name string `json:"name,omitempty"`
}

type Config struct {
Urls []URL `json:"urls"`
Layout string `json:"layout"`
Layout Layout `json:"layout"`
}

var _ tmpl.File = (*Config)(nil)
Expand All @@ -29,7 +36,7 @@ func defaultConfig() *Config {
Name: "v1",
},
},
Layout: "BaseLayout",
Layout: BaseLayout,
}
}

Expand All @@ -50,12 +57,24 @@ func (c *Config) TagFunc(w io.Writer, tag string) (int, error) {
case "layout":
return w.Write([]byte(c.Layout))
case "urls":
if c.Layout == BaseLayout {
return w.Write([]byte("null"))
}

b, err := json.Marshal(c.Urls)
if err != nil {
return 0, fmt.Errorf("urls: %v", err)
}

return w.Write(b)
case "url":
if c.Layout == BaseLayout {
if len(c.Urls) > 0 {
return w.Write([]byte(c.Urls[0].URL))
}
}

return 0, nil
}

return 0, nil
Expand All @@ -70,7 +89,7 @@ func (c *Config) AddURL(url, name string) *Config {
return c
}

func (c *Config) SetLayout(layout string) *Config {
func (c *Config) SetLayout(layout Layout) *Config {
c.Layout = layout

return c
Expand Down
2 changes: 2 additions & 0 deletions files/config/swagger-initializer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
window.onload = function() {
window.ui = SwaggerUIBundle({
url: "{{url}}",
urls: {{urls}},
dom_id: "#swagger-ui",
deepLinking: true,
Expand All @@ -14,3 +15,4 @@ window.onload = function() {
validatorUrl: null
});
};

0 comments on commit 27ce5ed

Please sign in to comment.