diff --git a/apidef/oas/middleware.go b/apidef/oas/middleware.go index 11b532f7e14..ccc4871a050 100644 --- a/apidef/oas/middleware.go +++ b/apidef/oas/middleware.go @@ -414,6 +414,7 @@ func (g *Global) extractResponsePluginsTo(api *apidef.APIDefinition) { if g.ResponsePlugins != nil { api.CustomMiddleware.Response = make([]apidef.MiddlewareDefinition, len(g.ResponsePlugins)) g.ResponsePlugins.ExtractTo(api.CustomMiddleware.Response) + return } if g.ResponsePlugin == nil { diff --git a/apidef/oas/middleware_test.go b/apidef/oas/middleware_test.go index e843266ff71..96578b53359 100644 --- a/apidef/oas/middleware_test.go +++ b/apidef/oas/middleware_test.go @@ -29,6 +29,7 @@ func TestMiddleware(t *testing.T) { Path: "/path", }, } + var pluginMW = Middleware{ Global: &Global{ PrePlugin: &PrePlugin{ @@ -71,6 +72,61 @@ func TestMiddleware(t *testing.T) { } assert.Equal(t, expectedMW, resultMiddleware) }) + + t.Run("response plugins", func(t *testing.T) { + customPlugins := CustomPlugins{ + CustomPlugin{ + Enabled: true, + FunctionName: "func1", + Path: "/path1", + }, + } + + responsePlugins := CustomPlugins{ + CustomPlugin{ + Enabled: true, + FunctionName: "func2", + Path: "/path2", + }, + CustomPlugin{ + Enabled: true, + FunctionName: "func3", + Path: "/path3", + }, + } + + var pluginMW = Middleware{ + Global: &Global{ + ResponsePlugin: &ResponsePlugin{ + Plugins: customPlugins, + }, + ResponsePlugins: responsePlugins, + }, + } + + var convertedAPI apidef.APIDefinition + convertedAPI.SetDisabledFlags() + + pluginMW.ExtractTo(&convertedAPI) + + // regression https://tyktech.atlassian.net/browse/TT-12762 + assert.Equal(t, len(responsePlugins), len(convertedAPI.CustomMiddleware.Response)) + + var resultMiddleware = Middleware{ + Global: &Global{ + ResponsePlugin: &ResponsePlugin{}, + }, + } + resultMiddleware.Fill(convertedAPI) + + expectedMW := Middleware{ + Global: &Global{ + ResponsePlugins: responsePlugins, + }, + } + + assert.Equal(t, expectedMW, resultMiddleware) + }) } func TestGlobal(t *testing.T) { diff --git a/main b/main new file mode 100755 index 00000000000..fc29789e6a4 Binary files /dev/null and b/main differ