From bd3a836bdbbab1ff4c404f6d009e5b8d62ac3708 Mon Sep 17 00:00:00 2001 From: "mayur.popli" Date: Thu, 10 Apr 2025 15:30:02 +0530 Subject: [PATCH 1/3] feat: added contextKeys and domain in schema error --- pkg/plugin/implementation/reqpreprocessor/cmd/plugin.go | 4 ++++ pkg/plugin/implementation/schemavalidator/schemavalidator.go | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/plugin/implementation/reqpreprocessor/cmd/plugin.go b/pkg/plugin/implementation/reqpreprocessor/cmd/plugin.go index 331ec80..e5ae3e2 100644 --- a/pkg/plugin/implementation/reqpreprocessor/cmd/plugin.go +++ b/pkg/plugin/implementation/reqpreprocessor/cmd/plugin.go @@ -3,6 +3,7 @@ package main import ( "context" "net/http" + "strings" "github.com/beckn/beckn-onix/pkg/plugin/implementation/reqpreprocessor" ) @@ -14,6 +15,9 @@ func (p provider) New(ctx context.Context, c map[string]string) (func(http.Handl if role, ok := c["role"]; ok { config.Role = role } + if contextKeys, ok := c["contextKeys"]; ok { + config.ContextKeys = strings.Split(contextKeys, ",") + } return reqpreprocessor.NewPreProcessor(config) } diff --git a/pkg/plugin/implementation/schemavalidator/schemavalidator.go b/pkg/plugin/implementation/schemavalidator/schemavalidator.go index bab2dba..f7e28c5 100644 --- a/pkg/plugin/implementation/schemavalidator/schemavalidator.go +++ b/pkg/plugin/implementation/schemavalidator/schemavalidator.go @@ -78,7 +78,7 @@ func (v *schemaValidator) Validate(ctx context.Context, url *url.URL, data []byt // Retrieve the schema from the cache. schema, exists := v.schemaCache[schemaFileName] if !exists { - return model.NewBadReqErr(errors.New("schema not found for domain")) + return model.NewBadReqErr(errors.New(fmt.Sprintf("schema not found for domain: %s", domain))) } var jsonData any From 949a8d47c3d1d5454199a51927bc7621f9953f17 Mon Sep 17 00:00:00 2001 From: "mayur.popli" Date: Fri, 11 Apr 2025 11:35:48 +0530 Subject: [PATCH 2/3] fix: linting errors --- pkg/plugin/implementation/schemavalidator/schemavalidator.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/plugin/implementation/schemavalidator/schemavalidator.go b/pkg/plugin/implementation/schemavalidator/schemavalidator.go index f7e28c5..5a04a4c 100644 --- a/pkg/plugin/implementation/schemavalidator/schemavalidator.go +++ b/pkg/plugin/implementation/schemavalidator/schemavalidator.go @@ -3,7 +3,6 @@ package schemavalidator import ( "context" "encoding/json" - "errors" "fmt" "net/url" "os" @@ -78,7 +77,7 @@ func (v *schemaValidator) Validate(ctx context.Context, url *url.URL, data []byt // Retrieve the schema from the cache. schema, exists := v.schemaCache[schemaFileName] if !exists { - return model.NewBadReqErr(errors.New(fmt.Sprintf("schema not found for domain: %s", domain))) + return model.NewBadReqErr(fmt.Errorf("schema not found for domain: %s", domain)) } var jsonData any From 37a72d79a3505141067549d238421a9b78cbef84 Mon Sep 17 00:00:00 2001 From: "mayur.popli" Date: Fri, 11 Apr 2025 15:13:29 +0530 Subject: [PATCH 3/3] fix: context keys test case --- .../reqpreprocessor/cmd/plugin_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/plugin/implementation/reqpreprocessor/cmd/plugin_test.go b/pkg/plugin/implementation/reqpreprocessor/cmd/plugin_test.go index 20cc426..cb5c7e6 100644 --- a/pkg/plugin/implementation/reqpreprocessor/cmd/plugin_test.go +++ b/pkg/plugin/implementation/reqpreprocessor/cmd/plugin_test.go @@ -67,6 +67,20 @@ func TestProviderNew(t *testing.T) { req.Header.Set("transaction_id", "test-transaction") }, }, + { + name: "passing the contextKeys", + config: map[string]string{ + "role": "bpp", + "contextKeys": "transaction_id,message_id", + }, + expectedError: false, + expectedStatus: http.StatusOK, + prepareRequest: func(req *http.Request) { + req.Header.Set("context", "test-context") + req.Header.Set("transaction_id", "test-transaction") + req.Header.Set("bpp_id", "bpp1") + }, + }, } for _, tc := range testCases {