Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
DocExpansion string
DomID string
InstanceName string
IndexTemplate string
DeepLinking bool
PersistAuthorization bool
SyntaxHighlight bool
Expand Down Expand Up @@ -82,6 +83,13 @@ func InstanceName(instanceName string) func(*Config) {
}
}

// IndexTemplate overrides default index template
func IndexTemplate(indexTemplate string) func(*Config) {
return func(c *Config) {
c.IndexTemplate = indexTemplate
}
}

// PersistAuthorization Persist authorization information over browser close/refresh.
// Defaults to false.
func PersistAuthorization(persistAuthorization bool) func(*Config) {
Expand All @@ -102,6 +110,7 @@ func newConfig(configFns ...func(*Config)) *Config {
DocExpansion: "list",
DomID: "swagger-ui",
InstanceName: "swagger",
IndexTemplate: indexTemplate,
DeepLinking: true,
PersistAuthorization: false,
SyntaxHighlight: true,
Expand All @@ -126,9 +135,9 @@ func EchoWrapHandler(options ...func(*Config)) echo.HandlerFunc {
config := newConfig(options...)

// create a template with name
index, _ := template.New("swagger_index.html").Parse(indexTemplate)
index, _ := template.New("swagger_index.html").Parse(config.IndexTemplate)

var re = regexp.MustCompile(`^(.*/)([^?].*)?[?|.]*$`)
re := regexp.MustCompile(`^(.*/)([^?].*)?[?|.]*$`)

return func(c echo.Context) error {
if c.Request().Method != http.MethodGet {
Expand Down
9 changes: 8 additions & 1 deletion swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ func TestWrapHandler(t *testing.T) {
assert.Equal(t, http.StatusMethodNotAllowed, performRequest(http.MethodPost, "/index.html", router).Code)

assert.Equal(t, http.StatusMethodNotAllowed, performRequest(http.MethodPut, "/index.html", router).Code)

}

func TestConfig(t *testing.T) {
Expand Down Expand Up @@ -406,6 +405,14 @@ func TestInstanceName(t *testing.T) {
assert.Equal(t, swag.Name, newCfg.InstanceName)
}

func TestIndexTemplate(t *testing.T) {
var cfg Config

expected := "custom-index-template"
IndexTemplate(expected)(&cfg)
assert.Equal(t, expected, cfg.IndexTemplate)
}

func TestPersistAuthorization(t *testing.T) {
var cfg Config
expected := true
Expand Down