Skip to content

Commit

Permalink
add setting/function to enable/disable syntax highlighting (swaggo#91)
Browse files Browse the repository at this point in the history
* add setting/function to enable/disable syntax highlighting

* adding unit test for SyntaxHighlight setting

Co-authored-by: Kakwa <[email protected]>
  • Loading branch information
kakwa and Kakwa authored Aug 17, 2022
1 parent 717c612 commit 7531e85
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Config struct {
InstanceName string
DeepLinking bool
PersistAuthorization bool
SyntaxHighlight bool

// The information for OAuth2 integration, if any.
OAuth *OAuthConfig
Expand Down Expand Up @@ -54,6 +55,13 @@ func DeepLinking(deepLinking bool) func(*Config) {
}
}

// SyntaxHighlight true, false.
func SyntaxHighlight(syntaxHighlight bool) func(*Config) {
return func(c *Config) {
c.SyntaxHighlight = syntaxHighlight
}
}

// DocExpansion list, full, none.
func DocExpansion(docExpansion string) func(*Config) {
return func(c *Config) {
Expand Down Expand Up @@ -97,6 +105,7 @@ func newConfig(configFns ...func(*Config)) *Config {
InstanceName: "swagger",
DeepLinking: true,
PersistAuthorization: false,
SyntaxHighlight: true,
}

for _, fn := range configFns {
Expand Down Expand Up @@ -257,6 +266,7 @@ window.onload = function() {
// Build a system
const ui = SwaggerUIBundle({
url: "{{.URL}}",
syntaxHighlight: {{.SyntaxHighlight}},
deepLinking: {{.DeepLinking}},
docExpansion: "{{.DocExpansion}}",
persistAuthorization: {{.PersistAuthorization}},
Expand Down
7 changes: 7 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,13 @@ func TestDeepLinking(t *testing.T) {
assert.Equal(t, expected, cfg.DeepLinking)
}

func TestSyntaxHighlight(t *testing.T) {
var cfg Config
expected := true
SyntaxHighlight(expected)(&cfg)
assert.Equal(t, expected, cfg.SyntaxHighlight)
}

func TestDocExpansion(t *testing.T) {
var cfg Config
expected := "https://github.com/swaggo/docs"
Expand Down

0 comments on commit 7531e85

Please sign in to comment.