Skip to content

Commit 7531e85

Browse files
kakwaKakwa
andauthored
add setting/function to enable/disable syntax highlighting (#91)
* add setting/function to enable/disable syntax highlighting * adding unit test for SyntaxHighlight setting Co-authored-by: Kakwa <[email protected]>
1 parent 717c612 commit 7531e85

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

swagger.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type Config struct {
2222
InstanceName string
2323
DeepLinking bool
2424
PersistAuthorization bool
25+
SyntaxHighlight bool
2526

2627
// The information for OAuth2 integration, if any.
2728
OAuth *OAuthConfig
@@ -54,6 +55,13 @@ func DeepLinking(deepLinking bool) func(*Config) {
5455
}
5556
}
5657

58+
// SyntaxHighlight true, false.
59+
func SyntaxHighlight(syntaxHighlight bool) func(*Config) {
60+
return func(c *Config) {
61+
c.SyntaxHighlight = syntaxHighlight
62+
}
63+
}
64+
5765
// DocExpansion list, full, none.
5866
func DocExpansion(docExpansion string) func(*Config) {
5967
return func(c *Config) {
@@ -97,6 +105,7 @@ func newConfig(configFns ...func(*Config)) *Config {
97105
InstanceName: "swagger",
98106
DeepLinking: true,
99107
PersistAuthorization: false,
108+
SyntaxHighlight: true,
100109
}
101110

102111
for _, fn := range configFns {
@@ -257,6 +266,7 @@ window.onload = function() {
257266
// Build a system
258267
const ui = SwaggerUIBundle({
259268
url: "{{.URL}}",
269+
syntaxHighlight: {{.SyntaxHighlight}},
260270
deepLinking: {{.DeepLinking}},
261271
docExpansion: "{{.DocExpansion}}",
262272
persistAuthorization: {{.PersistAuthorization}},

swagger_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,13 @@ func TestDeepLinking(t *testing.T) {
374374
assert.Equal(t, expected, cfg.DeepLinking)
375375
}
376376

377+
func TestSyntaxHighlight(t *testing.T) {
378+
var cfg Config
379+
expected := true
380+
SyntaxHighlight(expected)(&cfg)
381+
assert.Equal(t, expected, cfg.SyntaxHighlight)
382+
}
383+
377384
func TestDocExpansion(t *testing.T) {
378385
var cfg Config
379386
expected := "https://github.com/swaggo/docs"

0 commit comments

Comments
 (0)