changes in Initialse method as adding AddResource function

This commit is contained in:
AshwiniK-protean
2025-02-28 18:02:20 +05:30
parent 26c97c5774
commit 4b940d9e51
57 changed files with 2516 additions and 2993 deletions

View File

@@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
@@ -84,10 +85,10 @@ func (v *tekuriValidator) Validate(ctx context.Context, data []byte) error {
// } // }
// (Approach 2)(all json files for each schema from sub directories) // (Approach 2)(all json files for each schema from sub directories)
func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plugins.Validator, error) { func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plugins.Validator, error) {
vp.schemaCache = make(map[string]map[string]*jsonschema.Schema) vp.schemaCache = make(map[string]map[string]*jsonschema.Schema)
validatorCache := make(map[string]plugins.Validator) validatorCache := make(map[string]plugins.Validator)
baseCustomID := "https://core/v1.1.0/"
// Walk through the directory and compile all .json files // Walk through the directory and compile all .json files
err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error {
@@ -96,12 +97,28 @@ func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plug
} }
if !info.IsDir() && filepath.Ext(info.Name()) == ".json" { if !info.IsDir() && filepath.Ext(info.Name()) == ".json" {
filePath := filepath.Join(schemaDir, info.Name()) filePath := filepath.Join(schemaDir, info.Name())
fmt.Println("printing path : ", path)
fmt.Println("Compiling file path: ", filePath)
// Construct the CustomID using baseCustomID and the file name
customID := baseCustomID + info.Name()
compiler := jsonschema.NewCompiler() compiler := jsonschema.NewCompiler()
compiledSchema, err := compiler.Compile(path) resource, err := os.Open(path)
if err != nil {
return fmt.Errorf("failed to open JSON schema file %s: %v", info.Name(), err)
}
defer func() {
if err := resource.Close(); err != nil {
log.Printf("Error closing resource: %v", err)
}
}()
// defer resource.Close()
if err := compiler.AddResource(customID, resource); err != nil {
return fmt.Errorf("failed to add resource for JSON schema file %s and custom id is %s: %v", info.Name(), customID, err)
}
// compiledSchema, err := compiler.Compile(path)
compiledSchema, err := compiler.Compile(customID)
if err != nil { if err != nil {
return fmt.Errorf("failed to compile JSON schema from file %s: %v", info.Name(), err) return fmt.Errorf("failed to compile JSON schema from file %s: %v", info.Name(), err)
} }
@@ -109,8 +126,6 @@ func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plug
return fmt.Errorf("compiled schema is nil for file %s", info.Name()) return fmt.Errorf("compiled schema is nil for file %s", info.Name())
} }
fmt.Printf("Compiled schema for file %s: %+v\n", info.Name(), compiledSchema)
dir := filepath.Base(filepath.Dir(filePath)) dir := filepath.Base(filepath.Dir(filePath))
if vp.schemaCache[dir] == nil { if vp.schemaCache[dir] == nil {
vp.schemaCache[dir] = make(map[string]*jsonschema.Schema) vp.schemaCache[dir] = make(map[string]*jsonschema.Schema)
@@ -131,6 +146,7 @@ var _ plugins.ValidatorProvider = (*tekuriValidatorProvider)(nil)
var providerInstance = &tekuriValidatorProvider{} var providerInstance = &tekuriValidatorProvider{}
// GetProvider returns the ValidatorProvider instance.
func GetProvider() plugins.ValidatorProvider { func GetProvider() plugins.ValidatorProvider {
return providerInstance return providerInstance
} }

View File

@@ -21,7 +21,7 @@ type Message struct{}
func TestInitializeValidDirectory(t *testing.T) { func TestInitializeValidDirectory(t *testing.T) {
provider := &tekuriValidatorProvider{} provider := &tekuriValidatorProvider{}
schemaDir := "../schema/ondc_trv10_2.0.0/" schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
_, err := provider.Initialize(schemaDir) _, err := provider.Initialize(schemaDir)
if err != nil { if err != nil {
t.Fatalf("expected no error, got %v", err) t.Fatalf("expected no error, got %v", err)
@@ -30,7 +30,7 @@ func TestInitializeValidDirectory(t *testing.T) {
func TestInitializeInValidDirectory(t *testing.T) { func TestInitializeInValidDirectory(t *testing.T) {
provider := &tekuriValidatorProvider{} provider := &tekuriValidatorProvider{}
schemaDir := "../schemas/ondc_trv10_2.0.0/" schemaDir := "../schema/ondc_trv10_2.0.0/"
_, err := provider.Initialize(schemaDir) _, err := provider.Initialize(schemaDir)
if err != nil { if err != nil {
t.Fatalf("failed to read schema directory: %v", err) t.Fatalf("failed to read schema directory: %v", err)
@@ -68,7 +68,7 @@ func TestInvalidCompileSchema(t *testing.T) {
} }
func TestValidateData(t *testing.T) { func TestValidateData(t *testing.T) {
schemaDir := "../schema/ondc_trv10_2.0.0/" schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
if _, err := os.Stat(schemaDir); os.IsNotExist(err) { if _, err := os.Stat(schemaDir); os.IsNotExist(err) {
t.Fatalf("Schema directory does not exist: %v", schemaDir) t.Fatalf("Schema directory does not exist: %v", schemaDir)
} }
@@ -108,7 +108,7 @@ func TestValidateData(t *testing.T) {
} }
func TestInValidateData(t *testing.T) { func TestInValidateData(t *testing.T) {
schemaDir := "../schema/ondc_trv10_2.0.0/" schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
if _, err := os.Stat(schemaDir); os.IsNotExist(err) { if _, err := os.Stat(schemaDir); os.IsNotExist(err) {
t.Fatalf("Schema directory does not exist: %v", schemaDir) t.Fatalf("Schema directory does not exist: %v", schemaDir)
@@ -138,7 +138,7 @@ func TestInValidateData(t *testing.T) {
} }
func TestInValidateUnmarshalData(t *testing.T) { func TestInValidateUnmarshalData(t *testing.T) {
schemaDir := "../schema/ondc_trv10_2.0.0/" schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
if _, err := os.Stat(schemaDir); os.IsNotExist(err) { if _, err := os.Stat(schemaDir); os.IsNotExist(err) {
t.Fatalf("Schema directory does not exist: %v", schemaDir) t.Fatalf("Schema directory does not exist: %v", schemaDir)

View File

@@ -12,20 +12,24 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
// PluginConfig represents the configuration for plugins, including the plugins themselves.
type PluginConfig struct { type PluginConfig struct {
Plugins Plugins `yaml:"plugins"` Plugins Plugins `yaml:"plugins"`
} }
// Plugins holds the various plugin types used in the configuration.
type Plugins struct { type Plugins struct {
ValidationPlugin ValidationPlugin `yaml:"validation_plugin"` ValidationPlugin ValidationPlugin `yaml:"validation_plugin"`
} }
// ValidationPlugin represents a plugin with an ID, configuration, and the path to the plugin.
type ValidationPlugin struct { type ValidationPlugin struct {
ID string `yaml:"id"` ID string `yaml:"id"`
Config PluginDetails `yaml:"config"` Config PluginDetails `yaml:"config"`
PluginPath string `yaml:"plugin_path"` PluginPath string `yaml:"plugin_path"`
} }
// PluginDetails contains information about the plugin schema directory.
type PluginDetails struct { type PluginDetails struct {
Schema string `yaml:"schema_dir"` Schema string `yaml:"schema_dir"`
} }
@@ -87,7 +91,7 @@ func NewValidatorProvider(pluginsConfig PluginConfig) (*PluginManager, map[strin
return &PluginManager{validatorProvider: validatorProvider}, validator, nil return &PluginManager{validatorProvider: validatorProvider}, validator, nil
} }
// loadPluginsConfig loads the plugins configuration from a YAML file. // LoadPluginsConfig loads the plugins configuration from a YAML file.
func LoadPluginsConfig(filePath string) (PluginConfig, error) { func LoadPluginsConfig(filePath string) (PluginConfig, error) {
// start := time.Now() // start := time.Now()

View File

@@ -22,8 +22,25 @@
] ]
} }
] ]
},
"message": {
"type": "object",
"additionalProperties": false,
"properties": {
"order_id": {
"$ref": "definitions.json#/$defs/Order"
},
"cancellation_reason_id": {
"$ref": "definitions.json#/$defs/Option"
},
"descriptor": {
"$ref": "definitions.json#/$defs/Descriptor"
}
},
"required": [
"order_id"
]
} }
}, },
"required": [ "required": [
"message", "message",

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/confirm", "$id": "confirm",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/init", "$id": "init",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnCancel", "$id": "OnCancel",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnConfirm", "$id": "OnConfirm",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnInit", "$id": "OnInit",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnRating", "$id": "OnRating",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnSearch", "$id": "OnSearch",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnSelect", "$id": "OnSelect",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnStatus", "$id": "OnStatus",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnSupport", "$id": "OnSupport",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnTrack", "$id": "OnTrack",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/OnUpdate", "$id": "OnUpdate",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/rating", "$id": "rating",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/Response", "$id": "Response",
"type": "object", "type": "object",
"properties": {}, "properties": {},
"required": [] "required": []

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/status", "$id": "status",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/support", "$id": "support",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/track", "$id": "track",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/update", "$id": "update",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_cancel", "$id": "on_cancel",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_confirm", "$id": "on_confirm",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_init", "$id": "on_init",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_rating", "$id": "on_rating",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_search", "$id": "on_search",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_select", "$id": "on_select",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_status", "$id": "on_status",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_support", "$id": "on_support",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_track", "$id": "on_track",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/on_update", "$id": "on_update",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/search", "$id": "search",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://beckn.org/schema/select", "$id": "select",
"type": "object", "type": "object",
"properties": { "properties": {
"context": { "context": {

View File

@@ -1,13 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/cancel", "$id": "cancel",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/cancel.json#" "$ref": "../../core/v1.1.0/cancel.json#"
},
{
"$ref": "https://beckn.org/schema/cancel#"
}, },
{ {
"$ref": "./init.json#/allOf/2" "$ref": "./init.json#/allOf/2"

View File

@@ -1,13 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/confirm", "$id": "confirm",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
},
{
"$ref": "https://beckn.org/schema/confirm#"
}, },
{ {
"$ref": "./init.json#/allOf/2" "$ref": "./init.json#/allOf/2"

View File

@@ -1,10 +1,9 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/init", "$id": "init",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ "$ref": "../core/v1.1.0/init.json#" }, { "$ref": "../../core/v1.1.0/init.json#" },
{ "$ref": "https://beckn.org/schema/init#" },
{ {
"allOf": [ "allOf": [
{ "$ref": "./search.json#/properties/context/allOf/0" }, { "$ref": "./search.json#/properties/context/allOf/0" },
@@ -43,7 +42,7 @@
} }
}, },
{ "$ref": "./confirm.json#/allOf/4" }, { "$ref": "./confirm.json#/allOf/4" },
{ "$ref": "./on_select.json#/allOf/10" }, { "$ref": "./on_select.json#" },
{ {
"properties": { "properties": {
"message": { "message": {

View File

@@ -4,7 +4,7 @@
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -4,7 +4,7 @@
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_init", "$id": "on_init",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/on_init.json#" "$ref": "../../core/v1.1.0/on_init.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/on_init#" "$ref": "https://beckn.org/schema/on_init#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_rating", "$id": "on_rating",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_search", "$id": "on_search",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/on_search.json#" "$ref": "../../core/v1.1.0/on_search.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/on_search#" "$ref": "https://beckn.org/schema/on_search#"

View File

@@ -1,23 +1,14 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_select", "$id": "on_select",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/on_select.json#" "$ref": "../../core/v1.1.0/on_select.json#"
},
{
"$ref": "https://beckn.org/schema/on_select#"
}, },
{ {
"$ref": "./init.json#/allOf/2" "$ref": "./init.json#/allOf/2"
}, },
{
"$ref": "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2"
},
{
"$ref": "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4"
},
{ {
"properties": { "properties": {
"message": { "message": {
@@ -793,9 +784,6 @@
} }
] ]
}, },
{
"$ref": "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/6"
},
{ {
"properties": { "properties": {
"message": { "message": {
@@ -819,9 +807,6 @@
} }
} }
} }
},
{
"$ref": "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7"
} }
] ]
} }

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_status", "$id": "on_status",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_support", "$id": "on_support",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/on_track", "$id": "on_track",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/confirm.json#" "$ref": "../../core/v1.1.0/confirm.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/confirm#" "$ref": "https://beckn.org/schema/confirm#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/rating", "$id": "rating",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/rating.json#" "$ref": "../../core/v1.1.0/rating.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/rating#" "$ref": "https://beckn.org/schema/rating#"

View File

@@ -1,9 +1,8 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/search", "$id": "search",
"allOf": [ "allOf": [
{ "$ref": "../core/v1.1.0/search.json#" }, { "$ref": "../core/v1.1.0/search.json#" }
{ "$ref": "https://beckn.org/schema/search#" }
], ],
"type": "object", "type": "object",
"properties": { "properties": {
@@ -40,11 +39,11 @@
}, },
"bap_id": { "bap_id": {
"type": "string", "type": "string",
"pattern": "^(?!https?://).*$" "pattern": "^(http|https).*"
}, },
"bpp_id": { "bpp_id": {
"type": "string", "type": "string",
"pattern": "^(?!https?://).*$" "pattern": "^(http|https).*"
}, },
"ttl": { "ttl": {
"type": "string", "type": "string",

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/select", "$id": "select",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ "$ref": "../core/v1.1.0/select.json#" }, { "$ref": "../core/v1.1.0/select.json#" },

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/status", "$id": "status",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/status.json#" "$ref": "../../core/v1.1.0/status.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/status#" "$ref": "https://beckn.org/schema/status#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/support", "$id": "support",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/support.json#" "$ref": "../../core/v1.1.0/support.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/support#" "$ref": "https://beckn.org/schema/support#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/track", "$id": "track",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/track.json#" "$ref": "../../core/v1.1.0/track.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/track#" "$ref": "https://beckn.org/schema/track#"

View File

@@ -1,10 +1,10 @@
{ {
"$schema": "https://json-schema.org/draft/2020-12/schema", "$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://ondc.org/trv10/2.0.0/update", "$id": "update",
"type": "object", "type": "object",
"allOf": [ "allOf": [
{ {
"$ref": "../core/v1.1.0/update.json#" "$ref": "../../core/v1.1.0/update.json#"
}, },
{ {
"$ref": "https://beckn.org/schema/update#" "$ref": "https://beckn.org/schema/update#"

View File

@@ -248,498 +248,6 @@
"required": ["intent"] "required": ["intent"]
} }
} }
},
"select": {
"$id": "select#",
"type": "object",
"properties": {
"context": {
"type": "object",
"properties": {
"domain": {
"type": "string"
},
"location": {
"type": "object",
"properties": {
"city": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
},
"required": ["code"]
},
"country": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": ["IND"]
}
},
"required": ["code"]
}
},
"required": ["city", "country"]
},
"action": {
"type": "string",
"enum": ["search"]
},
"bap_id": {
"type": "string"
},
"bap_uri": {
"type": "string",
"format": "uri"
},
"bpp_id": {
"type": "string"
},
"bpp_uri": {
"type": "string",
"format": "uri"
},
"transaction_id": {
"type": "string",
"format": "uuid"
},
"message_id": {
"type": "string",
"format": "uuid"
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"ttl": {
"type": "string",
"format": "duration"
}
},
"required": [
"domain",
"location",
"action",
"bap_id",
"bap_uri",
"transaction_id",
"message_id",
"timestamp",
"ttl"
]
},
"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"
}
},
"required": ["gps"]
},
"type": {
"type": "string",
"enum": ["START", "END"]
}
},
"required": ["location", "type"]
},
"minItems": 2,
"maxItems": 2
}
},
"required": ["stops"]
},
"payment": {
"type": "object",
"properties": {
"collected_by": {
"type": "string",
"enum": ["BPP", "BAP"]
},
"tags": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": ["SETTLEMENT_TERMS", "BUYER_FINDER_FEES"]
}
},
"required": ["code"]
}
},
"allOf": [
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "SETTLEMENT_TERMS"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"SETTLEMENT_BASIS",
"SETTLEMENT_WINDOW",
"STATIC_TERMS",
"SETTLEMENT_TYPE",
"DELAY_INTEREST"
]
}
},
"required": ["code"]
},
"value": {
"type": "string"
}
},
"required": ["descriptor", "value"]
}
}
}
}
},
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "BUYER_FINDER_FEES"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"enum": ["BUYER_FINDER_FEES_PERCENTAGE"]
}
},
"required": ["code"]
},
"value": {
"type": "string",
"pattern": "^-?\\d+(\\.\\d+)?$"
}
},
"required": ["descriptor", "value"]
}
}
}
}
}
],
"required": ["descriptor"]
}
}
},
"required": ["collected_by", "tags"]
}
},
"required": ["fulfillment", "payment"]
}
},
"required": ["intent"]
}
}
},
"on_init": {
"$id": "on_init#",
"type": "object",
"properties": {
"context": {
"type": "object",
"properties": {
"domain": {
"type": "string"
},
"location": {
"type": "object",
"properties": {
"city": {
"type": "object",
"properties": {
"code": {
"type": "string"
}
},
"required": ["code"]
},
"country": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": ["IND"]
}
},
"required": ["code"]
}
},
"required": ["city", "country"]
},
"action": {
"type": "string",
"enum": ["search"]
},
"bap_id": {
"type": "string"
},
"bap_uri": {
"type": "string",
"format": "uri"
},
"bpp_id": {
"type": "string"
},
"bpp_uri": {
"type": "string",
"format": "uri"
},
"transaction_id": {
"type": "string",
"format": "uuid"
},
"message_id": {
"type": "string",
"format": "uuid"
},
"timestamp": {
"type": "string",
"format": "date-time"
},
"ttl": {
"type": "string",
"format": "duration"
}
},
"required": [
"domain",
"location",
"action",
"bap_id",
"bap_uri",
"transaction_id",
"message_id",
"timestamp",
"ttl"
]
},
"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"
}
},
"required": ["gps"]
},
"type": {
"type": "string",
"enum": ["START", "END"]
}
},
"required": ["location", "type"]
},
"minItems": 2,
"maxItems": 2
}
},
"required": ["stops"]
},
"payment": {
"type": "object",
"properties": {
"collected_by": {
"type": "string",
"enum": ["BPP", "BAP"]
},
"tags": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"uniqueItems": true,
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": ["SETTLEMENT_TERMS", "BUYER_FINDER_FEES"]
}
},
"required": ["code"]
}
},
"allOf": [
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "SETTLEMENT_TERMS"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"type": "string",
"enum": [
"SETTLEMENT_BASIS",
"SETTLEMENT_WINDOW",
"STATIC_TERMS",
"SETTLEMENT_TYPE",
"DELAY_INTEREST"
]
}
},
"required": ["code"]
},
"value": {
"type": "string"
}
},
"required": ["descriptor", "value"]
}
}
}
}
},
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "BUYER_FINDER_FEES"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"descriptor": {
"type": "object",
"properties": {
"code": {
"enum": ["BUYER_FINDER_FEES_PERCENTAGE"]
}
},
"required": ["code"]
},
"value": {
"type": "string",
"pattern": "^-?\\d+(\\.\\d+)?$"
}
},
"required": ["descriptor", "value"]
}
}
}
}
}
],
"required": ["descriptor"]
}
}
},
"required": ["collected_by", "tags"]
}
},
"required": ["fulfillment", "payment"]
}
},
"required": ["intent"]
}
}
} }
} }
} }

View File

@@ -10,6 +10,7 @@ import (
"strings" "strings"
) )
// Payload represents the structure of the data payload with context information.
type Payload struct { type Payload struct {
Context struct { Context struct {
Domain string `json:"domain"` Domain string `json:"domain"`