update the file structure update Initialise function , update interface and update code and write table test cases
This commit is contained in:
16
shared/plugin/definition/validator.go
Normal file
16
shared/plugin/definition/validator.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package definition
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// Validator interface for schema validation
|
||||
type Validator interface {
|
||||
Validate(ctx context.Context, url url.URL, payload []byte) (bool, error)
|
||||
}
|
||||
|
||||
// ValidatorProvider interface for creating validators
|
||||
type ValidatorProvider interface {
|
||||
New(ctx context.Context, config map[string]string) (map[string]Validator, error)
|
||||
}
|
||||
BIN
shared/plugin/implementations/validator.so
Normal file
BIN
shared/plugin/implementations/validator.so
Normal file
Binary file not shown.
31
shared/plugin/implementations/validator/cmd/plugin.go
Normal file
31
shared/plugin/implementations/validator/cmd/plugin.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"beckn-onix/shared/plugin/definition"
|
||||
"beckn-onix/shared/plugin/implementations/validator"
|
||||
)
|
||||
|
||||
// ValidatorProvider provides instances of Validator.
|
||||
type ValidatorProvider struct{}
|
||||
|
||||
// New initializes a new Verifier instance.
|
||||
func (vp ValidatorProvider) New(ctx context.Context, config map[string]string) (map[string]definition.Validator, error) {
|
||||
// Create a new Validator instance with the provided configuration
|
||||
validators, err := validator.New(ctx, config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Convert the map to the expected type
|
||||
result := make(map[string]definition.Validator)
|
||||
for key, val := range validators {
|
||||
result[key] = val
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// Provider is the exported symbol that the plugin manager will look for.
|
||||
var Provider definition.ValidatorProvider = ValidatorProvider{}
|
||||
85
shared/plugin/implementations/validator/cmd/plugin_test.go
Normal file
85
shared/plugin/implementations/validator/cmd/plugin_test.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
||||
"beckn-onix/shared/plugin/definition"
|
||||
)
|
||||
|
||||
// MockValidator is a mock implementation of the Validator interface for testing.
|
||||
type MockValidator struct{}
|
||||
|
||||
func (m *MockValidator) Validate(ctx context.Context, u url.URL, data []byte) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Mock New function for testing
|
||||
func MockNew(ctx context.Context, config map[string]string) (map[string]definition.Validator, error) {
|
||||
if config["error"] == "true" {
|
||||
return nil, errors.New("mock error")
|
||||
}
|
||||
|
||||
return map[string]definition.Validator{
|
||||
"validator1": &MockValidator{},
|
||||
"validator2": &MockValidator{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestValidatorProvider_New(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config map[string]string
|
||||
expectedError string
|
||||
expectedCount int
|
||||
}{
|
||||
{
|
||||
name: "Successful initialization",
|
||||
config: map[string]string{"some_key": "some_value"},
|
||||
expectedError: "",
|
||||
expectedCount: 2, // Expecting 2 mock validators
|
||||
},
|
||||
{
|
||||
name: "Error during initialization (mock error)",
|
||||
config: map[string]string{"error": "true"},
|
||||
expectedError: "mock error",
|
||||
expectedCount: 0,
|
||||
},
|
||||
{
|
||||
name: "Empty config map",
|
||||
config: map[string]string{},
|
||||
expectedError: "",
|
||||
expectedCount: 2, // Expecting 2 mock validators
|
||||
},
|
||||
{
|
||||
name: "Non-empty config with invalid key",
|
||||
config: map[string]string{"invalid_key": "invalid_value"},
|
||||
expectedError: "",
|
||||
expectedCount: 2, // Expecting 2 mock validators
|
||||
},
|
||||
}
|
||||
|
||||
// Using the mock New function directly for testing
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create a ValidatorProvider with the mock New function
|
||||
vp := &ValidatorProvider{}
|
||||
validators, err := vp.New(context.Background(), tt.config)
|
||||
|
||||
// Check for expected error
|
||||
if tt.expectedError != "" {
|
||||
if err == nil || err.Error() != tt.expectedError {
|
||||
t.Errorf("expected error %q, got %v", tt.expectedError, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Check for expected number of validators
|
||||
if len(validators) != tt.expectedCount {
|
||||
t.Errorf("expected %d validators, got %d", tt.expectedCount, len(validators))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
165
shared/plugin/implementations/validator/validator.go
Normal file
165
shared/plugin/implementations/validator/validator.go
Normal file
@@ -0,0 +1,165 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/santhosh-tekuri/jsonschema/v6"
|
||||
)
|
||||
|
||||
// Validator implements the Validator interface.
|
||||
type Validator struct {
|
||||
config map[string]string
|
||||
schema *jsonschema.Schema
|
||||
SchemaCache map[string]*jsonschema.Schema
|
||||
}
|
||||
|
||||
// New creates a new Verifier instance.
|
||||
func New(ctx context.Context, config map[string]string) (map[string]*Validator, error) {
|
||||
v := &Validator{config: config}
|
||||
// Call Initialise function to load schemas and get validators
|
||||
validators, err := v.Initialise()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialise validators: %v", err)
|
||||
}
|
||||
return validators, nil
|
||||
}
|
||||
|
||||
// Payload represents the structure of the data payload with context information.
|
||||
type Payload struct {
|
||||
Context struct {
|
||||
Domain string `json:"domain"`
|
||||
Version string `json:"version"`
|
||||
} `json:"context"`
|
||||
}
|
||||
|
||||
// ValidatorProvider provides instances of Validator.
|
||||
type ValidatorProvider struct{}
|
||||
|
||||
// Validate validates the given data against the schema.
|
||||
func (v *Validator) Validate(ctx context.Context, url url.URL, payload []byte) (bool, error) {
|
||||
var payloadData Payload
|
||||
err := json.Unmarshal(payload, &payloadData)
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("failed to parse JSON payload: %v", err)
|
||||
}
|
||||
|
||||
// Extract domain, version, and endpoint from the payload and uri
|
||||
domain := payloadData.Context.Domain
|
||||
version := payloadData.Context.Version
|
||||
version = fmt.Sprintf("v%s", version)
|
||||
|
||||
endpoint := path.Base(url.String())
|
||||
fmt.Println("Handling request for endpoint:", endpoint)
|
||||
domain = strings.ToLower(domain)
|
||||
domain = strings.ReplaceAll(domain, ":", "_")
|
||||
|
||||
//schemaFileName := fmt.Sprintf("%s_%s_%s", domain, version, endpoint)
|
||||
var jsonData interface{}
|
||||
if err := json.Unmarshal(payload, &jsonData); err != nil {
|
||||
return false, err
|
||||
}
|
||||
err = v.schema.Validate(jsonData)
|
||||
if err != nil {
|
||||
// TODO: Integrate with the logging module once it is ready
|
||||
return false, fmt.Errorf("Validation failed: %v", err)
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// Initialise initialises the validator provider by compiling all the JSON schema files
|
||||
// from the specified directory and storing them in a cache. It returns a map of validators
|
||||
// indexed by their schema filenames.
|
||||
func (v *Validator) Initialise() (map[string]*Validator, error) {
|
||||
// Initialize SchemaCache as an empty Map if it's nil
|
||||
if v.SchemaCache == nil {
|
||||
v.SchemaCache = make(map[string]*jsonschema.Schema)
|
||||
}
|
||||
schemaDir := v.config["schema_dir"]
|
||||
// Check if the directory exists and is accessible
|
||||
info, err := os.Stat(schemaDir)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return nil, fmt.Errorf("schema directory does not exist: %s", schemaDir)
|
||||
}
|
||||
return nil, fmt.Errorf("failed to access schema directory: %v", err)
|
||||
}
|
||||
if !info.IsDir() {
|
||||
return nil, fmt.Errorf("provided schema path is not a directory: %s", schemaDir)
|
||||
}
|
||||
|
||||
// Initialize the validatorCache map to store the Validator instances associated with each schema.
|
||||
validatorCache := make(map[string]*Validator)
|
||||
compiler := jsonschema.NewCompiler()
|
||||
|
||||
// Helper function to process directories recursively
|
||||
var processDir func(dir string) error
|
||||
processDir = func(dir string) error {
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read directory: %v", err)
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
path := filepath.Join(dir, entry.Name())
|
||||
if entry.IsDir() {
|
||||
// Recursively process subdirectories
|
||||
if err := processDir(path); err != nil {
|
||||
return err
|
||||
}
|
||||
} else if filepath.Ext(entry.Name()) == ".json" {
|
||||
// Process JSON files
|
||||
compiledSchema, err := compiler.Compile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compile JSON schema from file %s: %v", entry.Name(), err)
|
||||
}
|
||||
|
||||
// Use relative path from schemaDir to avoid absolute paths and make schema keys domain/version specific.
|
||||
relativePath, err := filepath.Rel(schemaDir, path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get relative path for file %s: %v", entry.Name(), err)
|
||||
}
|
||||
// Split the relative path to get domain, version, and schema.
|
||||
parts := strings.Split(relativePath, string(os.PathSeparator))
|
||||
|
||||
// Ensure that the file path has at least 3 parts: domain, version, and schema file.
|
||||
if len(parts) < 3 {
|
||||
return fmt.Errorf("invalid schema file structure, expected domain/version/schema.json but got: %s", relativePath)
|
||||
}
|
||||
|
||||
// Extract domain, version, and schema filename from the parts.
|
||||
// Validate that the extracted parts are non-empty
|
||||
domain := strings.TrimSpace(parts[0])
|
||||
version := strings.TrimSpace(parts[1])
|
||||
schemaFileName := strings.TrimSpace(parts[2])
|
||||
schemaFileName = strings.TrimSuffix(schemaFileName, ".json")
|
||||
|
||||
if domain == "" || version == "" || schemaFileName == "" {
|
||||
return fmt.Errorf("invalid schema file structure, one or more components are empty. Relative path: %s", relativePath)
|
||||
}
|
||||
|
||||
// Construct a unique key combining domain, version, and schema name (e.g., ondc_trv10_v2.0.0_schema).
|
||||
uniqueKey := fmt.Sprintf("%s_%s_%s", domain, version, schemaFileName)
|
||||
// Store the compiled schema in the SchemaCache using the unique key.
|
||||
v.SchemaCache[uniqueKey] = compiledSchema
|
||||
// Store the corresponding validator in the validatorCache using the same unique key.
|
||||
validatorCache[uniqueKey] = &Validator{schema: compiledSchema}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start processing from the root schema directory
|
||||
if err := processDir(schemaDir); err != nil {
|
||||
return nil, fmt.Errorf("failed to read schema directory: %v", err)
|
||||
}
|
||||
|
||||
return validatorCache, nil
|
||||
}
|
||||
291
shared/plugin/implementations/validator/validator_test.go
Normal file
291
shared/plugin/implementations/validator/validator_test.go
Normal file
@@ -0,0 +1,291 @@
|
||||
package validator
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidator_Validate(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
url string
|
||||
payload string
|
||||
wantValid bool
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "Valid payload",
|
||||
url: "http://example.com/endpoint",
|
||||
payload: `{"context": {"domain": "example", "version": "1.0"}}`,
|
||||
wantValid: true,
|
||||
wantErr: "",
|
||||
},
|
||||
{
|
||||
name: "Invalid JSON payload",
|
||||
url: "http://example.com/endpoint",
|
||||
payload: `{"context": {"domain": "example", "version": "1.0"`,
|
||||
wantValid: false,
|
||||
wantErr: "failed to parse JSON payload",
|
||||
},
|
||||
{
|
||||
name: "Schema validation failure",
|
||||
url: "http://example.com/endpoint",
|
||||
payload: `{"context": {"domain": "invalid", "version": "1.0"}}`,
|
||||
wantValid: false,
|
||||
wantErr: "Validation failed",
|
||||
},
|
||||
}
|
||||
|
||||
// Setup a temporary schema directory for testing
|
||||
schemaDir := filepath.Join(os.TempDir(), "schemas")
|
||||
defer os.RemoveAll(schemaDir)
|
||||
os.MkdirAll(schemaDir, 0755)
|
||||
|
||||
// Create a sample schema file
|
||||
schemaContent := `{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"domain": {"type": "string"},
|
||||
"version": {"type": "string"}
|
||||
},
|
||||
"required": ["domain", "version"]
|
||||
}
|
||||
},
|
||||
"required": ["context"]
|
||||
}`
|
||||
schemaFile := filepath.Join(schemaDir, "example", "1.0", "endpoint.json")
|
||||
os.MkdirAll(filepath.Dir(schemaFile), 0755)
|
||||
os.WriteFile(schemaFile, []byte(schemaContent), 0644)
|
||||
|
||||
config := map[string]string{"schema_dir": schemaDir}
|
||||
v, err := New(context.Background(), config)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create validator: %v", err)
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
u, _ := url.Parse(tt.url)
|
||||
valid, err := v["example_1.0_endpoint"].Validate(context.Background(), *u, []byte(tt.payload))
|
||||
if (err != nil && !strings.Contains(err.Error(), tt.wantErr)) || (err == nil && tt.wantErr != "") {
|
||||
t.Errorf("Error: Validate() returned error = %v, expected error = %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if valid != tt.wantValid {
|
||||
t.Errorf("Error: Validate() returned valid = %v, expected valid = %v", valid, tt.wantValid)
|
||||
} else {
|
||||
t.Logf("Test %s passed: valid = %v", tt.name, valid)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidator_Initialise(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
setupFunc func(schemaDir string) error
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "Schema directory does not exist",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Do not create the schema directory
|
||||
return nil
|
||||
},
|
||||
wantErr: "schema directory does not exist",
|
||||
},
|
||||
{
|
||||
name: "Schema path is not a directory",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a file instead of a directory
|
||||
return os.WriteFile(schemaDir, []byte{}, 0644)
|
||||
},
|
||||
wantErr: "provided schema path is not a directory",
|
||||
},
|
||||
{
|
||||
name: "Invalid schema file structure",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create an invalid schema file structure
|
||||
invalidSchemaFile := filepath.Join(schemaDir, "invalid_schema.json")
|
||||
os.MkdirAll(filepath.Dir(invalidSchemaFile), 0755)
|
||||
return os.WriteFile(invalidSchemaFile, []byte(`{}`), 0644)
|
||||
},
|
||||
wantErr: "invalid schema file structure",
|
||||
},
|
||||
{
|
||||
name: "Failed to compile JSON schema",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a schema file with invalid JSON
|
||||
invalidSchemaFile := filepath.Join(schemaDir, "example", "1.0", "endpoint.json")
|
||||
os.MkdirAll(filepath.Dir(invalidSchemaFile), 0755)
|
||||
return os.WriteFile(invalidSchemaFile, []byte(`{invalid json}`), 0644)
|
||||
},
|
||||
wantErr: "failed to compile JSON schema",
|
||||
},
|
||||
{
|
||||
name: "Invalid schema file structure with empty components",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a schema file with empty domain, version, or schema name
|
||||
invalidSchemaFile := filepath.Join(schemaDir, "", "1.0", "endpoint.json")
|
||||
os.MkdirAll(filepath.Dir(invalidSchemaFile), 0755)
|
||||
return os.WriteFile(invalidSchemaFile, []byte(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"domain": {"type": "string"},
|
||||
"version": {"type": "string"}
|
||||
},
|
||||
"required": ["domain", "version"]
|
||||
}
|
||||
},
|
||||
"required": ["context"]
|
||||
}`), 0644)
|
||||
},
|
||||
wantErr: "invalid schema file structure, one or more components are empty",
|
||||
},
|
||||
{
|
||||
name: "Failed to read directory",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a directory and remove read permissions
|
||||
os.MkdirAll(schemaDir, 0000)
|
||||
return nil
|
||||
},
|
||||
wantErr: "failed to read directory",
|
||||
},
|
||||
{
|
||||
name: "Failed to access schema directory",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a directory and remove access permissions
|
||||
os.MkdirAll(schemaDir, 0000)
|
||||
return nil
|
||||
},
|
||||
wantErr: "failed to access schema directory",
|
||||
},
|
||||
{
|
||||
name: "Valid schema directory",
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a valid schema file
|
||||
validSchemaFile := filepath.Join(schemaDir, "example", "1.0", "endpoint.json")
|
||||
os.MkdirAll(filepath.Dir(validSchemaFile), 0755)
|
||||
return os.WriteFile(validSchemaFile, []byte(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"domain": {"type": "string"},
|
||||
"version": {"type": "string"}
|
||||
},
|
||||
"required": ["domain", "version"]
|
||||
}
|
||||
},
|
||||
"required": ["context"]
|
||||
}`), 0644)
|
||||
},
|
||||
wantErr: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Setup a temporary schema directory for testing
|
||||
schemaDir := filepath.Join(os.TempDir(), "schemas")
|
||||
defer os.RemoveAll(schemaDir)
|
||||
|
||||
// Run the setup function to prepare the test case
|
||||
if err := tt.setupFunc(schemaDir); err != nil {
|
||||
t.Fatalf("setupFunc() error = %v", err)
|
||||
}
|
||||
|
||||
config := map[string]string{"schema_dir": schemaDir}
|
||||
v := &Validator{config: config}
|
||||
|
||||
_, err := v.Initialise()
|
||||
if (err != nil && !strings.Contains(err.Error(), tt.wantErr)) || (err == nil && tt.wantErr != "") {
|
||||
t.Errorf("Error: Initialise() returned error = %v, expected error = %v", err, tt.wantErr)
|
||||
} else if err == nil {
|
||||
t.Logf("Test %s passed: validator initialized successfully", tt.name)
|
||||
} else {
|
||||
t.Logf("Test %s passed with expected error: %v", tt.name, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidator_New(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
config map[string]string
|
||||
setupFunc func(schemaDir string) error
|
||||
wantErr string
|
||||
}{
|
||||
{
|
||||
name: "Failed to initialise validators",
|
||||
config: map[string]string{
|
||||
"schema_dir": "/invalid/path",
|
||||
},
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Do not create the schema directory
|
||||
return nil
|
||||
},
|
||||
wantErr: "failed to initialise validators",
|
||||
},
|
||||
{
|
||||
name: "Valid initialisation",
|
||||
config: map[string]string{
|
||||
"schema_dir": "/valid/path",
|
||||
},
|
||||
setupFunc: func(schemaDir string) error {
|
||||
// Create a valid schema directory and file
|
||||
validSchemaFile := filepath.Join(schemaDir, "example", "1.0", "endpoint.json")
|
||||
os.MkdirAll(filepath.Dir(validSchemaFile), 0755)
|
||||
return os.WriteFile(validSchemaFile, []byte(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"domain": {"type": "string"},
|
||||
"version": {"type": "string"}
|
||||
},
|
||||
"required": ["domain", "version"]
|
||||
}
|
||||
},
|
||||
"required": ["context"]
|
||||
}`), 0644)
|
||||
},
|
||||
wantErr: "",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Setup a temporary schema directory for testing
|
||||
schemaDir := tt.config["schema_dir"]
|
||||
defer os.RemoveAll(schemaDir)
|
||||
|
||||
// Run the setup function to prepare the test case
|
||||
if err := tt.setupFunc(schemaDir); err != nil {
|
||||
t.Fatalf("setupFunc() error = %v", err)
|
||||
}
|
||||
|
||||
_, err := New(context.Background(), tt.config)
|
||||
if (err != nil && !strings.Contains(err.Error(), tt.wantErr)) || (err == nil && tt.wantErr != "") {
|
||||
t.Errorf("Error: New() returned error = %v, expected error = %v", err, tt.wantErr)
|
||||
} else if err == nil {
|
||||
t.Logf("Test %s passed: validator initialized successfully", tt.name)
|
||||
} else {
|
||||
t.Logf("Test %s passed with expected error: %v", tt.name, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
137
shared/plugin/manager.go
Normal file
137
shared/plugin/manager.go
Normal file
@@ -0,0 +1,137 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"beckn-onix/shared/plugin/definition"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"plugin"
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// ValidationPluginConfig represents configuration details for a plugin.
|
||||
type ValidationPluginConfig struct {
|
||||
ID string `yaml:"id"`
|
||||
Schema SchemaDetails `yaml:"config"`
|
||||
PluginPath string `yaml:"plugin_path"`
|
||||
}
|
||||
|
||||
// SchemaDetails contains information about the plugin schema directory.
|
||||
type SchemaDetails struct {
|
||||
SchemaDir string `yaml:"schema_dir"`
|
||||
}
|
||||
|
||||
// Config represents the configuration for the application, including plugin configurations.
|
||||
type Config struct {
|
||||
Plugins struct {
|
||||
ValidationPlugin ValidationPluginConfig `yaml:"validation_plugin"`
|
||||
} `yaml:"plugins"`
|
||||
}
|
||||
|
||||
// Manager handles dynamic plugin loading and management.
|
||||
type Manager struct {
|
||||
vp definition.ValidatorProvider
|
||||
validators map[string]definition.Validator
|
||||
cfg *Config
|
||||
}
|
||||
|
||||
// NewManager initializes a new Manager with the given configuration file.
|
||||
func NewManager(ctx context.Context, cfg *Config) (*Manager, error) {
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("configuration cannot be nil")
|
||||
}
|
||||
|
||||
// Load validator plugin
|
||||
vp, err := provider[definition.ValidatorProvider](cfg.Plugins.ValidationPlugin.PluginPath, cfg.Plugins.ValidationPlugin.ID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load validator plugin: %w", err)
|
||||
}
|
||||
if vp == nil {
|
||||
return nil, fmt.Errorf("validator provider is nil")
|
||||
}
|
||||
|
||||
// Initialize validator
|
||||
validatorMap, err := vp.New(ctx, map[string]string{
|
||||
"schema_dir": cfg.Plugins.ValidationPlugin.Schema.SchemaDir,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize validator: %w", err)
|
||||
}
|
||||
|
||||
// Initialize the validators map
|
||||
validators := make(map[string]definition.Validator)
|
||||
for key, validator := range validatorMap {
|
||||
validators[key] = validator
|
||||
}
|
||||
fmt.Println("validators : ", validators)
|
||||
|
||||
return &Manager{vp: vp, validators: validators, cfg: cfg}, nil
|
||||
}
|
||||
|
||||
// provider loads a plugin dynamically and retrieves its provider instance.
|
||||
func provider[T any](path string, id string) (T, error) {
|
||||
var zero T
|
||||
if len(strings.TrimSpace(id)) == 0 {
|
||||
return zero, nil
|
||||
}
|
||||
|
||||
p, err := plugin.Open(pluginPath(path, id))
|
||||
if err != nil {
|
||||
return zero, fmt.Errorf("failed to open plugin %s: %w", id, err)
|
||||
}
|
||||
|
||||
symbol, err := p.Lookup("Provider")
|
||||
if err != nil {
|
||||
return zero, fmt.Errorf("failed to find Provider symbol in plugin %s: %w", id, err)
|
||||
}
|
||||
|
||||
// Ensure the symbol is of the correct type
|
||||
prov, ok := symbol.(*T)
|
||||
if !ok {
|
||||
return zero, fmt.Errorf("failed to cast Provider for %s", id)
|
||||
}
|
||||
|
||||
return *prov, nil
|
||||
}
|
||||
|
||||
// pluginPath constructs the path to the plugin shared object file.
|
||||
func pluginPath(path, id string) string {
|
||||
return filepath.Join(path, id+".so")
|
||||
}
|
||||
|
||||
// Validators retrieves the validation plugin instances.
|
||||
func (m *Manager) Validators(ctx context.Context) (map[string]definition.Validator, error) {
|
||||
if m.vp == nil {
|
||||
return nil, fmt.Errorf("validator plugin provider not loaded")
|
||||
}
|
||||
|
||||
configMap := map[string]string{
|
||||
"schema_dir": m.cfg.Plugins.ValidationPlugin.Schema.SchemaDir,
|
||||
}
|
||||
_, err := m.vp.New(ctx, configMap)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize validator: %w", err)
|
||||
}
|
||||
|
||||
return m.validators, nil
|
||||
}
|
||||
|
||||
// LoadConfig loads the configuration from a YAML file.
|
||||
func LoadConfig(path string) (*Config, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open config file: %w", err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var cfg Config
|
||||
decoder := yaml.NewDecoder(file)
|
||||
if err := decoder.Decode(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode config file: %w", err)
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
6
shared/plugin/plugin.yaml
Normal file
6
shared/plugin/plugin.yaml
Normal file
@@ -0,0 +1,6 @@
|
||||
plugins:
|
||||
validation_plugin:
|
||||
id: validator
|
||||
config:
|
||||
schema_dir: #Directory where the schema files are stored
|
||||
plugin_path: shared/plugin/implementations/
|
||||
0
shared/plugin/testData/directory.json
Normal file
0
shared/plugin/testData/directory.json
Normal file
31
shared/plugin/testData/payloads/cancel.json
Normal file
31
shared/plugin/testData/payloads/cancel.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "cancel",
|
||||
"bap_id": "example-bap.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"bpp_id": "api.beckn.juspay.in/dobpp/beckn/7f7896dd-787e-4a0b-8675-e9e6fe93bb8f",
|
||||
"bpp_uri": "https://example-bpp.com/prod/seller",
|
||||
"domain": "ONDC:TRV10",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "std:080"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "be6a495a-e941-4fbf-9d59-f1e6166cccc8",
|
||||
"timestamp": "2023-03-23T05:15:08Z",
|
||||
"transaction_id": "870782be-6757-43f1-945c-8eeaf9536259",
|
||||
"ttl": "PT30S",
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"message": {
|
||||
"cancellation_reason_id": "7",
|
||||
"descriptor": {
|
||||
"code": "SOFT_CANCEL",
|
||||
"name": "Ride Cancellation"
|
||||
},
|
||||
"order_id": "O1"
|
||||
}
|
||||
}
|
||||
153
shared/plugin/testData/payloads/confirm.json
Normal file
153
shared/plugin/testData/payloads/confirm.json
Normal file
@@ -0,0 +1,153 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "confirm",
|
||||
"bap_id": "example-bap.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"bpp_id": "example-bpp.com",
|
||||
"bpp_uri": "https://example-bpp.com/prod/seller",
|
||||
"domain": "ONDC:TRV10",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "std:080"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "6743e9e2-4fb5-487c-92b7-13ba8018f176",
|
||||
"timestamp": "2023-12-10T04:34:48.031Z",
|
||||
"transaction_id": "870782be-6757-43f1-945c-8eeaf9536259",
|
||||
"ttl": "PT30S",
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"message": {
|
||||
"order": {
|
||||
"billing": {
|
||||
"name": "Joe Adams"
|
||||
},
|
||||
"fulfillments": [
|
||||
{
|
||||
"customer": {
|
||||
"contact": {
|
||||
"phone": "9876556789"
|
||||
},
|
||||
"person": {
|
||||
"name": "Joe Adams"
|
||||
}
|
||||
},
|
||||
"id": "F1",
|
||||
"stops": [
|
||||
{
|
||||
"location": {
|
||||
"gps": "13.008935, 77.644408"
|
||||
},
|
||||
"type": "START"
|
||||
},
|
||||
{
|
||||
"location": {
|
||||
"gps": "12.971186, 77.586812"
|
||||
},
|
||||
"type": "END"
|
||||
}
|
||||
],
|
||||
"vehicle": {
|
||||
"category": "AUTO_RICKSHAW"
|
||||
}
|
||||
}
|
||||
],
|
||||
"items": [
|
||||
{
|
||||
"id": "I1"
|
||||
}
|
||||
],
|
||||
"payments": [
|
||||
{
|
||||
"collected_by": "BPP",
|
||||
"id": "PA1",
|
||||
"params": {
|
||||
"bank_account_number": "xxxxxxxxxxxxxx",
|
||||
"bank_code": "XXXXXXXX",
|
||||
"virtual_payment_address": "9988199772@okicic"
|
||||
},
|
||||
"status": "NOT-PAID",
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES_PERCENTAGE"
|
||||
},
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TERMS"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_WINDOW"
|
||||
},
|
||||
"value": "PT60M"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_BASIS"
|
||||
},
|
||||
"value": "DELIVERY"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TYPE"
|
||||
},
|
||||
"value": "UPI"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "MANDATORY_ARBITRATION"
|
||||
},
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "COURT_JURISDICTION"
|
||||
},
|
||||
"value": "New Delhi"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "DELAY_INTEREST"
|
||||
},
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "STATIC_TERMS"
|
||||
},
|
||||
"value": "https://example-test-bap.com/static-terms.txt"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_AMOUNT"
|
||||
},
|
||||
"value": "1.46"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"type": "ON-FULFILLMENT"
|
||||
}
|
||||
],
|
||||
"provider": {
|
||||
"id": "P1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
80
shared/plugin/testData/payloads/search.json
Normal file
80
shared/plugin/testData/payloads/search.json
Normal file
@@ -0,0 +1,80 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "search",
|
||||
"bap_id": "example-bap.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"domain": "ONDC:TRV10",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "std:080"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "40963dc1-e402-4f4d-ae70-7c5864ca682c",
|
||||
"timestamp": "2023-12-09T13:39:56.645Z",
|
||||
"transaction_id": "870782be-6757-43f1-945c-8eeaf9536259",
|
||||
"ttl": "PT30S",
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"message": {
|
||||
"intent": {
|
||||
"fulfillment": {
|
||||
"stops": [
|
||||
{
|
||||
"location": {
|
||||
"gps": "13.008935, 77.644408"
|
||||
},
|
||||
"type": "START"
|
||||
},
|
||||
{
|
||||
"location": {
|
||||
"gps": "12.971186, 77.586812"
|
||||
},
|
||||
"type": "END"
|
||||
}
|
||||
]
|
||||
},
|
||||
"payment": {
|
||||
"collected_by": "BPP",
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES_PERCENTAGE"
|
||||
},
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TERMS"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "DELAY_INTEREST"
|
||||
},
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "STATIC_TERMS"
|
||||
},
|
||||
"value": "https://example-test-bap.com/static-terms.txt"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
shared/plugin/testData/payloads/search_extraField.json
Normal file
63
shared/plugin/testData/payloads/search_extraField.json
Normal file
@@ -0,0 +1,63 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "search",
|
||||
"bap_id": "bap.example.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"domain": "example-domain",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "PUN"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "123e4567-e89b-12d3-a456-426614174000",
|
||||
"timestamp": "2025-03-06T12:00:00Z",
|
||||
"transaction_id": "123e4567-e89b-12d3-a456-426614174001",
|
||||
"ttl": "PT30M",
|
||||
"version": "1.0.0",
|
||||
"extra_field": "unexpected_value"
|
||||
},
|
||||
"message": {
|
||||
"intent": {
|
||||
"fulfillment": {
|
||||
"stops": [
|
||||
{
|
||||
"location": {
|
||||
"gps": "19.0760,72.8777",
|
||||
"created_at": "unexpected_value"
|
||||
},
|
||||
"type": "START"
|
||||
},
|
||||
{
|
||||
"location": {
|
||||
"gps": "18.5204,73.8567"
|
||||
},
|
||||
"type": "END"
|
||||
}
|
||||
]
|
||||
},
|
||||
"payment": {
|
||||
"collected_by": "BPP",
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "some-code"
|
||||
},
|
||||
"display": true,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "list-code"
|
||||
},
|
||||
"value": "list-value"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
65
shared/plugin/testData/payloads/search_missingField.json
Normal file
65
shared/plugin/testData/payloads/search_missingField.json
Normal file
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "search",
|
||||
"bap_id": "example-bap.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"domain": "ONDC:TRV10",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "std:080"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "40963dc1-e402-4f4d-ae70-7c5864ca682c",
|
||||
"timestamp": "2023-12-09T13:39:56.645Z",
|
||||
"transaction_id": "870782be-6757-43f1-945c-8eeaf9536259",
|
||||
"ttl": "PT30S",
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"message": {
|
||||
"intent": {
|
||||
"payment": {
|
||||
"collected_by": "BPP",
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES_PERCENTAGE"
|
||||
},
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TERMS"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "DELAY_INTEREST"
|
||||
},
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "STATIC_TERMS"
|
||||
},
|
||||
"value": "https://example-test-bap.com/static-terms.txt"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
352
shared/plugin/testData/payloads/select.json
Normal file
352
shared/plugin/testData/payloads/select.json
Normal file
@@ -0,0 +1,352 @@
|
||||
{
|
||||
"context": {
|
||||
"action": "select",
|
||||
"bap_id": "example-bap.com",
|
||||
"bap_uri": "https://example-bap.com/prod/trv10",
|
||||
"bpp_id": "example-bpp.com",
|
||||
"bpp_uri": "https://example-bpp.com/prod/seller",
|
||||
"domain": "ONDC:TRV10",
|
||||
"location": {
|
||||
"city": {
|
||||
"code": "std:080"
|
||||
},
|
||||
"country": {
|
||||
"code": "IND"
|
||||
}
|
||||
},
|
||||
"message_id": "8926b747-0362-4fcc-b795-0994a6287700",
|
||||
"timestamp": "2023-12-09T14:11:32.859Z",
|
||||
"transaction_id": "870782be-6757-43f1-945c-8eeaf9536259",
|
||||
"ttl": "PT30S",
|
||||
"version": "2.0.0"
|
||||
},
|
||||
"message": {
|
||||
"order": {
|
||||
"cancellation_terms": [
|
||||
{
|
||||
"cancellation_fee": {
|
||||
"percentage": "0"
|
||||
},
|
||||
"fulfillment_state": {
|
||||
"descriptor": {
|
||||
"code": "RIDE_ASSIGNED"
|
||||
}
|
||||
},
|
||||
"reason_required": true
|
||||
},
|
||||
{
|
||||
"cancellation_fee": {
|
||||
"amount": {
|
||||
"currency": "INR",
|
||||
"value": "30"
|
||||
}
|
||||
},
|
||||
"fulfillment_state": {
|
||||
"descriptor": {
|
||||
"code": "RIDE_ENROUTE_PICKUP"
|
||||
}
|
||||
},
|
||||
"reason_required": true
|
||||
},
|
||||
{
|
||||
"cancellation_fee": {
|
||||
"amount": {
|
||||
"currency": "INR",
|
||||
"value": "50"
|
||||
}
|
||||
},
|
||||
"fulfillment_state": {
|
||||
"descriptor": {
|
||||
"code": "RIDE_ARRIVED_PICKUP"
|
||||
}
|
||||
},
|
||||
"reason_required": true
|
||||
},
|
||||
{
|
||||
"cancellation_fee": {
|
||||
"percentage": "100"
|
||||
},
|
||||
"fulfillment_state": {
|
||||
"descriptor": {
|
||||
"code": "RIDE_STARTED"
|
||||
}
|
||||
},
|
||||
"reason_required": true
|
||||
}
|
||||
],
|
||||
"fulfillments": [
|
||||
{
|
||||
"id": "F1",
|
||||
"customer": {
|
||||
"contact": {
|
||||
"phone": "9876556789"
|
||||
},
|
||||
"person": {
|
||||
"name": "Joe Adams"
|
||||
}
|
||||
},
|
||||
"stops": [
|
||||
{
|
||||
"location": {
|
||||
"gps": "13.008935, 77.644408"
|
||||
},
|
||||
"type": "START"
|
||||
},
|
||||
{
|
||||
"location": {
|
||||
"gps": "12.971186, 77.586812"
|
||||
},
|
||||
"type": "END"
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "ROUTE_INFO",
|
||||
"name": "Route Information"
|
||||
},
|
||||
"display": true,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "ENCODED_POLYLINE",
|
||||
"name": "Path"
|
||||
},
|
||||
"value": "_p~iF~ps|U_ulLnnqC_mqNvxq`@"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "WAYPOINTS",
|
||||
"name": "Waypoints"
|
||||
},
|
||||
"value": "[{\"gps\":\"12.909982, 77.611822\"},{\"gps\":\"12.909982,77.611822\"},{\"gps\":\"12.909982,77.611822\"},{\"gps\":\"12.909982, 77.611822\"}]"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"type": "DELIVERY",
|
||||
"vehicle": {
|
||||
"category": "AUTO_RICKSHAW"
|
||||
}
|
||||
}
|
||||
],
|
||||
"items": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "RIDE",
|
||||
"name": "Auto Ride"
|
||||
},
|
||||
"fulfillment_ids": [
|
||||
"F1"
|
||||
],
|
||||
"id": "I1",
|
||||
"location_ids": [
|
||||
"L1",
|
||||
"L3"
|
||||
],
|
||||
"payment_ids": [
|
||||
"PA1"
|
||||
],
|
||||
"price": {
|
||||
"currency": "INR",
|
||||
"maximum_value": "176",
|
||||
"minimum_value": "136",
|
||||
"value": "146"
|
||||
},
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "FARE_POLICY",
|
||||
"name": "Daytime Charges"
|
||||
},
|
||||
"display": true,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "MIN_FARE"
|
||||
},
|
||||
"value": "30"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "MIN_FARE_DISTANCE_KM"
|
||||
},
|
||||
"value": "2"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "PER_KM_CHARGE"
|
||||
},
|
||||
"value": "15"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "PICKUP_CHARGE"
|
||||
},
|
||||
"value": "10"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "WAITING_CHARGE_PER_MIN"
|
||||
},
|
||||
"value": "2"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "NIGHT_CHARGE_MULTIPLIER"
|
||||
},
|
||||
"value": "1.5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "NIGHT_SHIFT_START_TIME"
|
||||
},
|
||||
"value": "22:00:00"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "NIGHT_SHIFT_END_TIME"
|
||||
},
|
||||
"value": "05:00:00"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "INFO",
|
||||
"name": "General Information"
|
||||
},
|
||||
"display": true,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "DISTANCE_TO_NEAREST_DRIVER_METER"
|
||||
},
|
||||
"value": "661"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "ETA_TO_NEAREST_DRIVER_MIN"
|
||||
},
|
||||
"value": "3"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"payments": [
|
||||
{
|
||||
"collected_by": "BPP",
|
||||
"id": "PA1",
|
||||
"params": {
|
||||
"bank_account_number": "xxxxxxxxxxxxxx",
|
||||
"bank_code": "XXXXXXXX",
|
||||
"virtual_payment_address": "9988199772@okicic"
|
||||
},
|
||||
"status": "NOT-PAID",
|
||||
"tags": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES_PERCENTAGE"
|
||||
},
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TERMS"
|
||||
},
|
||||
"display": false,
|
||||
"list": [
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "DELAY_INTEREST"
|
||||
},
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_TYPE"
|
||||
},
|
||||
"value": "UPI"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_WINDOW"
|
||||
},
|
||||
"value": "PT2D"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_BASIS"
|
||||
},
|
||||
"value": "DELIVERY"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "MANDATORY_ARBITRATION"
|
||||
},
|
||||
"value": "true"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "COURT_JURISDICTION"
|
||||
},
|
||||
"value": "New Delhi"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "STATIC_TERMS"
|
||||
},
|
||||
"value": "https://example-test-bpp.com/static-terms.txt"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "SETTLEMENT_AMOUNT"
|
||||
},
|
||||
"value": "1.46"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"type": "ON-FULFILLMENT"
|
||||
}
|
||||
],
|
||||
"provider": {
|
||||
"id": "P1"
|
||||
},
|
||||
"quote": {
|
||||
"breakup": [
|
||||
{
|
||||
"price": {
|
||||
"currency": "INR",
|
||||
"value": "30"
|
||||
},
|
||||
"title": "BASE_FARE"
|
||||
},
|
||||
{
|
||||
"price": {
|
||||
"currency": "INR",
|
||||
"value": "116"
|
||||
},
|
||||
"title": "DISTANCE_FARE"
|
||||
}
|
||||
],
|
||||
"price": {
|
||||
"currency": "INR",
|
||||
"value": "146"
|
||||
},
|
||||
"ttl": "PT30S"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
{
|
||||
"$id": "http://example.com/schema/searchSchema",
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": { "type": "string" },
|
||||
"bap_id": { "type": "string" },
|
||||
"bap_uri": { "type": "string", "format": "uri" },
|
||||
"domain": { "type": "string" },
|
||||
"location": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"city": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "type": "string" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"country": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "type": "string" }
|
||||
},
|
||||
"required": ["code"]
|
||||
}
|
||||
},
|
||||
"required": ["city", "country"]
|
||||
},
|
||||
"message_id": { "type": "string", "format": "uuid" },
|
||||
"timestamp": { "type": "string", "format": "date-time" },
|
||||
"transaction_id": { "type": "string", "format": "uuid" },
|
||||
"ttl": { "type": "string" },
|
||||
"version": { "type": "string" }
|
||||
},
|
||||
"required": [
|
||||
"action",
|
||||
"bap_id",
|
||||
"bap_uri",
|
||||
"domain",
|
||||
"location",
|
||||
"message_id",
|
||||
"timestamp",
|
||||
"transaction_id",
|
||||
"ttl",
|
||||
"version"
|
||||
]
|
||||
},
|
||||
"message": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"intent": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"fulfillment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"stops": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"location": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"gps": { "type": "string", "pattern": "^\\d{1,3}\\.\\d+,\\s?\\d{1,3}\\.\\d+$" }
|
||||
},
|
||||
"required": ["gps"]
|
||||
},
|
||||
"type": { "type": "string", "enum": ["START", "END"] }
|
||||
},
|
||||
"required": ["location", "type"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["stops"]
|
||||
},
|
||||
"payment": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"collected_by": { "type": "string", "enum": ["BPP", "BAP"] },
|
||||
"tags": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "type": "string" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"display": { "type": "boolean" },
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "type": "string" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": { "type": "string" }
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "display", "list"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["collected_by", "tags"]
|
||||
}
|
||||
},
|
||||
"required": ["fulfillment", "payment"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["context", "message"]
|
||||
}
|
||||
Reference in New Issue
Block a user