created a plugin for schema validation and related unit test

This commit is contained in:
AshwiniK-protean
2025-02-14 11:05:54 +05:30
parent 91f0b16b5c
commit 50f93d8239
10 changed files with 600 additions and 0 deletions

View 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.0089, 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": "example-test-bap.com/static-terms.txt"
}
]
}
]
}
}
}
}

294
plugins/schemas/schema.json Normal file
View File

@@ -0,0 +1,294 @@
{
"$id": "http://example.com/schema/search",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"context": {
"type": "object",
"properties": {
"domain": {
"type": "string",
"description": "Domain code relevant to this transaction context"
},
"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"],
"allOf": [
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "SETTLEMENT_TYPE"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"value": {
"enum": ["upi", "neft", "rtgs"]
}
}
}
},
{
"if": {
"properties": {
"descriptor": {
"properties": {
"code": {
"const": "DELAY_INTEREST"
}
},
"required": ["code"]
}
}
},
"then": {
"properties": {
"value": {
"pattern": "^\\d+(\\.\\d{1,2})?$"
}
}
}
}
]
}
}
}
}
},
{
"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"]
}
},
"required": ["context", "message"]
}