Skip to content

Commit

Permalink
feat: option to chose for swagger layout (#87)
Browse files Browse the repository at this point in the history
* Creating Method to modify the layout

* Fixing spacing
  • Loading branch information
felipe0328 committed Mar 3, 2023
1 parent c8d62bf commit 1f40b78
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion swagger.go
Expand Up @@ -27,6 +27,7 @@ type Config struct {
UIConfig map[template.JS]template.JS
DeepLinking bool
PersistAuthorization bool
Layout string
}

// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
Expand Down Expand Up @@ -110,6 +111,19 @@ func AfterScript(js string) func(*Config) {
}
}

type Layouts string
const (
BaseLayout Layouts = "BaseLayout"
StandaloneLayout Layouts = "StandaloneLayout"
)

// Define Layout options are BaseLayout or StandaloneLayout
func Layout(layout Layouts) func(*Config) {
return func(c *Config) {
c.Layout = string(layout)
}
}

func newConfig(configFns ...func(*Config)) *Config {
config := Config{
URL: "doc.json",
Expand All @@ -118,6 +132,7 @@ func newConfig(configFns ...func(*Config)) *Config {
InstanceName: "swagger",
DeepLinking: true,
PersistAuthorization: false,
Layout: string(StandaloneLayout),
}

for _, fn := range configFns {
Expand Down Expand Up @@ -285,7 +300,7 @@ window.onload = function() {
{{- range $k, $v := .UIConfig}}
{{$k}}: {{$v}},
{{- end}}
layout: "StandaloneLayout"
layout: "{{$.Layout}}"
})
window.ui = ui
Expand Down

0 comments on commit 1f40b78

Please sign in to comment.