feat: enable customization of HTML title (#180)
This commit is contained in:
parent
301224e3df
commit
74c905c98f
|
|
@ -20,6 +20,7 @@ type swaggerConfig struct {
|
||||||
DocExpansion string
|
DocExpansion string
|
||||||
DefaultModelsExpandDepth int
|
DefaultModelsExpandDepth int
|
||||||
Oauth2RedirectURL template.JS
|
Oauth2RedirectURL template.JS
|
||||||
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config stores ginSwagger configuration variables.
|
// Config stores ginSwagger configuration variables.
|
||||||
|
|
@ -30,6 +31,7 @@ type Config struct {
|
||||||
DocExpansion string
|
DocExpansion string
|
||||||
DefaultModelsExpandDepth int
|
DefaultModelsExpandDepth int
|
||||||
InstanceName string
|
InstanceName string
|
||||||
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the config to a swagger one in order to fill unexposed template values.
|
// Convert the config to a swagger one in order to fill unexposed template values.
|
||||||
|
|
@ -44,6 +46,7 @@ func (c Config) ToSwaggerConfig() swaggerConfig {
|
||||||
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
|
"{window.location.pathname.split('/').slice(0, window.location.pathname.split('/').length - 1).join('/')}" +
|
||||||
"/oauth2-redirect.html`",
|
"/oauth2-redirect.html`",
|
||||||
),
|
),
|
||||||
|
Title: c.Title,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -92,6 +95,7 @@ func WrapHandler(h *webdav.Handler, confs ...func(c *Config)) gin.HandlerFunc {
|
||||||
DocExpansion: "list",
|
DocExpansion: "list",
|
||||||
DefaultModelsExpandDepth: 1,
|
DefaultModelsExpandDepth: 1,
|
||||||
InstanceName: swag.Name,
|
InstanceName: swag.Name,
|
||||||
|
Title: "Swagger UI",
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range confs {
|
for _, c := range confs {
|
||||||
|
|
@ -108,6 +112,9 @@ func CustomWrapHandler(config *Config, handler *webdav.Handler) gin.HandlerFunc
|
||||||
if config.InstanceName == "" {
|
if config.InstanceName == "" {
|
||||||
config.InstanceName = swag.Name
|
config.InstanceName = swag.Name
|
||||||
}
|
}
|
||||||
|
if config.Title == "" {
|
||||||
|
config.Title = "Swagger UI"
|
||||||
|
}
|
||||||
|
|
||||||
// create a template with name
|
// create a template with name
|
||||||
t := template.New("swagger_index.html")
|
t := template.New("swagger_index.html")
|
||||||
|
|
@ -194,7 +201,7 @@ const swagger_index_templ = `<!-- HTML for static distribution bundle build -->
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Swagger UI</title>
|
<title>{{.Title}}</title>
|
||||||
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700" rel="stylesheet">
|
||||||
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
<link rel="stylesheet" type="text/css" href="./swagger-ui.css" >
|
||||||
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
<link rel="icon" type="image/png" href="./favicon-32x32.png" sizes="32x32" />
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue