Skip to content

Commit 3a7ae30

Browse files
authored
feat: allow for displaying extensions in the UI (#118)
1 parent 537f045 commit 3a7ae30

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

swagger.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type Config struct {
2929
PersistAuthorization bool
3030
Layout SwaggerLayout
3131
DefaultModelsExpandDepth ModelsExpandDepthType
32+
ShowExtensions bool
3233
}
3334

3435
// URL presents the url pointing to API definition (normally swagger.json or swagger.yaml).
@@ -141,6 +142,14 @@ func DefaultModelsExpandDepth(defaultModelsExpandDepth ModelsExpandDepthType) fu
141142
}
142143
}
143144

145+
// ShowExtensions controls the display of vendor extension (x-) fields and values for Operations,
146+
// Parameters, Responses, and Schema.
147+
func ShowExtensions(showExtensions bool) func(config *Config) {
148+
return func(c *Config) {
149+
c.ShowExtensions = showExtensions
150+
}
151+
}
152+
144153
func newConfig(configFns ...func(*Config)) *Config {
145154
config := Config{
146155
URL: "doc.json",
@@ -151,6 +160,7 @@ func newConfig(configFns ...func(*Config)) *Config {
151160
PersistAuthorization: false,
152161
Layout: StandaloneLayout,
153162
DefaultModelsExpandDepth: ShowModel,
163+
ShowExtensions: false,
154164
}
155165

156166
for _, fn := range configFns {
@@ -321,7 +331,8 @@ window.onload = function() {
321331
{{$k}}: {{$v}},
322332
{{- end}}
323333
layout: "{{$.Layout}}",
324-
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
334+
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
335+
showExtensions: {{.ShowExtensions}}
325336
})
326337
327338
window.ui = ui

swagger_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,16 @@ func TestDefaultModelsExpandDepth(t *testing.T) {
559559
DefaultModelsExpandDepth(ShowModel)(cfg)
560560
assert.Equal(t, ShowModel, cfg.DefaultModelsExpandDepth)
561561
}
562+
563+
func TestShowExtensions(t *testing.T) {
564+
var cfg *Config
565+
566+
cfg = newConfig()
567+
assert.False(t, cfg.ShowExtensions)
568+
569+
cfg = newConfig(ShowExtensions(true))
570+
assert.True(t, cfg.ShowExtensions)
571+
572+
cfg = newConfig(ShowExtensions(false))
573+
assert.False(t, cfg.ShowExtensions)
574+
}

0 commit comments

Comments
 (0)