Skip to content

Commit

Permalink
feat: allow for displaying extensions in the UI (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrukowski authored Aug 15, 2024
1 parent 537f045 commit 3a7ae30
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Config struct {
PersistAuthorization bool
Layout SwaggerLayout
DefaultModelsExpandDepth ModelsExpandDepthType
ShowExtensions bool
}

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

// ShowExtensions controls the display of vendor extension (x-) fields and values for Operations,
// Parameters, Responses, and Schema.
func ShowExtensions(showExtensions bool) func(config *Config) {
return func(c *Config) {
c.ShowExtensions = showExtensions
}
}

func newConfig(configFns ...func(*Config)) *Config {
config := Config{
URL: "doc.json",
Expand All @@ -151,6 +160,7 @@ func newConfig(configFns ...func(*Config)) *Config {
PersistAuthorization: false,
Layout: StandaloneLayout,
DefaultModelsExpandDepth: ShowModel,
ShowExtensions: false,
}

for _, fn := range configFns {
Expand Down Expand Up @@ -321,7 +331,8 @@ window.onload = function() {
{{$k}}: {{$v}},
{{- end}}
layout: "{{$.Layout}}",
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}}
defaultModelsExpandDepth: {{.DefaultModelsExpandDepth}},
showExtensions: {{.ShowExtensions}}
})
window.ui = ui
Expand Down
13 changes: 13 additions & 0 deletions swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,16 @@ func TestDefaultModelsExpandDepth(t *testing.T) {
DefaultModelsExpandDepth(ShowModel)(cfg)
assert.Equal(t, ShowModel, cfg.DefaultModelsExpandDepth)
}

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

cfg = newConfig()
assert.False(t, cfg.ShowExtensions)

cfg = newConfig(ShowExtensions(true))
assert.True(t, cfg.ShowExtensions)

cfg = newConfig(ShowExtensions(false))
assert.False(t, cfg.ShowExtensions)
}

0 comments on commit 3a7ae30

Please sign in to comment.