update schemas and create a validateHandler function
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
@@ -25,7 +24,6 @@ type tekuriValidatorProvider struct {
|
||||
|
||||
// Validate validates the given data against the schema.
|
||||
func (v *tekuriValidator) Validate(ctx context.Context, data []byte) error {
|
||||
// start := time.Now()
|
||||
var jsonData interface{}
|
||||
if err := json.Unmarshal(data, &jsonData); err != nil {
|
||||
return err
|
||||
@@ -35,11 +33,55 @@ func (v *tekuriValidator) Validate(ctx context.Context, data []byte) error {
|
||||
fmt.Printf("Validation error: %v\n", err)
|
||||
}
|
||||
|
||||
// fmt.Printf("validate executed in %s\n", time.Since(start))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// (Approach 2)(all json files for each schema from sub directories)
|
||||
func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plugins.Validator, error) {
|
||||
vp.schemaCache = make(map[string]map[string]*jsonschema.Schema)
|
||||
validatorCache := make(map[string]plugins.Validator)
|
||||
|
||||
err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() && filepath.Ext(info.Name()) == ".json" {
|
||||
filePath := filepath.Join(schemaDir, info.Name())
|
||||
compiler := jsonschema.NewCompiler()
|
||||
compiledSchema, err := compiler.Compile(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to compile JSON schema from file %s: %v", info.Name(), err)
|
||||
}
|
||||
if compiledSchema == nil {
|
||||
return fmt.Errorf("compiled schema is nil for file %s", info.Name())
|
||||
}
|
||||
|
||||
dir := filepath.Base(filepath.Dir(filePath))
|
||||
if vp.schemaCache[dir] == nil {
|
||||
vp.schemaCache[dir] = make(map[string]*jsonschema.Schema)
|
||||
}
|
||||
vp.schemaCache[dir][info.Name()] = compiledSchema
|
||||
validatorCache[info.Name()] = &tekuriValidator{schema: compiledSchema}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read schema directory: %v", err)
|
||||
}
|
||||
|
||||
return validatorCache, nil
|
||||
}
|
||||
|
||||
var _ plugins.ValidatorProvider = (*tekuriValidatorProvider)(nil)
|
||||
|
||||
var providerInstance = &tekuriValidatorProvider{}
|
||||
|
||||
// GetProvider returns the ValidatorProvider instance.
|
||||
func GetProvider() plugins.ValidatorProvider {
|
||||
return providerInstance
|
||||
}
|
||||
|
||||
///////////////////////
|
||||
//(Approach 2)(all json files for each schema)
|
||||
|
||||
// Initialize reads all .json files from the given schema directory, validates them using JSON Schema, and prints the result.
|
||||
@@ -82,74 +124,6 @@ func (v *tekuriValidator) Validate(ctx context.Context, data []byte) error {
|
||||
// // fmt.Printf("initialize executed in %s\n", time.Since(start))
|
||||
|
||||
// return validatorCache, nil
|
||||
// }
|
||||
|
||||
// (Approach 2)(all json files for each schema from sub directories)
|
||||
func (vp *tekuriValidatorProvider) Initialize(schemaDir string) (map[string]plugins.Validator, error) {
|
||||
vp.schemaCache = make(map[string]map[string]*jsonschema.Schema)
|
||||
validatorCache := make(map[string]plugins.Validator)
|
||||
baseCustomID := "https://core/v1.1.0/"
|
||||
|
||||
// Walk through the directory and compile all .json files
|
||||
err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !info.IsDir() && filepath.Ext(info.Name()) == ".json" {
|
||||
filePath := filepath.Join(schemaDir, info.Name())
|
||||
|
||||
// Construct the CustomID using baseCustomID and the file name
|
||||
customID := baseCustomID + info.Name()
|
||||
compiler := jsonschema.NewCompiler()
|
||||
|
||||
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 {
|
||||
return fmt.Errorf("failed to compile JSON schema from file %s: %v", info.Name(), err)
|
||||
}
|
||||
if compiledSchema == nil {
|
||||
return fmt.Errorf("compiled schema is nil for file %s", info.Name())
|
||||
}
|
||||
|
||||
dir := filepath.Base(filepath.Dir(filePath))
|
||||
if vp.schemaCache[dir] == nil {
|
||||
vp.schemaCache[dir] = make(map[string]*jsonschema.Schema)
|
||||
}
|
||||
vp.schemaCache[dir][info.Name()] = compiledSchema
|
||||
validatorCache[info.Name()] = &tekuriValidator{schema: compiledSchema}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to read schema directory: %v", err)
|
||||
}
|
||||
|
||||
return validatorCache, nil
|
||||
}
|
||||
|
||||
var _ plugins.ValidatorProvider = (*tekuriValidatorProvider)(nil)
|
||||
|
||||
var providerInstance = &tekuriValidatorProvider{}
|
||||
|
||||
// GetProvider returns the ValidatorProvider instance.
|
||||
func GetProvider() plugins.ValidatorProvider {
|
||||
return providerInstance
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// (Approach 1)
|
||||
|
||||
@@ -21,7 +21,7 @@ type Message struct{}
|
||||
|
||||
func TestInitializeValidDirectory(t *testing.T) {
|
||||
provider := &tekuriValidatorProvider{}
|
||||
schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
|
||||
schemaDir := "../schemas/"
|
||||
_, err := provider.Initialize(schemaDir)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
@@ -68,7 +68,7 @@ func TestInvalidCompileSchema(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestValidateData(t *testing.T) {
|
||||
schemaDir := "../schema_valid/ondc_trv10_2.0.0/"
|
||||
schemaDir := "../schemas/"
|
||||
if _, err := os.Stat(schemaDir); os.IsNotExist(err) {
|
||||
t.Fatalf("Schema directory does not exist: %v", schemaDir)
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -80,8 +80,6 @@ func NewValidatorProvider(pluginsConfig PluginConfig) (*PluginManager, map[strin
|
||||
log.Fatalf("Failed to initialize validator provider: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("printing validators in new validator provider : ", validator)
|
||||
|
||||
var memStatsAfter runtime.MemStats
|
||||
runtime.ReadMemStats(&memStatsAfter)
|
||||
fmt.Printf("Memory allocated during plugin boot-up: %v MiB", (memStatsAfter.Alloc-memStatsBefore.Alloc)/1024/1024)
|
||||
|
||||
@@ -22,25 +22,8 @@
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"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": [
|
||||
"message",
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/cancel.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "init.json#/allOf/2"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
|
||||
@@ -7,15 +7,15 @@
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/3"
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
},
|
||||
{
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "./on_select.json#/allOf/8/allOf/0"
|
||||
"$ref": "./on_select.json#/allOf/5"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
@@ -77,7 +77,7 @@
|
||||
{
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "./init.json#/allOf/6"
|
||||
"$ref": "./init.json#/allOf/7"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
|
||||
@@ -2,395 +2,549 @@
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "init",
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
{ "$ref": "../../core/v1.1.0/init.json#" },
|
||||
"allOf": [
|
||||
{
|
||||
"allOf": [
|
||||
{ "$ref": "./search.json#/properties/context/allOf/0" },
|
||||
{ "required": ["bpp_id", "bpp_uri"] }
|
||||
]
|
||||
"$ref": "../../core/v1.1.0/init.json#"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"context": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"provider": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string" }
|
||||
},
|
||||
"required": ["id"]
|
||||
},
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string" }
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "./search.json#/properties/context/allOf/0"
|
||||
},
|
||||
"required": ["id"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["provider", "items"]
|
||||
{
|
||||
|
||||
"required": [
|
||||
"bpp_id",
|
||||
"bpp_uri"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ "$ref": "./confirm.json#/allOf/4" },
|
||||
{ "$ref": "./on_select.json#" },
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"required": ["fulfillments"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"order": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"payments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"params": {
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amount": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": ["PRE-ORDER", "ON-FULFILLMENT", "POST-FULFILLMENT"]
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["PAID", "NOT-PAID"]
|
||||
},
|
||||
"collected_by": {
|
||||
"type": "string",
|
||||
"enum": ["BAP", "BPP"]
|
||||
},
|
||||
"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": ["descriptor"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["type", "status", "collected_by", "tags"],
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{ "properties": { "collected_by": { "const": "BAP" } } },
|
||||
{ "properties": { "type": { "const": "PRE-ORDER" } } }
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": { "code": { "const": "SETTLEMENT_TERMS" } }
|
||||
"provider": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "STATIC_TERMS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_BASIS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": ["DELIVERY"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_WINDOW" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "DELAY_INTEREST" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
}
|
||||
"required": [
|
||||
"id"
|
||||
]
|
||||
},
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"id"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{ "properties": { "collected_by": { "const": "BPP" } } },
|
||||
{ "properties": { "type": { "const": "PRE-ORDER" } } }
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": { "code": { "const": "SETTLEMENT_TERMS" } }
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "STATIC_TERMS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_BASIS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": ["DELIVERY"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_WINDOW" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{ "properties": { "collected_by": { "const": "BPP" } } },
|
||||
{ "properties": { "type": { "const": "ON-FULFILLMENT" } } }
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": { "code": { "const": "SETTLEMENT_TERMS" } }
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "STATIC_TERMS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_BASIS" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": ["DELIVERY"]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "SETTLEMENT_WINDOW" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": { "code": { "const": "DELAY_INTEREST" } }
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"required": [
|
||||
"provider",
|
||||
"items"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"billing": {
|
||||
"required": ["name"]
|
||||
"$ref": "./confirm.json#/allOf/4"
|
||||
},
|
||||
{
|
||||
"$ref": "./on_select.json#"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"required": [
|
||||
"fulfillments"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"order": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"payments": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"params": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"amount": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"PRE-ORDER",
|
||||
"ON-FULFILLMENT",
|
||||
"POST-FULFILLMENT"
|
||||
]
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"PAID",
|
||||
"NOT-PAID"
|
||||
]
|
||||
},
|
||||
"collected_by": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"BAP",
|
||||
"BPP"
|
||||
]
|
||||
},
|
||||
"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": [
|
||||
"descriptor"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"type",
|
||||
"status",
|
||||
"collected_by",
|
||||
"tags"
|
||||
],
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"collected_by": {
|
||||
"const": "BAP"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "PRE-ORDER"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_TERMS"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "STATIC_TERMS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_BASIS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DELIVERY"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_WINDOW"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "DELAY_INTEREST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"collected_by": {
|
||||
"const": "BPP"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "PRE-ORDER"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_TERMS"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "STATIC_TERMS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_BASIS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DELIVERY"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_WINDOW"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"collected_by": {
|
||||
"const": "BPP"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"type": {
|
||||
"const": "ON-FULFILLMENT"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_TERMS"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "STATIC_TERMS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"format": "uri"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_BASIS"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DELIVERY"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "SETTLEMENT_WINDOW"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": {
|
||||
"const": "DELAY_INTEREST"
|
||||
}
|
||||
}
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d{1,2})?$"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"billing": {
|
||||
"required": [
|
||||
"name"
|
||||
]
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"billing"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["billing"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://ondc.org/trv10/2.0.0/on_cancel",
|
||||
"$id": "on_cancel",
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://ondc.org/trv10/2.0.0/on_confirm",
|
||||
"$id": "on_confirm",
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
{
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/on_init.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/on_init#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
@@ -35,7 +32,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "./on_select.json#/allOf/5"
|
||||
"$ref": "./confirm.json#/allOf/5"
|
||||
},
|
||||
{
|
||||
"$ref": "./on_select.json#/allOf/6"
|
||||
@@ -69,7 +66,7 @@
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "./confirm.json#/allOf/5/allOf/1"
|
||||
"$ref": "./confirm.json#/allOf/4/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
@@ -226,7 +223,7 @@
|
||||
]
|
||||
},
|
||||
{
|
||||
"$ref": "./confirm.json#/allOf/7"
|
||||
"$ref": "./confirm.json#/allOf/6"
|
||||
},
|
||||
{
|
||||
"allOf": [
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/on_search.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/on_search#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
|
||||
@@ -7,604 +7,16 @@
|
||||
"$ref": "../../core/v1.1.0/on_select.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"order": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"items": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": { "type": "string" },
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"code": { "type": "string", "enum": ["RIDE"] }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"price": {
|
||||
"type": "object",
|
||||
"properties": { "value": { "type": "string" } },
|
||||
"required": ["value"]
|
||||
},
|
||||
"fulfillment_ids": { "minItems": 1 },
|
||||
"location_ids": { "minItems": 1 }
|
||||
},
|
||||
"required": ["id", "price", "descriptor"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["items"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"$ref": "./on_init.json#/allOf/2"
|
||||
},
|
||||
{
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "FARE_POLICY" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"MIN_FARE",
|
||||
"MIN_FARE_DISTANCE_KM",
|
||||
"PER_KM_CHARGE",
|
||||
"PICKUP_CHARGE",
|
||||
"WAITING_CHARGE_PER_MIN",
|
||||
"NIGHT_CHARGE_MULTIPLIER",
|
||||
"NIGHT_SHIFT_START_TIME",
|
||||
"NIGHT_SHIFT_END_TIME",
|
||||
"EXTERNAL_REF"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "FARE_POLICY" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "MIN_FARE" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "MIN_FARE_DISTANCE_KM" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "PER_KM_CHARGE" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "PICKUP_CHARGE" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "WAITING_CHARGE_PER_MIN" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "NIGHT_CHARGE_MULTIPLIER" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^[0-9]+(\\.[0-9]+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "NIGHT_SHIFT_START_TIME" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "FARE_POLICY" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"enum": [
|
||||
"MIN_FARE",
|
||||
"MIN_FARE_DISTANCE_KM",
|
||||
"PER_KM_CHARGE",
|
||||
"PICKUP_CHARGE",
|
||||
"WAITING_CHARGE_PER_MIN",
|
||||
"NIGHT_CHARGE_MULTIPLIER"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^-?\\d+(\\.\\d+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"enum": [
|
||||
"NIGHT_SHIFT_START_TIME",
|
||||
"NIGHT_SHIFT_END_TIME"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "EXTERNAL_REF" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^https?://[^\\s/$.?#].[^\\s]*$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"$ref": "./confirm.json#/allOf/5"
|
||||
},
|
||||
{
|
||||
"allOf": [
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "INFO" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"DISTANCE_TO_NEAREST_DRIVER_METER",
|
||||
"ETA_TO_NEAREST_DRIVER_MIN"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "INFO" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"allOf": [
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "ETA_TO_NEAREST_DRIVER_MIN" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
},
|
||||
{
|
||||
"contains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"code": { "const": "DISTANCE_TO_NEAREST_DRIVER_METER" }
|
||||
},
|
||||
"required": ["code"]
|
||||
},
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^\\d+(\\.\\d+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
"properties": {
|
||||
"order": {
|
||||
"properties": {
|
||||
"items": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"properties": {
|
||||
"tags": {
|
||||
"items": {
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": { "const": "INFO" }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"list": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"allOf": [
|
||||
{
|
||||
"if": {
|
||||
"properties": {
|
||||
"descriptor": {
|
||||
"properties": {
|
||||
"code": {
|
||||
"enum": [
|
||||
"DISTANCE_TO_NEAREST_DRIVER_METER",
|
||||
"ETA_TO_NEAREST_DRIVER_MIN"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"then": {
|
||||
"properties": {
|
||||
"value": {
|
||||
"type": "string",
|
||||
"pattern": "^-?\\d+(\\.\\d+)?$"
|
||||
}
|
||||
},
|
||||
"required": ["descriptor", "value"]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"$ref": "./on_init.json#/allOf/5"
|
||||
},
|
||||
{
|
||||
"allOf": [
|
||||
@@ -784,6 +196,9 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"$ref": "./on_init.json#/allOf/7"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
"message": {
|
||||
@@ -807,6 +222,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"$ref": "./on_init.json#/allOf/8"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/confirm.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/confirm#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://ondc.org/trv10/2.0.0/on_update",
|
||||
"$id": "on_update",
|
||||
"type": "object",
|
||||
"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/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/rating.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/rating#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "search",
|
||||
"allOf": [
|
||||
{ "$ref": "../core/v1.1.0/search.json#" }
|
||||
{ "$ref": "../../core/v1.1.0/search.json#" }
|
||||
],
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -38,12 +38,10 @@
|
||||
"required": ["city", "country"]
|
||||
},
|
||||
"bap_id": {
|
||||
"type": "string",
|
||||
"pattern": "^(http|https).*"
|
||||
"type": "string"
|
||||
},
|
||||
"bpp_id": {
|
||||
"type": "string",
|
||||
"pattern": "^(http|https).*"
|
||||
"type": "string"
|
||||
},
|
||||
"ttl": {
|
||||
"type": "string",
|
||||
|
||||
@@ -3,9 +3,14 @@
|
||||
"$id": "select",
|
||||
"type": "object",
|
||||
"allOf": [
|
||||
{ "$ref": "../core/v1.1.0/select.json#" },
|
||||
{ "$ref": "https://beckn.org/schema/select#" },
|
||||
{ "$ref": "./init.json#/$defs/init_schema_1" },
|
||||
{ "$ref": "../paths/init.json#/$defs/init_schema_2" }
|
||||
{
|
||||
"$ref": "../../core/v1.1.0/select.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/status.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/status#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/support.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/support#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/track.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/track#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -7,10 +7,7 @@
|
||||
"$ref": "../../core/v1.1.0/update.json#"
|
||||
},
|
||||
{
|
||||
"$ref": "https://beckn.org/schema/update#"
|
||||
},
|
||||
{
|
||||
"$ref": "./init.json#/allOf/2"
|
||||
"$ref": "./init.json#/allOf/1"
|
||||
},
|
||||
{
|
||||
"properties": {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
{
|
||||
"context": {
|
||||
"action": "search",
|
||||
@@ -24,7 +25,7 @@
|
||||
"stops": [
|
||||
{
|
||||
"location": {
|
||||
"gps": "13.0089, 77.644408"
|
||||
"gps": "13.008935, 77.644408"
|
||||
},
|
||||
"type": "START"
|
||||
},
|
||||
@@ -49,7 +50,7 @@
|
||||
"descriptor": {
|
||||
"code": "BUYER_FINDER_FEES_PERCENTAGE"
|
||||
},
|
||||
"value": 1
|
||||
"value": "1"
|
||||
}
|
||||
]
|
||||
},
|
||||
@@ -63,13 +64,13 @@
|
||||
"descriptor": {
|
||||
"code": "DELAY_INTEREST"
|
||||
},
|
||||
"value": 5
|
||||
"value": "5"
|
||||
},
|
||||
{
|
||||
"descriptor": {
|
||||
"code": "STATIC_TERMS"
|
||||
},
|
||||
"value": "example-test-bap.com/static-terms.txt"
|
||||
"value": "https://example-test-bap.com/static-terms.txt"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -78,3 +79,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
80
test.go
80
test.go
@@ -2,10 +2,10 @@ package main
|
||||
|
||||
import (
|
||||
"beckn-onix/plugins"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
@@ -19,55 +19,63 @@ type Payload struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", validateHandler)
|
||||
fmt.Println("Starting server on port 8084...")
|
||||
err := http.ListenAndServe(":8084", nil)
|
||||
if err != nil {
|
||||
log.Fatalf("Server failed to start: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func validateHandler(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
|
||||
return
|
||||
}
|
||||
|
||||
// Extract endpoint from request URL
|
||||
requestURL := r.RequestURI
|
||||
u, err := url.Parse(requestURL)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to parse request URL", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// Ensure endpoint trimming to avoid leading slashes
|
||||
endpoint := strings.Trim(u.Path, "/")
|
||||
schemaFileName := fmt.Sprintf("%s.json", endpoint)
|
||||
|
||||
fmt.Println("Handling request for endpoint:", endpoint)
|
||||
|
||||
pluginsConfig, err := plugins.LoadPluginsConfig("plugins/config.yaml")
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load plugins configuration: %v", err)
|
||||
http.Error(w, "Failed to load plugins configuration", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
_, validators, err := plugins.NewValidatorProvider(pluginsConfig)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to create PluginManager: %v", err)
|
||||
http.Error(w, "Failed to create PluginManager", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
for fileName, validator := range validators {
|
||||
fmt.Printf("%s: %v\n", fileName, validator)
|
||||
}
|
||||
requestURL := "http://example.com/select"
|
||||
|
||||
// Extract endpoint from request URL
|
||||
u, err := url.Parse(requestURL)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to parse request URL: %v", err)
|
||||
}
|
||||
schemaFileName := fmt.Sprintf("%s.json", strings.Trim(u.Path, "/"))
|
||||
|
||||
//approch 1 start
|
||||
// endpoint := strings.Trim(u.Path, "/")
|
||||
|
||||
payloadData, err := ioutil.ReadFile("plugins/test/payload.json") //approach 2
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read payload data: %v", err)
|
||||
}
|
||||
// var payload Payload
|
||||
// if err := json.Unmarshal(payloadData, &payload); err != nil {
|
||||
// log.Fatalf("Failed to unmarshal payload: %v", err)
|
||||
// }
|
||||
// domain := strings.Replace(strings.ToLower(payload.Context.Domain), ":", "_", -1)
|
||||
// schemaFileName := fmt.Sprintf("%s_%s.json.%s", domain,
|
||||
// strings.ToLower(payload.Context.Version), endpoint)
|
||||
|
||||
//end
|
||||
|
||||
validator, exists := validators[schemaFileName]
|
||||
if !exists {
|
||||
log.Fatalf("Validator not found for %s", schemaFileName)
|
||||
http.Error(w, fmt.Sprintf("Validator not found for %s", schemaFileName), http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
ctx := context.Background()
|
||||
|
||||
payloadData, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
http.Error(w, "Failed to read payload data", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
err = validator.Validate(ctx, payloadData)
|
||||
if err != nil {
|
||||
fmt.Printf("Document validation failed: %v\n", err)
|
||||
http.Error(w, fmt.Sprintf("Document validation failed: %v", err), http.StatusBadRequest)
|
||||
} else {
|
||||
fmt.Println("Document validation succeeded!")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte("Document validation succeeded!"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user