Merge pull request #455 from MayurWitsLab/fix/schema_domain
feat: added contextKeys in reqpreprocessor and domain in schema error
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/beckn/beckn-onix/pkg/plugin/implementation/reqpreprocessor"
|
"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 {
|
if role, ok := c["role"]; ok {
|
||||||
config.Role = role
|
config.Role = role
|
||||||
}
|
}
|
||||||
|
if contextKeys, ok := c["contextKeys"]; ok {
|
||||||
|
config.ContextKeys = strings.Split(contextKeys, ",")
|
||||||
|
}
|
||||||
return reqpreprocessor.NewPreProcessor(config)
|
return reqpreprocessor.NewPreProcessor(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,20 @@ func TestProviderNew(t *testing.T) {
|
|||||||
req.Header.Set("transaction_id", "test-transaction")
|
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 {
|
for _, tc := range testCases {
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package schemavalidator
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -78,7 +77,7 @@ func (v *schemaValidator) Validate(ctx context.Context, url *url.URL, data []byt
|
|||||||
// Retrieve the schema from the cache.
|
// Retrieve the schema from the cache.
|
||||||
schema, exists := v.schemaCache[schemaFileName]
|
schema, exists := v.schemaCache[schemaFileName]
|
||||||
if !exists {
|
if !exists {
|
||||||
return model.NewBadReqErr(errors.New("schema not found for domain"))
|
return model.NewBadReqErr(fmt.Errorf("schema not found for domain: %s", domain))
|
||||||
}
|
}
|
||||||
|
|
||||||
var jsonData any
|
var jsonData any
|
||||||
|
|||||||
Reference in New Issue
Block a user