Skip to content

Commit 7553365

Browse files
committed
fix(http): add default server only after patching
1 parent 342278a commit 7553365

4 files changed

Lines changed: 5 additions & 11 deletions

File tree

providers/openapi/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ func (c *Config) Parse(config *dynamic.Config, reader dynamic.Reader) error {
114114
return nil
115115
}
116116

117-
if len(c.Servers) == 0 {
118-
c.Servers = append(c.Servers, &Server{Url: "/"})
119-
}
120-
121117
config.Scope.OpenIfNeeded(config.Info.Path())
122118

123119
return c.Paths.parse(config, reader)

providers/openapi/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@ func TestConfig_Parse(t *testing.T) {
153153
test func(t *testing.T, config *openapi.Config, err error)
154154
}{
155155
{
156+
// empty server is handled in runtime after patching
156157
name: "empty server",
157158
config: &openapi.Config{},
158159
test: func(t *testing.T, config *openapi.Config, err error) {
159160
require.NoError(t, err)
160-
require.Len(t, config.Servers, 1)
161-
require.Equal(t, "/", config.Servers[0].Url)
161+
require.Len(t, config.Servers, 0)
162162
},
163163
},
164164
{

providers/swagger/convert.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ func (c *converter) Convert() (*openapi.Config, error) {
3030

3131
if len(c.config.Schemes) == 0 {
3232
if len(c.config.Host) == 0 {
33-
if c.config.BasePath == "" {
34-
result.Servers = append(result.Servers, &openapi.Server{Url: "/"})
35-
} else {
33+
if c.config.BasePath != "" {
3634
result.Servers = append(result.Servers, &openapi.Server{Url: c.config.BasePath})
3735
}
3836
} else {

providers/swagger/convert_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ func TestConvert(t *testing.T) {
110110
},
111111
},
112112
{
113+
// empty server is handled in runtime after patching
113114
name: "scheme, host and basePath is empty",
114115
config: `{"swagger": "2.0"}`,
115116
test: func(t *testing.T, config *openapi.Config) {
116-
require.Len(t, config.Servers, 1)
117-
require.Equal(t, "/", config.Servers[0].Url)
117+
require.Len(t, config.Servers, 0)
118118
},
119119
},
120120
{

0 commit comments

Comments
 (0)