From cab6fd6355e03a307fc7139b48a7e05ada7916f4 Mon Sep 17 00:00:00 2001 From: Abhishek Y Date: Mon, 23 Sep 2024 18:39:46 +0530 Subject: [PATCH 1/3] P26 Support for Open API 3.1 --- package-lock.json | 147 +- package.json | 5 +- schemas/ONDC_TRV10_2.0.1.yaml | 5109 +++++++++++++++++ schemas/context_2.0.1.json | 9 + schemas/core_2.0.1.yaml | 5109 +++++++++++++++++ src/app.ts | 2 + src/middlewares/schemaValidator.middleware.ts | 21 +- .../schemaValidatorAjv.middleware.ts | 285 + 8 files changed, 10623 insertions(+), 64 deletions(-) create mode 100644 schemas/ONDC_TRV10_2.0.1.yaml create mode 100644 schemas/context_2.0.1.json create mode 100644 schemas/core_2.0.1.yaml create mode 100644 src/middlewares/schemaValidatorAjv.middleware.ts diff --git a/package-lock.json b/package-lock.json index 4ef3a88..9241f12 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,6 +9,8 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", "amqplib": "^0.10.0", "axios": "^0.26.1", "axios-retry": "^4.0.0", @@ -16,12 +18,13 @@ "cors": "^2.8.5", "dotenv": "^16.4.1", "express": "^4.18.1", - "express-openapi-validator": "^5.1.6", + "express-openapi-validator": "^6.0.0-alpha.3", "express-status-monitor": "^1.3.4", "ioredis": "^5.0.6", "libsodium-wrappers": "^0.7.9", "mongodb": "^4.7.0", "node-mocks-http": "^1.15.0", + "openapi-types": "^12.1.3", "request-ip": "^3.3.0", "uuid": "^8.3.2", "winston": "^3.7.2", @@ -44,9 +47,9 @@ } }, "node_modules/@apidevtools/json-schema-ref-parser": { - "version": "11.6.4", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.6.4.tgz", - "integrity": "sha512-9K6xOqeevacvweLGik6LnZCb1fBtCOSIWQs8d096XGeqoLKC33UVMGz9+77Gw44KvbH4pKcQPWo4ZpxkXYj05w==", + "version": "11.7.0", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.7.0.tgz", + "integrity": "sha512-pRrmXMCwnmrkS3MLgAIW5dXRzeTv6GLjkjb4HmxNnvAKXN1Nfzp4KmGADBQvlVUcqi+a5D+hfGDLLnd5NnYxog==", "dependencies": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.15", @@ -355,14 +358,14 @@ "license": "MIT" }, "node_modules/ajv": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", - "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dependencies": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" }, "funding": { "type": "github", @@ -383,9 +386,9 @@ } }, "node_modules/ajv-formats": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", - "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", "dependencies": { "ajv": "^8.0.0" }, @@ -1133,13 +1136,13 @@ } }, "node_modules/express-openapi-validator": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/express-openapi-validator/-/express-openapi-validator-5.2.0.tgz", - "integrity": "sha512-7YMLsnC9MfeCa/nb2YnAxxRKGzkZ6GucjCcZc+IZU6AHq0TZ3vLOGhXT+uqMV3QiCJWy0XdzQtrUBwGD8eBEaQ==", + "version": "6.0.0-alpha.3", + "resolved": "https://registry.npmjs.org/express-openapi-validator/-/express-openapi-validator-6.0.0-alpha.3.tgz", + "integrity": "sha512-88KU8y2d5wTmtpgmz0MkFW25leh77wXPqd0aNdiWIS/C+faLLjn6Lcew6Y64nBehdZ1Cv9VTnoztjMm5PHn+zA==", "dependencies": { - "@apidevtools/json-schema-ref-parser": "^11.6.2", + "@apidevtools/json-schema-ref-parser": "^11.7.0", "@types/multer": "^1.4.11", - "ajv": "^8.14.0", + "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", "content-type": "^1.0.5", @@ -1155,10 +1158,26 @@ "express": "*" } }, + "node_modules/express-openapi-validator/node_modules/ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, "node_modules/express-openapi-validator/node_modules/path-to-regexp": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.2.tgz", - "integrity": "sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw==" + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==" }, "node_modules/express-status-monitor": { "version": "1.3.4", @@ -1221,6 +1240,11 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "node_modules/fast-uri": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", + "integrity": "sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==" + }, "node_modules/fecha": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", @@ -2015,6 +2039,11 @@ "@jsdevtools/ono": "7.1.3" } }, + "node_modules/openapi-types": { + "version": "12.1.3", + "resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.1.3.tgz", + "integrity": "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==" + }, "node_modules/parseqs": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz", @@ -2731,14 +2760,6 @@ "node": ">= 0.8" } }, - "node_modules/uri-js": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", - "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dependencies": { - "punycode": "^2.1.0" - } - }, "node_modules/url-parse": { "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", @@ -2959,9 +2980,9 @@ }, "dependencies": { "@apidevtools/json-schema-ref-parser": { - "version": "11.6.4", - "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.6.4.tgz", - "integrity": "sha512-9K6xOqeevacvweLGik6LnZCb1fBtCOSIWQs8d096XGeqoLKC33UVMGz9+77Gw44KvbH4pKcQPWo4ZpxkXYj05w==", + "version": "11.7.0", + "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-11.7.0.tgz", + "integrity": "sha512-pRrmXMCwnmrkS3MLgAIW5dXRzeTv6GLjkjb4HmxNnvAKXN1Nfzp4KmGADBQvlVUcqi+a5D+hfGDLLnd5NnYxog==", "requires": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.15", @@ -3237,26 +3258,25 @@ "integrity": "sha512-QbJ0NTQ/I9DI3uSJA4cbexiwQeRAfjPScqIbSjUDd9TOrcg6pTkdgziesOqxBMBzit8vFCTwrP27t13vFOORRA==" }, "ajv": { - "version": "8.16.0", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.16.0.tgz", - "integrity": "sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", + "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "requires": { "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", "json-schema-traverse": "^1.0.0", - "require-from-string": "^2.0.2", - "uri-js": "^4.4.1" + "require-from-string": "^2.0.2" } }, "ajv-draft-04": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/ajv-draft-04/-/ajv-draft-04-1.0.0.tgz", - "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==", - "requires": {} + "integrity": "sha512-mv00Te6nmYbRp5DCwclxtt7yV/joXJPGS7nM+97GdxvuttCOfgI3K4U25zboyeX0O+myI8ERluxQe5wljMmVIw==" }, "ajv-formats": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", - "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", "requires": { "ajv": "^8.0.0" } @@ -3868,13 +3888,13 @@ } }, "express-openapi-validator": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/express-openapi-validator/-/express-openapi-validator-5.2.0.tgz", - "integrity": "sha512-7YMLsnC9MfeCa/nb2YnAxxRKGzkZ6GucjCcZc+IZU6AHq0TZ3vLOGhXT+uqMV3QiCJWy0XdzQtrUBwGD8eBEaQ==", + "version": "6.0.0-alpha.3", + "resolved": "https://registry.npmjs.org/express-openapi-validator/-/express-openapi-validator-6.0.0-alpha.3.tgz", + "integrity": "sha512-88KU8y2d5wTmtpgmz0MkFW25leh77wXPqd0aNdiWIS/C+faLLjn6Lcew6Y64nBehdZ1Cv9VTnoztjMm5PHn+zA==", "requires": { - "@apidevtools/json-schema-ref-parser": "^11.6.2", + "@apidevtools/json-schema-ref-parser": "^11.7.0", "@types/multer": "^1.4.11", - "ajv": "^8.14.0", + "ajv": "^8.17.1", "ajv-draft-04": "^1.0.0", "ajv-formats": "^2.1.1", "content-type": "^1.0.5", @@ -3887,10 +3907,18 @@ "path-to-regexp": "^6.2.2" }, "dependencies": { + "ajv-formats": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", + "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", + "requires": { + "ajv": "^8.0.0" + } + }, "path-to-regexp": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.2.tgz", - "integrity": "sha512-GQX3SSMokngb36+whdpRXE+3f9V8UzyAorlYvOGx87ufGHehNTn5lCxrKtLyZ4Yl/wEKnNnr98ZzOwwDZV5ogw==" + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.3.0.tgz", + "integrity": "sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==" } } }, @@ -3931,6 +3959,11 @@ "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, + "fast-uri": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.0.1.tgz", + "integrity": "sha512-MWipKbbYiYI0UC7cl8m/i/IWTqfC8YXsqjzybjddLsFjStroQzsHXkc73JutMvBiXmOvapk+axIl79ig5t55Bw==" + }, "fecha": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/fecha/-/fecha-4.2.3.tgz", @@ -4515,6 +4548,11 @@ "@jsdevtools/ono": "7.1.3" } }, + "openapi-types": { + "version": "12.1.3", + "resolved": "https://registry.npmjs.org/openapi-types/-/openapi-types-12.1.3.tgz", + "integrity": "sha512-N4YtSYJqghVu4iek2ZUvcN/0aqH1kRDuNqzcycDxhOUpg7GdvLa2F3DgS6yBNhInhv2r/6I0Flkn7CqL8+nIcw==" + }, "parseqs": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz", @@ -5068,14 +5106,6 @@ "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" }, - "uri-js": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", - "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "requires": { - "punycode": "^2.1.0" - } - }, "url-parse": { "version": "1.5.10", "resolved": "https://registry.npmjs.org/url-parse/-/url-parse-1.5.10.tgz", @@ -5195,8 +5225,7 @@ "ws": { "version": "7.5.10", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", - "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", - "requires": {} + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==" }, "xmlhttprequest-ssl": { "version": "1.6.3", diff --git a/package.json b/package.json index f605082..508c034 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,8 @@ "typescript": "^4.7.3" }, "dependencies": { + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", "amqplib": "^0.10.0", "axios": "^0.26.1", "axios-retry": "^4.0.0", @@ -32,12 +34,13 @@ "cors": "^2.8.5", "dotenv": "^16.4.1", "express": "^4.18.1", - "express-openapi-validator": "^5.1.6", + "express-openapi-validator": "^6.0.0-alpha.3", "express-status-monitor": "^1.3.4", "ioredis": "^5.0.6", "libsodium-wrappers": "^0.7.9", "mongodb": "^4.7.0", "node-mocks-http": "^1.15.0", + "openapi-types": "^12.1.3", "request-ip": "^3.3.0", "uuid": "^8.3.2", "winston": "^3.7.2", diff --git a/schemas/ONDC_TRV10_2.0.1.yaml b/schemas/ONDC_TRV10_2.0.1.yaml new file mode 100644 index 0000000..8fa19ac --- /dev/null +++ b/schemas/ONDC_TRV10_2.0.1.yaml @@ -0,0 +1,5109 @@ +openapi: 3.1.0 +info: + description: Adaptation of beckn protocol for the mobility sector. Compatible with core version V1.1. + title: Beckn Mobility API Specification + version: 0.8.3 +security: + - SubscriberAuth: [] +servers: + - url: "https://ps-bap-client.becknprotocol.io" + description: BOC Network +paths: + /search: + post: + description: Search for services by intent + operationId: search + tags: + - Beckn Provider Platform (BPP) + - Beckn Gateway (BG) + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + intent: + $ref: "#/components/schemas/Intent" + type: object + required: + - context + - message + - allOf: + - properties: + context: + properties: + location: + properties: + city: + properties: + code: + type: string + required: + - code + country: + properties: + code: + type: string + enum: + - IND + required: + - code + bap_id: + type: string + pattern: "^(?!https?://).*$" + bpp_id: + type: string + pattern: "^(?!https?://).*$" + ttl: + type: string + # format: date-time + timestamp: + type: string + format: date-time + required: + - location + - domain + - action + - message_id + - transaction_id + - timestamp + - bap_id + - bap_uri + - ttl + - properties: + context: + properties: + action: + type: string + enum: + - search + - properties: + message: + properties: + intent: + properties: + tags: + items: + properties: + list: + items: + properties: + value: + type: string + enum: + - START + - STOP + payment: + properties: + collected_by: + type: string + enum: + - BPP + - BAP + required: + - collected_by + required: + - payment + - tags + required: + - intent + - properties: + message: + properties: + intent: + properties: + payment: + 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 + required: + - code + value: + type: string + format: uri + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TYPE + required: + - code + value: + type: string + enum: + - upi + - neft + - rtgs + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_WINDOW + required: + - code + value: + type: string + pattern: '^PT\d+[MH]$' + required: + - descriptor + - value + - properties: + message: + properties: + intent: + properties: + fulfillment: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + required: + - fulfillment + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + /select: + post: + description: Select items from the catalog and build your order + operationId: select + tags: + - Beckn Provider Platform (BPP) + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - select + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + /init: + post: + description: Initialize an order by providing billing and/or shipping details + operationId: init + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + required: + - context + - message + - allOf: + - allOf: + - $ref: "#/paths/~1search/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + required: + - bpp_id + - bpp_uri + - properties: + context: + properties: + action: + type: string + enum: + - init + - properties: + message: + properties: + order: + type: object + properties: + provider: + type: object + properties: + id: + type: string + required: + - id + items: + type: array + items: + type: object + properties: + id: + type: string + required: + - id + required: + - provider + - items + - allOf: + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - $ref: "#/paths/~1on_select/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - properties: + message: + properties: + order: + required: + - fulfillments + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + type: object + properties: + type: + type: string + enum: + - PRE-ORDER + - ON-FULFILLMENT + - POST-FULFILLMENT + status: + type: string + enum: + - PAID + - NOT-PAID + collected_by: + type: string + enum: + - BAP + - BPP + params: + type: object + properties: + amount: + type: string + pattern: '^\d+(\.\d{1,2})?$' + currency: + type: string + required: + - type + - status + - collected_by + - params + required: + - payments + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + params: + required: + - bank_code + - bank_account_number + - virtual_payment_address + required: + - type + - status + - collected_by + - params + required: + - payments + - properties: + message: + properties: + order: + properties: + billing: + required: + - name + required: + - billing + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /confirm: + post: + description: Initialize an order by providing billing and/or shipping details + operationId: confirm + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - confirm + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - allOf: + - $ref: "#/paths/~1on_select/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - properties: + customer: + properties: + contact: + properties: + phone: + type: string + pattern: '^\+?[1-9]\d{1,14}$' + required: + - phone + person: + properties: + name: + type: string + required: + - name + required: + - contact + - person + required: + - customer + - allOf: + - properties: + message: + properties: + order: + 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 + - 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 + - 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 + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - allOf: + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - BUYER_FINDER_FEES_PERCENTAGE + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + allOf: + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: BUYER_FINDER_FEES_PERCENTAGE + required: + - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + allOf: + - if: + properties: + ? descriptor + : ? properties + : code: + ? enum + : - BUYER_FINDER_FEES_PERCENTAGE + then: + properties: + value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - descriptor + - value + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - SETTLEMENT_WINDOW + - SETTLEMENT_BASIS + - SETTLEMENT_TYPE + - MANDATORY_ARBITRATION + - COURT_JURISDICTION + - DELAY_INTEREST + - STATIC_TERMS + - SETTLEMENT_AMOUNT + - properties: + message: + properties: + order: + properties: + payments: + items: + 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 + required: + - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: SETTLEMENT_TYPE + required: + - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: SETTLEMENT_WINDOW + required: + - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + allOf: + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_WINDOW + then: + properties: + value: + type: string + pattern: '^P(?!$)(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$' + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_BASIS + then: + properties: + value: + type: string + enum: + - INVOICE_RECEIPT + - DELIVERY + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: MANDATORY_ARBITRATION + then: + properties: + value: + type: string + pattern: ^(true|false)$ + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: STATIC_TERMS + then: + properties: + value: + type: string + format: uri + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: COURT_JURISDICTION + then: + properties: + value: + type: string + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: DELAY_INTEREST + then: + properties: + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_TYPE + then: + properties: + value: + type: string + enum: + - UPI + - NEFT + - RTGS + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_AMOUNT + then: + properties: + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: BUYER_FINDER_FEES + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TERMS + required: + - code + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + properties: + type: + type: string + params: + type: object + properties: + transaction_id: + type: string + required: + - type + allOf: + - if: + properties: + type: + const: PRE-ORDER + then: + properties: + params: + required: + - transaction_id + required: + - payments + - properties: + message: + properties: + order: + not: + required: + - id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /status: + post: + description: Fetch the latest order object + operationId: status + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - status + - properties: + message: + properties: + order_id: + type: string + required: + - order_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /update: + post: + description: Remove object + operationId: update + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - update + required: + - bpp_id + - bpp_uri + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + description: Updated order object + required: + - id + update_target: + description: 'Comma separated values of order objects being updated. For example: ```"update_target":"item,billing,fulfillment"```' + type: string + required: + - update_target + - order + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - update + - properties: + message: + type: object + properties: + order: + type: object + properties: + id: + type: string + required: + - id + update_target: + type: string + pattern: "^[^,]+(,[^,]+)*$" + required: + - order + - update_target + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /rating: + post: + description: Provide feedback on a service + operationId: rating + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - rating + message: + properties: + ratings: + type: array + items: + $ref: "#/components/schemas/Rating" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - rating + - properties: + message: + properties: + ratings: + type: array + minItems: 1 + items: + type: object + properties: + id: + type: string + value: + type: number + rating_category: + type: string + enum: + - RIDER + - DRIVER + - SERVICE + required: + - id + - value + - rating_category + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /support: + post: + description: Contact support + operationId: support + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - support + message: + properties: + support: + $ref: "#/components/schemas/Support" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - support + - properties: + message: + properties: + support: + properties: + ref_id: + type: string + required: + - ref_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /track: + post: + description: Track an active order + operationId: track + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - track + message: + additionalProperties: false + properties: + callback_url: + format: uri + type: string + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - track + - properties: + message: + properties: + order_id: + type: string + required: + - order_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /cancel: + post: + description: Cancel an order + operationId: cancel + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - cancel + message: + properties: + cancellation_reason_id: + $ref: "#/components/schemas/Option/properties/id" + descriptor: + $ref: "#/components/schemas/Descriptor" + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - cancel + - properties: + message: + properties: + order_id: + type: string + descriptor: + properties: + code: + type: string + enum: + - SOFT_CANCEL + - CONFIRM_CANCEL + required: + - code + cancellation_reason_id: + type: string + pattern: "^[0-9]+$" + required: + - order_id + - descriptor + - cancellation_reason_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /on_search: + post: + description: Send catalog + operationId: on_search + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + catalog: + $ref: "#/components/schemas/Catalog" + required: + - catalog + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_search + - properties: + message: + properties: + catalog: + type: object + properties: + descriptor: + type: object + properties: + name: + type: string + images: + type: array + items: + minItems: 1 + required: + - name + required: + - descriptor + - properties: + message: + properties: + catalog: + type: object + properties: + providers: + type: array + minItems: 1 + items: + type: object + properties: + id: + type: string + required: + - id + required: + - providers + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + fulfillments: + type: array + minItems: 1 + items: + properties: + vehicle: + properties: + category: + type: string + enum: + - AUTO_RICKSHAW + - CAB + required: + - category + type: + type: string + enum: + - DELIVERY + required: + - id + - vehicle + - type + required: + - fulfillments + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + items: + type: array + minItems: 1 + items: + type: object + properties: + descriptor: + type: object + properties: + name: + type: string + code: + type: string + enum: + - RIDE + required: + - code + price: + type: object + properties: + value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - value + - currency + fulfillment_ids: + type: array + minItems: 1 + payment_ids: + type: array + minItems: 1 + required: + - id + - descriptor + - price + - fulfillment_ids + - payment_ids + required: + - items + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + type: array + minItems: 1 + items: + type: object + properties: + type: + type: string + collected_by: + type: string + required: + - collected_by + required: + - payments + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + fulfillments: + items: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + - allOf: + - allOf: + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - BUYER_FINDER_FEES_PERCENTAGE + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + allOf: + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: BUYER_FINDER_FEES_PERCENTAGE + ? required + : - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + allOf: + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : ? enum + : - BUYER_FINDER_FEES_PERCENTAGE + then: + ? properties + : value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - descriptor + - value + - allOf: + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - SETTLEMENT_WINDOW + - SETTLEMENT_BASIS + - SETTLEMENT_TYPE + - MANDATORY_ARBITRATION + - COURT_JURISDICTION + - DELAY_INTEREST + - STATIC_TERMS + - SETTLEMENT_AMOUNT + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + 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 + ? required + : - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: SETTLEMENT_TYPE + ? required + : - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: SETTLEMENT_WINDOW + ? required + : - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + allOf: + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_WINDOW + then: + ? properties + : value: + type: string + pattern: '^P(?!$)(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$' + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_BASIS + then: + ? properties + : value: + type: string + enum: + - INVOICE_RECEIPT + - DELIVERY + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: MANDATORY_ARBITRATION + then: + ? properties + : value: + type: string + pattern: ^(true|false)$ + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: STATIC_TERMS + then: + ? properties + : value: + type: string + format: uri + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: COURT_JURISDICTION + then: + ? properties + : value: + type: string + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: DELAY_INTEREST + then: + ? properties + : value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_TYPE + then: + ? properties + : value: + type: string + enum: + - UPI + - NEFT + - RTGS + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_AMOUNT + then: + ? properties + : value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: BUYER_FINDER_FEES + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TERMS + required: + - code + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - context + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + - Beckn Gateway (BG) + /on_select: + post: + description: Send draft order object with quoted price for selected items + operationId: on_select + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_select + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - allOf: + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + required: + - id + required: + - fulfillments + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + state: + type: object + properties: + descriptor: + type: object + properties: + code: + type: string + enum: + - RIDE_ASSIGNED + - RIDE_ENROUTE_PICKUP + - RIDE_ARRIVED_PICKUP + - RIDE_STARTED + - RIDE_ENDED + - RIDE_CANCELLED + required: + - code + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + properties: + stops: + items: + properties: + authorization: + type: object + properties: + type: + type: string + enum: + - OTP + - QR + token: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - type + - token + - properties: + message: + properties: + order: + properties: + fulfillments: + items: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + vehicle: + properties: + category: + type: string + enum: + - AUTO_RICKSHAW + - CAB + required: + - category + required: + - vehicle + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - not: + required: + - agent + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_init: + post: + description: Send order object with payment details updated + operationId: on_init + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_init + - properties: + message: + properties: + order: + properties: + provider: + type: object + properties: + id: + type: string + required: + - id + required: + - provider + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - properties: + message: + properties: + order: + properties: + items: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: FARE_POLICY + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: INFO + required: + - code + - properties: + message: + properties: + order: + properties: + items: + type: array + minItems: 1 + items: + type: object + properties: + fulfillment_ids: + minItems: 1 + location_ids: + minItems: 1 + required: + - fulfillment_ids + - location_ids + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + type: + type: string + enum: + - DELIVERY + required: + - type + - allOf: + - properties: + message: + properties: + order: + properties: + quote: + type: object + properties: + price: + type: object + properties: + currency: + type: string + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - currency + - value + breakup: + type: array + items: + type: object + properties: + price: + type: object + properties: + currency: + type: string + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - currency + - value + title: + type: string + enum: + - BASE_FARE + - DISTANCE_FARE + - TAX + - DISCOUNT + - WAITING_CHARG + - CANCELLATION_CHARGES + required: + - price + - title + required: + - price + - breakup + required: + - quote + - properties: + message: + properties: + order: + properties: + quote: + properties: + breakup: + allOf: + - contains: + type: object + properties: + title: + const: BASE_FARE + price: + type: object + properties: + value: + type: string + required: + - value + required: + - title + - price + - contains: + type: object + properties: + title: + const: DISTANCE_FARE + price: + type: object + properties: + value: + type: string + required: + - value + required: + - title + - price + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + cancellation_terms: + items: + properties: + fulfillment_state: + properties: + descriptor: + properties: + code: + type: string + enum: + - RIDE_ASSIGNED + - RIDE_ENROUTE_PICKUP + - RIDE_ARRIVED_PICKUP + - RIDE_STARTED + required: + - code + cancellation_fee: + oneOf: + - properties: + percentage: + type: string + pattern: '^(100(\.0{1,2})?|(\d{1,2})(\.\d{1,2})?)$' + required: + - percentage + - properties: + amount: + properties: + value: + type: string + pattern: '^[+-]?(\d+(\.\d*)?|\.\d+)$' + required: + - currency + - value + required: + - amount + required: + - fulfillment_state + - cancellation_fee + required: + - cancellation_terms + - properties: + message: + type: object + required: + - message + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_confirm: + post: + description: Send active order object + operationId: on_confirm + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_confirm + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - COMPLETE + - ACTIVE + required: + - status + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - COMPLETE + - ACTIVE + - CANCELLED + - SOFT_CANCEL + required: + - status + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_status: + post: + description: Fetch the status of a Service + operationId: on_status + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_status + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - allOf: + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - properties: + agent: + properties: + contact: + properties: + phone: + type: string + pattern: '^\+?[1-9]\d{1,14}$' + required: + - phone + person: + properties: + name: + type: string + required: + - name + required: + - contact + - person + required: + - agent + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + properties: + type: + type: string + params: + type: object + properties: + transaction_id: + type: string + required: + - type + allOf: + - if: + properties: + type: + const: PRE-ORDER + then: + properties: + params: + required: + - transaction_id + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + properties: + vehicle: + type: object + properties: + registration: + type: string + required: + - registration + - make + - model + required: + - vehicle + - properties: + message: + properties: + order: + properties: + fulfillments: + items: + required: + - state + - properties: + message: + properties: + order: + required: + - id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_update: + post: + description: Returns updated service with updated runtime object + operationId: on_update + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_update + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_update + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_rating: + post: + description: Provide feedback on a service + operationId: on_rating + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_rating + error: + $ref: "#/components/schemas/Error" + message: + properties: + feedback_form: + allOf: + - $ref: "#/components/schemas/XInput" + description: A feedback form to allow the user to provide additional information on the rating provided + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_rating + - properties: + message: + properties: + feedback_form: + type: object + properties: + required: + type: boolean + form: + type: object + required: + - required + allOf: + - if: + properties: + required: + const: true + then: + required: + - form + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_support: + post: + description: Contact Support + operationId: on_support + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_support + error: + $ref: "#/components/schemas/Error" + message: + properties: + support: + $ref: "#/components/schemas/Support" + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_support + - properties: + message: + properties: + support: + type: object + properties: + email: + type: string + format: email + phone: + type: string + url: + type: string + format: uri + anyOf: + - required: + - email + - required: + - phone + - required: + - url + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_track: + post: + description: Send tracking details of an active order + operationId: on_track + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_track + error: + $ref: "#/components/schemas/Error" + message: + properties: + tracking: + $ref: "#/components/schemas/Tracking" + required: + - tracking + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_track + - properties: + message: + properties: + tracking: + type: object + properties: + status: + type: string + url: + type: string + location: + type: object + properties: + latitude: + type: number + longitude: + type: number + required: + - status + oneOf: + - required: + - url + - required: + - location + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_cancel: + post: + description: Send cancellation request_id with reasons list in case of cancellation request. Else send cancelled order object + operationId: on_cancel + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_cancel + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_cancel + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - CANCELLED + - SOFT_CANCEL + required: + - status + - properties: + message: + properties: + order: + properties: + cancellation_terms: + items: + required: + - reason_required + required: + - cancellation_terms + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) +components: + securitySchemes: + SubscriberAuth: + description: 'Signature of message body using BAP or BPP subscriber''s signing public key.

Format:

Authorization : Signature keyId="{subscriber_id}|{unique_key_id}|{algorithm}",algorithm="ed25519",created="1606970629",expires="1607030629",headers="(created) (expires) digest",signature="Base64(BLAKE-512(signing string))"' + in: header + name: Authorization + type: apiKey + schemas: + Ack: + additionalProperties: false + description: "Describes the acknowledgement sent in response to an API call. If the implementation uses HTTP/S, then Ack must be returned in the same session. Every API call to a BPP must be responded to with an Ack whether the BPP intends to respond with a callback or not. This has one property called `status` that indicates the status of the Acknowledgement." + properties: + status: + description: "The status of the acknowledgement. If the request passes the validation criteria of the BPP, then this is set to ACK. If a BPP responds with status = `ACK` to a request, it is required to respond with a callback. If the request fails the validation criteria, then this is set to NACK. Additionally, if a BPP does not intend to respond with a callback even after the request meets the validation criteria, it should set this value to `NACK`." + enum: + - ACK + - NACK + type: string + tags: + description: A list of tags containing any additional information sent along with the Acknowledgement. + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: object + AddOn: + additionalProperties: false + description: Describes an add-on + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + description: "ID of the add-on. This follows the syntax {item.id}/add-on/{add-on unique id} for item specific add-on OR " + type: string + price: + $ref: "#/components/schemas/Price" + type: object + Address: + description: Describes a postal address. + type: string + Agent: + additionalProperties: false + description: "Describes the direct performer, driver or executor that fulfills an order. It is usually a person. But in some rare cases, it could be a non-living entity like a drone, or a bot. Some examples of agents are Doctor in the healthcare sector, a driver in the mobility sector, or a delivery person in the logistics sector. This object can be set at any stage of the order lifecycle. This can be set at the discovery stage when the BPP wants to provide details on the agent fulfilling the order, like in healthcare, where the doctor's name appears during search. This object can also used to search for a particular person that the customer wants fulfilling an order. Sometimes, this object gets instantiated after the order is confirmed, like in the case of on-demand taxis, where the driver is assigned after the user confirms the ride." + properties: + contact: + $ref: "#/components/schemas/Contact" + organization: + $ref: "#/components/schemas/Organization" + person: + $ref: "#/components/schemas/Person" + rating: + $ref: "#/components/schemas/Rating/properties/value" + type: object + Authorization: + additionalProperties: false + description: Describes an authorization mechanism + properties: + status: + description: Status of the token + type: string + token: + description: Token used for authorization + type: string + type: + description: Type of authorization mechanism used + type: string + valid_from: + description: Timestamp in RFC3339 format from which token is valid + format: date-time + type: string + valid_to: + description: Timestamp in RFC3339 format until which token is valid + format: date-time + type: string + type: object + Billing: + additionalProperties: false + description: "Describes the billing details of an entity.
This has properties like name,organization,address,email,phone,time,tax_number, created_at,updated_at" + properties: + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The address of the billable entity + city: + allOf: + - $ref: "#/components/schemas/City" + description: The city where the billable entity resides. + email: + description: Email address where the bill is sent to + format: email + type: string + name: + description: Name of the billable entity + type: string + organization: + allOf: + - $ref: "#/components/schemas/Organization" + description: Details of the organization being billed. + phone: + description: Phone number of the billable entity + type: string + state: + allOf: + - $ref: "#/components/schemas/State" + description: The state where the billable entity resides. This is important for state-level tax calculation + tax_id: + description: ID of the billable entity as recognized by the taxation authority + type: string + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Details regarding the billing period + type: object + Cancellation: + additionalProperties: false + description: Describes a cancellation event + properties: + additional_description: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Any additional information regarding the nature of cancellation + cancelled_by: + type: string + reason: + allOf: + - $ref: "#/components/schemas/Option" + description: The reason for cancellation + time: + description: Date-time when the order was cancelled by the buyer + format: date-time + type: string + type: object + CancellationTerm: + additionalProperties: false + description: Describes the cancellation terms of an item or an order. This can be referenced at an item or order level. Item-level cancellation terms can override the terms at the order level. + properties: + cancel_by: + allOf: + - $ref: "#/components/schemas/Time" + description: Information related to the time of cancellation. + cancellation_fee: + $ref: "#/components/schemas/Fee" + external_ref: + $ref: "#/components/schemas/MediaFile" + fulfillment_state: + allOf: + - $ref: "#/components/schemas/FulfillmentState" + description: The state of fulfillment during which this term is applicable. + reason_required: + description: Indicates whether a reason is required to cancel the order + type: boolean + xinput: + $ref: "#/components/schemas/XInput" + required: + - cancellation_fee + type: object + Catalog: + additionalProperties: false + description: "Describes the products or services offered by a BPP. This is typically sent as the response to a search intent from a BAP. The payment terms, offers and terms of fulfillment supported by the BPP can also be included here. The BPP can show hierarchical nature of products/services in its catalog using the parent_category_id in categories. The BPP can also send a ttl (time to live) in the context which is the duration for which a BAP can cache the catalog and use the cached catalog.
This has properties like bbp/descriptor,bbp/categories,bbp/fulfillments,bbp/payments,bbp/offers,bbp/providers and exp
This is used in the following situations.
" + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + exp: + description: Timestamp after which catalog will expire + format: date-time + type: string + fulfillments: + description: Fulfillment modes offered at the BPP level. This is used when a BPP itself offers fulfillments on behalf of the providers it has onboarded. + items: + $ref: "#/components/schemas/Fulfillment" + type: array + offers: + description: Offers at the BPP-level. This is common across all providers onboarded by the BPP. + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + description: Payment terms offered by the BPP for all transactions. This can be overriden at the provider level. + items: + $ref: "#/components/schemas/Payment" + type: array + providers: + items: + $ref: "#/components/schemas/Provider" + type: array + ttl: + description: Duration in seconds after which this catalog will expire + type: string + type: object + Category: + additionalProperties: false + description: A label under which a collection of items can be grouped. + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + description: ID of the category + type: string + parent_category_id: + $ref: "#/components/schemas/Category/properties/id" + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + ttl: + description: Time to live for an instance of this schema + type: object + Circle: + additionalProperties: false + description: Describes a circular region of a specified radius centered at a specified GPS coordinate. + properties: + gps: + $ref: "#/components/schemas/Gps" + radius: + $ref: "#/components/schemas/Scalar" + type: object + City: + additionalProperties: false + description: Describes a city + properties: + code: + description: City code + type: string + name: + description: Name of the city + type: string + type: object + Contact: + additionalProperties: false + properties: + email: + type: string + jcard: + description: A Jcard object as per draft-ietf-jcardcal-jcard-03 specification + type: object + phone: + type: string + type: object + Context: + additionalProperties: false + description: "Every API call in beckn protocol has a context. It provides a high-level overview to the receiver about the nature of the intended transaction. Typically, it is the BAP that sets the transaction context based on the consumer's location and action on their UI. But sometimes, during unsolicited callbacks, the BPP also sets the transaction context but it is usually the same as the context of a previous full-cycle, request-callback interaction between the BAP and the BPP. The context object contains four types of fields.
  1. Demographic information about the transaction using fields like `domain`, `country`, and `region`.
  2. Addressing details like the sending and receiving platform's ID and API URL.
  3. Interoperability information like the protocol version that implemented by the sender and,
  4. Transaction details like the method being called at the receiver's endpoint, the transaction_id that represents an end-to-end user session at the BAP, a message ID to pair requests with callbacks, a timestamp to capture sending times, a ttl to specifiy the validity of the request, and a key to encrypt information if necessary.
This object must be passed in every interaction between a BAP and a BPP. In HTTP/S implementations, it is not necessary to send the context during the synchronous response. However, in asynchronous protocols, the context must be sent during all interactions," + properties: + action: + description: The Beckn protocol method being called by the sender and executed at the receiver. + type: string + bap_id: + allOf: + - description: "A globally unique identifier of the platform, Typically it is the fully qualified domain name (FQDN) of the platform." + type: string + description: Subscriber ID of the BAP + bap_uri: + allOf: + - description: The callback URL of the Subscriber. This should necessarily contain the same domain name as set in `subscriber_id``. + format: uri + type: string + description: Subscriber URL of the BAP for accepting callbacks from BPPs. + bpp_id: + allOf: + - $ref: "#/components/schemas/Context/properties/bap_id/allOf/0" + description: Subscriber ID of the BPP + bpp_uri: + allOf: + - $ref: "#/components/schemas/Context/properties/bap_uri/allOf/0" + description: Subscriber URL of the BPP for accepting calls from BAPs. + domain: + allOf: + - $ref: "#/components/schemas/Domain/properties/code" + description: Domain code that is relevant to this transaction context + key: + description: The encryption public key of the sender + type: string + location: + allOf: + - $ref: "#/components/schemas/Location" + description: The location where the transaction is intended to be fulfilled. + required: + - country + - city + message_id: + description: "This is a unique value which persists during a request / callback cycle. Since beckn protocol APIs are asynchronous, BAPs need a common value to match an incoming callback from a BPP to an earlier call. This value can also be used to ignore duplicate messages coming from the BPP. It is recommended to generate a fresh message_id for every new interaction. When sending unsolicited callbacks, BPPs must generate a new message_id." + format: uuid + type: string + timestamp: + description: Time of request generation in RFC3339 format + format: date-time + type: string + transaction_id: + description: "This is a unique value which persists across all API calls from `search` through `confirm`. This is done to indicate an active user session across multiple requests. The BPPs can use this value to push personalized recommendations, and dynamic offerings related to an ongoing transaction despite being unaware of the user active on the BAP." + format: uuid + type: string + ttl: + description: The duration in ISO8601 format after timestamp for which this message holds valid + type: string + version: + description: Version of transaction protocol being used by the sender. + type: string + type: object + Country: + additionalProperties: false + description: Describes a country. + properties: + code: + description: Country code as per ISO 3166-1 and ISO 3166-2 format + type: string + name: + description: Name of the country + type: string + type: object + Credential: + additionalProperties: false + description: Describes a credential of an entity - Person or Organization + properties: + id: + type: string + type: + default: VerifiableCredential + type: string + url: + description: URL of the credential + format: uri + type: string + type: object + Customer: + additionalProperties: false + description: Describes a customer buying/availing a product or a service + properties: + contact: + $ref: "#/components/schemas/Contact" + person: + $ref: "#/components/schemas/Person" + type: object + DecimalValue: + description: Describes a decimal value + pattern: "^[+-]?([0-9]*[.])?[0-9]+" + type: string + Descriptor: + additionalProperties: false + description: Physical description of something. + properties: + additional_desc: + properties: + content_type: + enum: + - text/plain + - text/html + - application/json + type: string + url: + type: string + type: object + code: + type: string + images: + items: + $ref: "#/components/schemas/Image" + type: array + long_desc: + type: string + media: + items: + $ref: "#/components/schemas/MediaFile" + type: array + name: + type: string + short_desc: + type: string + type: object + Domain: + additionalProperties: false + description: "Described the industry sector or sub-sector. The network policy should contain codes for all the industry sectors supported by the network. Domains can be created in varying levels of granularity. The granularity of a domain can be decided by the participants of the network. Too broad domains will result in irrelevant search broadcast calls to BPPs that don't have services supporting the domain. Too narrow domains will result in a large number of registry entries for each BPP. It is recommended that network facilitators actively collaborate with various working groups and network participants to carefully choose domain codes keeping in mind relevance, performance, and opportunity cost. It is recommended that networks choose broad domains like mobility, logistics, healthcare etc, and progressively granularize them as and when the number of network participants for each domain grows large." + properties: + additional_info: + allOf: + - $ref: "#/components/schemas/MediaFile" + description: A url that contains addtional information about that domain. + code: + description: "Standard code representing the domain. The standard is usually published as part of the network policy. Furthermore, the network facilitator should also provide a mechanism to provide the supported domains of a network." + type: string + name: + description: Name of the domain + type: string + type: object + Duration: + description: Describes duration as per ISO8601 format + type: string + Error: + additionalProperties: false + description: "Describes an error object that is returned by a BAP, BPP or BG as a response or callback to an action by another network participant. This object is sent when any request received by a network participant is unacceptable. This object can be sent either during Ack or with the callback." + properties: + code: + description: 'Standard error code. For full list of error codes, refer to docs/protocol-drafts/BECKN-005-ERROR-CODES-DRAFT-01.md of this repo"' + type: string + message: + description: Human readable message describing the error. Used mainly for logging. Not recommended to be shown to the user. + type: string + paths: + description: Path to json schema generating the error. Used only during json schema validation errors + type: string + type: object + Fee: + additionalProperties: false + description: A fee applied on a particular entity + properties: + amount: + allOf: + - $ref: "#/components/schemas/Price" + description: A fixed value + percentage: + allOf: + - $ref: "#/components/schemas/DecimalValue" + description: Percentage of a value + type: object + Form: + additionalProperties: false + description: Describes a form + properties: + data: + additionalProperties: + type: string + description: The form submission data + type: object + mime_type: + description: This field indicates the nature and format of the form received by querying the url. MIME types are defined and standardized in IETF's RFC 6838. + enum: + - text/html + - application/xml + type: string + submission_id: + format: uuid + type: string + url: + description: "The URL from where the form can be fetched. The content fetched from the url must be processed as per the mime_type specified in this object. Once fetched, the rendering platform can choosed to render the form as-is as an embeddable element; or process it further to blend with the theme of the application. In case the interface is non-visual, the the render can process the form data and reproduce it as per the standard specified in the form." + format: uri + type: string + type: object + Fulfillment: + additionalProperties: false + description: Describes how a an order will be rendered/fulfilled to the end-customer + properties: + agent: + allOf: + - $ref: "#/components/schemas/Agent" + description: The agent that is currently handling the fulfillment of the order + contact: + $ref: "#/components/schemas/Contact" + customer: + allOf: + - $ref: "#/components/schemas/Customer" + description: The person that will ultimately receive the order + id: + description: Unique reference ID to the fulfillment of an order + type: string + path: + description: The physical path taken by the agent that can be rendered on a map. The allowed format of this property can be set by the network. + type: string + rateable: + description: Whether the fulfillment can be rated or not + type: boolean + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating value of the fulfullment service. + state: + allOf: + - $ref: "#/components/schemas/FulfillmentState" + description: The current state of fulfillment. The BPP must set this value whenever the state of the order fulfillment changes and fire an unsolicited `on_status` call. + stops: + description: The list of logical stops encountered during the fulfillment of an order. + items: + $ref: "#/components/schemas/Stop" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + tracking: + default: false + description: Indicates whether the fulfillment allows tracking + type: boolean + type: + description: "A code that describes the mode of fulfillment. This is typically set when there are multiple ways an order can be fulfilled. For example, a retail order can be fulfilled either via store pickup or a home delivery. Similarly, a medical consultation can be provided either in-person or via tele-consultation. The network policy must publish standard fulfillment type codes for the different modes of fulfillment." + type: string + vehicle: + $ref: "#/components/schemas/Vehicle" + type: object + FulfillmentState: + additionalProperties: false + description: Describes the state of fulfillment + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + updated_at: + format: date-time + type: string + updated_by: + description: ID of entity which changed the state + type: string + type: object + Gps: + description: Describes a gps coordinate + pattern: '^[-+]?([1-8]?\d(\.\d{6,})?|90(\.0{6,})?),\s*[-+]?(180(\.0{6,})?|((1[0-7]\d)|([1-9]?\d))(\.\d{6,})?)$' + type: string + Image: + additionalProperties: false + description: Describes an image + properties: + height: + description: Height of the image in pixels + type: string + size_type: + description: The size of the image. The network policy can define the default dimensions of each type + enum: + - xs + - sm + - md + - lg + - xl + - custom + type: string + url: + description: URL to the image. This can be a data url or an remote url + format: uri + type: string + width: + description: Width of the image in pixels + type: string + required: + - url + type: object + Intent: + additionalProperties: false + description: "The intent to buy or avail a product or a service. The BAP can declare the intent of the consumer containing
This has properties like descriptor,provider,fulfillment,payment,category,offer,item,tags
This is typically used by the BAP to send the purpose of the user's search to the BPP. This will be used by the BPP to find products or services it offers that may match the user's intent.
For example, in Mobility, the mobility consumer declares a mobility intent. In this case, the mobility consumer declares information that describes various aspects of their journey like,
For example, in health domain, a consumer declares the intent for a lab booking the describes various aspects of their booking like," + properties: + category: + allOf: + - $ref: "#/components/schemas/Category" + description: Details on the item category + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "A raw description of the search intent. Free text search strings, raw audio, etc can be sent in this object." + fulfillment: + allOf: + - $ref: "#/components/schemas/Fulfillment" + description: Details on how the customer wants their order fulfilled + item: + allOf: + - $ref: "#/components/schemas/Item" + description: Details of the item that the consumer wants to order + offer: + allOf: + - $ref: "#/components/schemas/Offer" + description: details on the offer the customer wants to avail + payment: + allOf: + - $ref: "#/components/schemas/Payment" + description: Details on how the customer wants to pay for the order + provider: + allOf: + - $ref: "#/components/schemas/Provider" + description: The provider from which the customer wants to place to the order from + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: object + Item: + additionalProperties: false + description: "Describes a product or a service offered to the end consumer by the provider. In the mobility sector, it can represent a fare product like one way journey. In the logistics sector, it can represent the delivery service offering. In the retail domain it can represent a product like a grocery item." + properties: + add_ons: + items: + $ref: "#/components/schemas/AddOn" + type: array + cancellation_terms: + description: Cancellation terms of this item + items: + $ref: "#/components/schemas/CancellationTerm" + type: array + category_ids: + description: Categories this item can be listed under + items: + allOf: + - $ref: "#/components/schemas/Category/properties/id" + type: array + creator: + allOf: + - $ref: "#/components/schemas/Organization" + description: The creator of this item + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Physical description of the item + fulfillment_ids: + description: Modes through which this item can be fulfilled + items: + allOf: + - $ref: "#/components/schemas/Fulfillment/properties/id" + type: array + id: + description: ID of the item. + type: string + location_ids: + description: Provider Locations this item is available in + items: + allOf: + - $ref: "#/components/schemas/Location/properties/id" + type: array + matched: + description: Whether this item is an exact match of the request + type: boolean + parent_item_id: + allOf: + - $ref: "#/components/schemas/Item/properties/id" + description: "ID of the item, this item is a variant of" + parent_item_quantity: + allOf: + - $ref: "#/components/schemas/ItemQuantity" + description: The number of units of the parent item this item is a multiple of + payment_ids: + description: Payment modalities through which this item can be ordered + items: + allOf: + - $ref: "#/components/schemas/Payment/properties/id" + type: array + price: + allOf: + - $ref: "#/components/schemas/Price" + description: "The price of this item, if it has intrinsic value" + quantity: + allOf: + - $ref: "#/components/schemas/ItemQuantity" + description: The selling quantity of the item + rateable: + description: Whether this item can be rated + type: boolean + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating of the item + recommended: + description: Whether this item is a recommended item to a response + type: boolean + refund_terms: + description: Refund terms of this item + items: + description: Refund term of an item or an order + properties: + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term is applicable. + refund_amount: + $ref: "#/components/schemas/Price" + refund_eligible: + description: Indicates if cancellation will result in a refund + type: boolean + refund_within: + allOf: + - $ref: "#/components/schemas/Time" + description: Time within which refund will be processed after successful cancellation. + type: object + type: array + related: + description: Whether this item is a related item to the exactly matched item + type: boolean + replacement_terms: + description: Terms that are applicable be met when this item is replaced + items: + $ref: "#/components/schemas/ReplacementTerm" + type: array + return_terms: + description: Terms that are applicable when this item is returned + items: + $ref: "#/components/schemas/ReturnTerm" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Temporal attributes of this item. This property is used when the item exists on the catalog only for a limited period of time. + ttl: + description: Time to live in seconds for an instance of this schema + type: string + xinput: + allOf: + - $ref: "#/components/schemas/XInput" + description: Additional input required from the customer to purchase / avail this item + type: object + ItemQuantity: + additionalProperties: false + description: Describes the count or amount of an item + properties: + allocated: + description: This represents the exact quantity allocated for purchase of the item. + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + available: + description: This represents the exact quantity available for purchase of the item. The buyer can only purchase multiples of this + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + maximum: + description: This represents the maximum quantity allowed for purchase of the item + properties: + count: + minimum: 1 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + minimum: + description: This represents the minimum quantity allowed for purchase of the item + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + selected: + description: This represents the quantity selected for purchase of the item + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + unitized: + description: This represents the quantity available in a single unit of the item + properties: + count: + maximum: 1 + minimum: 1 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + type: object + Location: + additionalProperties: false + description: The physical location of something + properties: + 3dspace: + description: The three dimensional region describing this location + type: string + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The address of this location. + area_code: + type: string + circle: + $ref: "#/components/schemas/Circle" + city: + allOf: + - $ref: "#/components/schemas/City" + description: "The city this location is, or is located within" + country: + allOf: + - $ref: "#/components/schemas/Country" + description: "The country this location is, or is located within" + descriptor: + $ref: "#/components/schemas/Descriptor" + district: + description: "The state this location is, or is located within" + type: string + gps: + allOf: + - $ref: "#/components/schemas/Gps" + description: The GPS co-ordinates of this location. + id: + type: string + map_url: + description: The url to the map of the location. This can be a globally recognized map url or the one specified by the network policy. + format: uri + type: string + polygon: + description: The boundary polygon of this location + type: string + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating of this location + state: + allOf: + - $ref: "#/components/schemas/State" + description: "The state this location is, or is located within" + type: object + MediaFile: + additionalProperties: false + description: This object contains a url to a media file. + properties: + dsa: + description: The signing algorithm used by the sender + type: string + mimetype: + description: "indicates the nature and format of the document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838" + type: string + signature: + description: The digital signature of the file signed by the sender + type: string + url: + description: The URL of the file + format: uri + type: string + type: object + Offer: + additionalProperties: false + description: An offer associated with a catalog. This is typically used to promote a particular product and enable more purchases. + properties: + category_ids: + items: + $ref: "#/components/schemas/Category/properties/id" + type: array + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + type: string + item_ids: + items: + $ref: "#/components/schemas/Item/properties/id" + type: array + location_ids: + items: + $ref: "#/components/schemas/Location/properties/id" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + type: object + Option: + additionalProperties: false + description: Describes a selectable option + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + type: string + type: object + Order: + additionalProperties: false + description: Describes a legal purchase order. It contains the complete details of the legal contract created between the buyer and the seller. + properties: + add_ons: + description: The add-ons purchased / availed in this order + items: + $ref: "#/components/schemas/AddOn" + type: array + billing: + allOf: + - $ref: "#/components/schemas/Billing" + description: The billing details of this order + cancellation: + allOf: + - $ref: "#/components/schemas/Cancellation" + description: The cancellation details of this order + cancellation_terms: + description: Cancellation terms of this item + items: + $ref: "#/components/schemas/CancellationTerm" + type: array + created_at: + description: The date-time of creation of this order + format: date-time + type: string + fulfillments: + description: The fulfillments involved in completing this order + items: + $ref: "#/components/schemas/Fulfillment" + type: array + id: + description: Human-readable ID of the order. This is generated at the BPP layer. The BPP can either generate order id within its system or forward the order ID created at the provider level. + type: string + items: + description: The items purchased / availed in this order + items: + $ref: "#/components/schemas/Item" + type: array + offers: + description: The offers applied in this order + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + description: The terms of settlement for this order + items: + $ref: "#/components/schemas/Payment" + type: array + provider: + allOf: + - $ref: "#/components/schemas/Provider" + description: Details of the provider whose catalog items have been selected. + quote: + allOf: + - $ref: "#/components/schemas/Quotation" + description: The mutually agreed upon quotation for this order. + ref_order_ids: + description: A list of order IDs to link this order to previous orders. + items: + description: ID of a previous order + type: string + type: array + refund_terms: + description: Refund terms of this item + items: + $ref: "#/components/schemas/Item/properties/refund_terms/items" + type: array + replacement_terms: + description: Replacement terms of this item + items: + $ref: "#/components/schemas/ReplacementTerm" + type: array + return_terms: + description: Return terms of this item + items: + $ref: "#/components/schemas/ReturnTerm" + type: array + status: + description: Status of the order. Allowed values can be defined by the network policy + type: string + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: + default: DEFAULT + description: "This is used to indicate the type of order being created to BPPs. Sometimes orders can be linked to previous orders, like a replacement order in a retail domain. A follow-up consultation in healthcare domain. A single order part of a subscription order. The list of order types can be standardized at the network level." + enum: + - DRAFT + - DEFAULT + type: string + updated_at: + description: The date-time of updated of this order + format: date-time + type: string + xinput: + allOf: + - $ref: "#/components/schemas/XInput" + description: Additional input required from the customer to confirm this order + type: object + Organization: + additionalProperties: false + description: An organization. Usually a recognized business entity. + properties: + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The postal address of the organization + city: + allOf: + - $ref: "#/components/schemas/City" + description: The city where the the organization's address is registered + contact: + $ref: "#/components/schemas/Contact" + descriptor: + $ref: "#/components/schemas/Descriptor" + state: + allOf: + - $ref: "#/components/schemas/State" + description: The state where the organization's address is registered + type: object + Payment: + additionalProperties: false + description: "Describes the terms of settlement between the BAP and the BPP for a single transaction. When instantiated, this object contains
  1. the amount that has to be settled,
  2. The payment destination destination details
  3. When the settlement should happen, and
  4. A transaction reference ID
. During a transaction, the BPP reserves the right to decide the terms of payment. However, the BAP can send its terms to the BPP first. If the BPP does not agree to those terms, it must overwrite the terms and return them to the BAP. If overridden, the BAP must either agree to the terms sent by the BPP in order to preserve the provider's autonomy, or abort the transaction. In case of such disagreements, the BAP and the BPP can perform offline negotiations on the payment terms. Once an agreement is reached, the BAP and BPP can resume transactions." + properties: + collected_by: + description: "This field indicates who is the collector of payment. The BAP can set this value to 'bap' if it wants to collect the payment first and settle it to the BPP. If the BPP agrees to those terms, the BPP should not send the payment url. Alternatively, the BPP can set this field with the value 'bpp' if it wants the payment to be made directly." + type: string + id: + description: ID of the payment term that can be referred at an item or an order level in a catalog + type: string + params: + properties: + amount: + type: string + bank_account_number: + type: string + bank_code: + type: string + currency: + type: string + source_bank_account_number: + type: string + source_bank_code: + type: string + source_virtual_payment_address: + type: string + transaction_id: + description: The reference transaction ID associated with a payment activity + type: string + virtual_payment_address: + type: string + type: object + status: + type: string + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + type: + type: string + url: + description: "A payment url to be called by the BAP. If empty, then the payment is to be done offline. The details of payment should be present in the params object. If tl_method = http/get, then the payment details will be sent as url params. Two url param values, ```$transaction_id``` and ```$amount``` are mandatory." + format: uri + type: string + type: object + Person: + additionalProperties: false + description: Describes a person as any individual + properties: + age: + allOf: + - $ref: "#/components/schemas/Duration" + description: Age of the person + creds: + items: + $ref: "#/components/schemas/Credential" + type: array + dob: + description: Date of birth of the person + format: date + type: string + gender: + description: "Gender of something, typically a Person, but possibly also fictional characters, animals, etc. While Male and Female may be used, text strings are also acceptable for people who do not identify as a binary gender.Allowed values for this field can be published in the network policy" + type: string + id: + description: Describes the identity of the person + type: string + image: + $ref: "#/components/schemas/Image" + languages: + items: + description: Describes a language known to the person. + properties: + code: + type: string + name: + type: string + type: object + type: array + name: + description: the name of the person + type: string + skills: + items: + description: Describes a skill of the person. + properties: + code: + type: string + name: + type: string + type: object + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + url: + description: Profile url of the person + format: uri + type: string + type: object + Price: + additionalProperties: false + description: Describes the price of an item. Allows for domain extension. + properties: + computed_value: + $ref: "#/components/schemas/DecimalValue" + currency: + type: string + estimated_value: + $ref: "#/components/schemas/DecimalValue" + listed_value: + $ref: "#/components/schemas/DecimalValue" + maximum_value: + $ref: "#/components/schemas/DecimalValue" + minimum_value: + $ref: "#/components/schemas/DecimalValue" + offered_value: + $ref: "#/components/schemas/DecimalValue" + value: + $ref: "#/components/schemas/DecimalValue" + type: object + Provider: + additionalProperties: false + description: Describes the catalog of a business. + properties: + categories: + items: + $ref: "#/components/schemas/Category" + type: array + category_id: + description: Category Id of the provider at the BPP-level catalog + type: string + descriptor: + $ref: "#/components/schemas/Descriptor" + exp: + description: Time after which catalog has to be refreshed + format: date-time + type: string + fulfillments: + items: + $ref: "#/components/schemas/Fulfillment" + type: array + id: + description: Id of the provider + type: string + items: + items: + $ref: "#/components/schemas/Item" + type: array + locations: + items: + $ref: "#/components/schemas/Location" + type: array + offers: + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + items: + $ref: "#/components/schemas/Payment" + type: array + rateable: + description: Whether this provider can be rated or not + type: boolean + rating: + $ref: "#/components/schemas/Rating/properties/value" + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + ttl: + description: "The time-to-live in seconds, for this object. This can be overriden at deeper levels. A value of -1 indicates that this object is not cacheable." + minimum: -1 + type: integer + type: object + Quotation: + additionalProperties: false + description: "Describes a quote. It is the estimated price of products or services from the BPP.
This has properties like price, breakup, ttl" + properties: + breakup: + description: the breakup of the total quoted price + items: + properties: + item: + $ref: "#/components/schemas/Item" + price: + $ref: "#/components/schemas/Price" + title: + type: string + type: object + type: array + id: + description: ID of the quote. + format: uuid + type: string + price: + allOf: + - $ref: "#/components/schemas/Price" + description: The total quoted price + ttl: + $ref: "#/components/schemas/Duration" + type: object + Rating: + additionalProperties: false + description: Describes the rating of an entity + properties: + id: + description: Id of the object being rated + type: string + rating_category: + description: Category of the entity being rated + type: string + value: + description: "Rating value given to the object. This can be a single value or can also contain an inequality operator like gt, gte, lt, lte. This can also contain an inequality expression containing logical operators like && and ||." + type: string + type: object + Region: + additionalProperties: false + description: Describes an arbitrary region of space. The network policy should contain a published list of supported regions by the network. + properties: + boundary: + description: "A string representing the boundary of the region. One-dimensional regions are represented by polylines. Two-dimensional regions are represented by polygons, and three-dimensional regions can represented by polyhedra." + type: string + code: + description: A standard code representing the region. This should be interpreted in the same way by all network participants. + type: string + dimensions: + description: "The number of dimensions that are used to describe any point inside that region. The most common dimensionality of a region is 2, that represents an area on a map. There are regions on the map that can be approximated to one-dimensional regions like roads, railway lines, or shipping lines. 3 dimensional regions are rarer, but are gaining popularity as flying drones are being adopted for various fulfillment services." + enum: + - "1" + - "2" + - "3" + type: string + map_url: + description: The url to the map of the region. This can be a globally recognized map or the one specified by the network policy. + type: string + name: + description: Name of the region as specified on the map where that region exists. + type: string + type: + description: "The type of region. This is used to specify the granularity of the region represented by this object. Various examples of two-dimensional region types are city, country, state, district, and so on. The network policy should contain a list of all possible region types supported by the network." + type: string + type: object + ReplacementTerm: + additionalProperties: false + description: The replacement policy of an item or an order + properties: + external_ref: + $ref: "#/components/schemas/MediaFile" + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term is applicable. + replace_within: + allOf: + - $ref: "#/components/schemas/Time" + description: "Applicable only for buyer managed returns where the buyer has to replace the item before a certain date-time, failing which they will not be eligible for replacement" + type: object + ReturnTerm: + additionalProperties: false + description: Describes the return policy of an item or an order + properties: + fulfillment_managed_by: + description: The entity that will perform the return + type: string + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term IETF''s applicable. + return_eligible: + description: Indicates whether the item is eligible for return + type: boolean + return_location: + allOf: + - $ref: "#/components/schemas/Location" + description: The location where the item or order must / will be returned to + return_time: + allOf: + - $ref: "#/components/schemas/Time" + description: "Applicable only for buyer managed returns where the buyer has to return the item to the origin before a certain date-time, failing which they will not be eligible for refund." + type: object + Scalar: + additionalProperties: false + description: Describes a scalar + properties: + computed_value: + $ref: "#/components/schemas/DecimalValue" + estimated_value: + $ref: "#/components/schemas/DecimalValue" + range: + properties: + max: + $ref: "#/components/schemas/DecimalValue" + min: + $ref: "#/components/schemas/DecimalValue" + type: object + type: + enum: + - CONSTANT + - VARIABLE + type: string + unit: + type: string + value: + $ref: "#/components/schemas/DecimalValue" + type: object + Schedule: + additionalProperties: false + description: Describes a schedule + properties: + frequency: + $ref: "#/components/schemas/Duration" + holidays: + items: + format: date-time + type: string + type: array + times: + items: + format: date-time + type: string + type: array + type: object + State: + additionalProperties: false + description: A bounded geopolitical region of governance inside a country. + properties: + code: + description: State code as per country or international standards + type: string + name: + description: Name of the state + type: string + type: object + Stop: + additionalProperties: false + description: A logical point in space and time during the fulfillment of an order. + properties: + authorization: + $ref: "#/components/schemas/Authorization" + contact: + allOf: + - $ref: "#/components/schemas/Contact" + description: Contact details of the stop + id: + type: string + instructions: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Instructions that need to be followed at the stop + location: + allOf: + - $ref: "#/components/schemas/Location" + description: Location of the stop + parent_stop_id: + type: string + person: + allOf: + - $ref: "#/components/schemas/Person" + description: The details of the person present at the stop + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Timings applicable at the stop. + type: + description: The type of stop. Allowed values of this property can be defined by the network policy. + enum: + - START + - END + type: string + type: object + Support: + additionalProperties: false + description: Details of customer support + properties: + callback_phone: + pattern: '^\+?[1-9]\d{1,14}$' + type: string + email: + format: email + type: string + phone: + pattern: '^\+?[1-9]\d{1,14}$' + type: string + ref_id: + type: string + url: + format: uri + type: string + type: object + Tag: + additionalProperties: false + description: "Describes a tag. This is used to contain extended metadata. This object can be added as a property to any schema to describe extended attributes. For BAPs, tags can be sent during search to optimize and filter search results. BPPs can use tags to index their catalog to allow better search functionality. Tags are sent by the BPP as part of the catalog response in the `on_search` callback. Tags are also meant for display purposes. Upon receiving a tag, BAPs are meant to render them as name-value pairs. This is particularly useful when rendering tabular information about a product or service." + properties: + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "Description of the Tag, can be used to store detailed information." + display: + description: "This value indicates if the tag is intended for display purposes. If set to `true`, then this tag must be displayed. If it is set to `false`, it should not be displayed. This value can override the group display value." + type: boolean + value: + description: The value of the tag. This set by the BPP and rendered as-is by the BAP. + type: string + type: object + TagGroup: + additionalProperties: false + description: "A collection of tag objects with group level attributes. For detailed documentation on the Tags and Tag Groups schema go to https://github.com/beckn/protocol-specifications/discussions/316" + properties: + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "Description of the TagGroup, can be used to store detailed information." + display: + default: true + description: "Indicates the display properties of the tag group. If display is set to false, then the group will not be displayed. If it is set to true, it should be displayed. However, group-level display properties can be overriden by individual tag-level display property. As this schema is purely for catalog display purposes, it is not recommended to send this value during search." + type: boolean + list: + description: "An array of Tag objects listed under this group. This property can be set by BAPs during search to narrow the `search` and achieve more relevant results. When received during `on_search`, BAPs must render this list under the heading described by the `name` property of this schema." + items: + $ref: "#/components/schemas/Tag" + type: array + type: object + Time: + additionalProperties: false + description: Describes time in its various forms. It can be a single point in time; duration; or a structured timetable of operations + properties: + days: + description: comma separated values representing days of the week + type: string + duration: + $ref: "#/components/schemas/Duration" + label: + type: string + range: + properties: + end: + format: date-time + type: string + start: + format: date-time + type: string + type: object + schedule: + $ref: "#/components/schemas/Schedule" + timestamp: + format: date-time + type: string + type: object + Tracking: + additionalProperties: false + description: Contains tracking information that can be used by the BAP to track the fulfillment of an order in real-time. which is useful for knowing the location of time sensitive deliveries. + properties: + id: + description: A unique tracking reference number + type: string + location: + allOf: + - $ref: "#/components/schemas/Location" + description: "In case there is no real-time tracking endpoint available, this field will contain the latest location of the entity being tracked. The BPP will update this value everytime the BAP calls the track API." + status: + description: "This value indicates if the tracking is currently active or not. If this value is `active`, then the BAP can begin tracking the order. If this value is `inactive`, the tracking URL is considered to be expired and the BAP should stop tracking the order." + enum: + - ACTIVE + - INACTIVE + type: string + url: + description: "A URL to the tracking endpoint. This can be a link to a tracking webpage, a webhook URL created by the BAP where BPP can push the tracking data, or a GET url creaed by the BPP which the BAP can poll to get the tracking data. It can also be a websocket URL where the BPP can push real-time tracking data." + format: uri + type: string + type: object + Vehicle: + additionalProperties: false + description: "Describes a vehicle is a device that is designed or used to transport people or cargo over land, water, air, or through space.
This has properties like category, capacity, make, model, size,variant,color,energy_type,registration" + properties: + capacity: + type: integer + cargo_volumne: + type: string + category: + type: string + code: + type: string + color: + type: string + emission_standard: + type: string + energy_type: + type: string + make: + type: string + model: + type: string + registration: + type: string + size: + type: string + variant: + type: string + wheelchair_access: + type: string + wheels_count: + type: string + type: object + XInput: + additionalProperties: false + description: "Contains any additional or extended inputs required to confirm an order. This is typically a Form Input. Sometimes, selection of catalog elements is not enough for the BPP to confirm an order. For example, to confirm a flight ticket, the airline requires details of the passengers along with information on baggage, identity, in addition to the class of ticket. Similarly, a logistics company may require details on the nature of shipment in order to confirm the shipping. A recruiting firm may require additional details on the applicant in order to confirm a job application. For all such purposes, the BPP can choose to send this object attached to any object in the catalog that is required to be sent while placing the order. This object can typically be sent at an item level or at the order level. The item level XInput will override the Order level XInput as it indicates a special requirement of information for that particular item. Hence the BAP must render a separate form for the Item and another form at the Order level before confirmation." + properties: + form: + $ref: "#/components/schemas/Form" + required: + description: Indicates whether the form data is mandatorily required by the BPP to confirm the order. + type: boolean + type: object diff --git a/schemas/context_2.0.1.json b/schemas/context_2.0.1.json new file mode 100644 index 0000000..36fc193 --- /dev/null +++ b/schemas/context_2.0.1.json @@ -0,0 +1,9 @@ +{ + "domain": "context.domain", + "version": "context.version", + "bap_id": "context.bap_id ? context.bap_id : getConfig().app.subscriberId", + "bap_uri": "context.bap_uri ? context.bap_uri : getConfig().app.subscriberUri", + "location": "context.location", + "bpp_id": "context.bpp_id", + "bpp_uri": "context.bpp_uri" +} diff --git a/schemas/core_2.0.1.yaml b/schemas/core_2.0.1.yaml new file mode 100644 index 0000000..8fa19ac --- /dev/null +++ b/schemas/core_2.0.1.yaml @@ -0,0 +1,5109 @@ +openapi: 3.1.0 +info: + description: Adaptation of beckn protocol for the mobility sector. Compatible with core version V1.1. + title: Beckn Mobility API Specification + version: 0.8.3 +security: + - SubscriberAuth: [] +servers: + - url: "https://ps-bap-client.becknprotocol.io" + description: BOC Network +paths: + /search: + post: + description: Search for services by intent + operationId: search + tags: + - Beckn Provider Platform (BPP) + - Beckn Gateway (BG) + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + intent: + $ref: "#/components/schemas/Intent" + type: object + required: + - context + - message + - allOf: + - properties: + context: + properties: + location: + properties: + city: + properties: + code: + type: string + required: + - code + country: + properties: + code: + type: string + enum: + - IND + required: + - code + bap_id: + type: string + pattern: "^(?!https?://).*$" + bpp_id: + type: string + pattern: "^(?!https?://).*$" + ttl: + type: string + # format: date-time + timestamp: + type: string + format: date-time + required: + - location + - domain + - action + - message_id + - transaction_id + - timestamp + - bap_id + - bap_uri + - ttl + - properties: + context: + properties: + action: + type: string + enum: + - search + - properties: + message: + properties: + intent: + properties: + tags: + items: + properties: + list: + items: + properties: + value: + type: string + enum: + - START + - STOP + payment: + properties: + collected_by: + type: string + enum: + - BPP + - BAP + required: + - collected_by + required: + - payment + - tags + required: + - intent + - properties: + message: + properties: + intent: + properties: + payment: + 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 + required: + - code + value: + type: string + format: uri + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TYPE + required: + - code + value: + type: string + enum: + - upi + - neft + - rtgs + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_WINDOW + required: + - code + value: + type: string + pattern: '^PT\d+[MH]$' + required: + - descriptor + - value + - properties: + message: + properties: + intent: + properties: + fulfillment: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + required: + - fulfillment + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + /select: + post: + description: Select items from the catalog and build your order + operationId: select + tags: + - Beckn Provider Platform (BPP) + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - select + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + /init: + post: + description: Initialize an order by providing billing and/or shipping details + operationId: init + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + required: + - context + - message + - allOf: + - allOf: + - $ref: "#/paths/~1search/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + required: + - bpp_id + - bpp_uri + - properties: + context: + properties: + action: + type: string + enum: + - init + - properties: + message: + properties: + order: + type: object + properties: + provider: + type: object + properties: + id: + type: string + required: + - id + items: + type: array + items: + type: object + properties: + id: + type: string + required: + - id + required: + - provider + - items + - allOf: + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - $ref: "#/paths/~1on_select/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - properties: + message: + properties: + order: + required: + - fulfillments + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + type: object + properties: + type: + type: string + enum: + - PRE-ORDER + - ON-FULFILLMENT + - POST-FULFILLMENT + status: + type: string + enum: + - PAID + - NOT-PAID + collected_by: + type: string + enum: + - BAP + - BPP + params: + type: object + properties: + amount: + type: string + pattern: '^\d+(\.\d{1,2})?$' + currency: + type: string + required: + - type + - status + - collected_by + - params + required: + - payments + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + params: + required: + - bank_code + - bank_account_number + - virtual_payment_address + required: + - type + - status + - collected_by + - params + required: + - payments + - properties: + message: + properties: + order: + properties: + billing: + required: + - name + required: + - billing + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /confirm: + post: + description: Initialize an order by providing billing and/or shipping details + operationId: confirm + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - confirm + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - allOf: + - $ref: "#/paths/~1on_select/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - properties: + customer: + properties: + contact: + properties: + phone: + type: string + pattern: '^\+?[1-9]\d{1,14}$' + required: + - phone + person: + properties: + name: + type: string + required: + - name + required: + - contact + - person + required: + - customer + - allOf: + - properties: + message: + properties: + order: + 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 + - 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 + - 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 + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - allOf: + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - BUYER_FINDER_FEES_PERCENTAGE + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + allOf: + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: BUYER_FINDER_FEES_PERCENTAGE + required: + - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + allOf: + - if: + properties: + ? descriptor + : ? properties + : code: + ? enum + : - BUYER_FINDER_FEES_PERCENTAGE + then: + properties: + value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - descriptor + - value + - allOf: + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - SETTLEMENT_WINDOW + - SETTLEMENT_BASIS + - SETTLEMENT_TYPE + - MANDATORY_ARBITRATION + - COURT_JURISDICTION + - DELAY_INTEREST + - STATIC_TERMS + - SETTLEMENT_AMOUNT + - properties: + message: + properties: + order: + properties: + payments: + items: + 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 + required: + - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: SETTLEMENT_TYPE + required: + - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + descriptor: + type: object + ? properties + : code: + const: SETTLEMENT_WINDOW + required: + - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + allOf: + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_WINDOW + then: + properties: + value: + type: string + pattern: '^P(?!$)(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$' + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_BASIS + then: + properties: + value: + type: string + enum: + - INVOICE_RECEIPT + - DELIVERY + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: MANDATORY_ARBITRATION + then: + properties: + value: + type: string + pattern: ^(true|false)$ + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: STATIC_TERMS + then: + properties: + value: + type: string + format: uri + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: COURT_JURISDICTION + then: + properties: + value: + type: string + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: DELAY_INTEREST + then: + properties: + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_TYPE + then: + properties: + value: + type: string + enum: + - UPI + - NEFT + - RTGS + required: + - descriptor + - value + - if: + properties: + ? descriptor + : ? properties + : code: + const: SETTLEMENT_AMOUNT + then: + properties: + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - properties: + message: + properties: + order: + properties: + payments: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: BUYER_FINDER_FEES + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TERMS + required: + - code + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + properties: + type: + type: string + params: + type: object + properties: + transaction_id: + type: string + required: + - type + allOf: + - if: + properties: + type: + const: PRE-ORDER + then: + properties: + params: + required: + - transaction_id + required: + - payments + - properties: + message: + properties: + order: + not: + required: + - id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /status: + post: + description: Fetch the latest order object + operationId: status + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + message: + properties: + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - status + - properties: + message: + properties: + order_id: + type: string + required: + - order_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /update: + post: + description: Remove object + operationId: update + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - update + required: + - bpp_id + - bpp_uri + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + description: Updated order object + required: + - id + update_target: + description: 'Comma separated values of order objects being updated. For example: ```"update_target":"item,billing,fulfillment"```' + type: string + required: + - update_target + - order + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - update + - properties: + message: + type: object + properties: + order: + type: object + properties: + id: + type: string + required: + - id + update_target: + type: string + pattern: "^[^,]+(,[^,]+)*$" + required: + - order + - update_target + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /rating: + post: + description: Provide feedback on a service + operationId: rating + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - rating + message: + properties: + ratings: + type: array + items: + $ref: "#/components/schemas/Rating" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - rating + - properties: + message: + properties: + ratings: + type: array + minItems: 1 + items: + type: object + properties: + id: + type: string + value: + type: number + rating_category: + type: string + enum: + - RIDER + - DRIVER + - SERVICE + required: + - id + - value + - rating_category + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /support: + post: + description: Contact support + operationId: support + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - support + message: + properties: + support: + $ref: "#/components/schemas/Support" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - support + - properties: + message: + properties: + support: + properties: + ref_id: + type: string + required: + - ref_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /track: + post: + description: Track an active order + operationId: track + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - track + message: + additionalProperties: false + properties: + callback_url: + format: uri + type: string + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - track + - properties: + message: + properties: + order_id: + type: string + required: + - order_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /cancel: + post: + description: Cancel an order + operationId: cancel + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - cancel + message: + properties: + cancellation_reason_id: + $ref: "#/components/schemas/Option/properties/id" + descriptor: + $ref: "#/components/schemas/Descriptor" + order_id: + $ref: "#/components/schemas/Order/properties/id" + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - cancel + - properties: + message: + properties: + order_id: + type: string + descriptor: + properties: + code: + type: string + enum: + - SOFT_CANCEL + - CONFIRM_CANCEL + required: + - code + cancellation_reason_id: + type: string + pattern: "^[0-9]+$" + required: + - order_id + - descriptor + - cancellation_reason_id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn Provider Platform (BPP) + /on_search: + post: + description: Send catalog + operationId: on_search + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + catalog: + $ref: "#/components/schemas/Catalog" + required: + - catalog + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_search + - properties: + message: + properties: + catalog: + type: object + properties: + descriptor: + type: object + properties: + name: + type: string + images: + type: array + items: + minItems: 1 + required: + - name + required: + - descriptor + - properties: + message: + properties: + catalog: + type: object + properties: + providers: + type: array + minItems: 1 + items: + type: object + properties: + id: + type: string + required: + - id + required: + - providers + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + fulfillments: + type: array + minItems: 1 + items: + properties: + vehicle: + properties: + category: + type: string + enum: + - AUTO_RICKSHAW + - CAB + required: + - category + type: + type: string + enum: + - DELIVERY + required: + - id + - vehicle + - type + required: + - fulfillments + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + items: + type: array + minItems: 1 + items: + type: object + properties: + descriptor: + type: object + properties: + name: + type: string + code: + type: string + enum: + - RIDE + required: + - code + price: + type: object + properties: + value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - value + - currency + fulfillment_ids: + type: array + minItems: 1 + payment_ids: + type: array + minItems: 1 + required: + - id + - descriptor + - price + - fulfillment_ids + - payment_ids + required: + - items + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + type: array + minItems: 1 + items: + type: object + properties: + type: + type: string + collected_by: + type: string + required: + - collected_by + required: + - payments + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + fulfillments: + items: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + - allOf: + - allOf: + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - BUYER_FINDER_FEES_PERCENTAGE + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + allOf: + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: BUYER_FINDER_FEES_PERCENTAGE + ? required + : - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: BUYER_FINDER_FEES + then: + properties: + list: + type: array + items: + allOf: + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : ? enum + : - BUYER_FINDER_FEES_PERCENTAGE + then: + ? properties + : value: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - descriptor + - value + - allOf: + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + type: object + properties: + descriptor: + properties: + code: + type: string + enum: + - SETTLEMENT_WINDOW + - SETTLEMENT_BASIS + - SETTLEMENT_TYPE + - MANDATORY_ARBITRATION + - COURT_JURISDICTION + - DELAY_INTEREST + - STATIC_TERMS + - SETTLEMENT_AMOUNT + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + 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 + ? required + : - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: SETTLEMENT_TYPE + ? required + : - code + value: + type: string + required: + - descriptor + - value + - contains: + type: object + properties: + ? descriptor + : type: object + ? properties + : code: + const: SETTLEMENT_WINDOW + ? required + : - code + value: + type: string + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + items: + if: + properties: + descriptor: + properties: + code: + const: SETTLEMENT_TERMS + then: + properties: + list: + type: array + items: + allOf: + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_WINDOW + then: + ? properties + : value: + type: string + pattern: '^P(?!$)(?:\d+Y)?(?:\d+M)?(?:\d+W)?(?:\d+D)?(?:T(?=\d)(?:\d+H)?(?:\d+M)?(?:\d+S)?)?$' + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_BASIS + then: + ? properties + : value: + type: string + enum: + - INVOICE_RECEIPT + - DELIVERY + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: MANDATORY_ARBITRATION + then: + ? properties + : value: + type: string + pattern: ^(true|false)$ + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: STATIC_TERMS + then: + ? properties + : value: + type: string + format: uri + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: COURT_JURISDICTION + then: + ? properties + : value: + type: string + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: DELAY_INTEREST + then: + ? properties + : value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_TYPE + then: + ? properties + : value: + type: string + enum: + - UPI + - NEFT + - RTGS + required: + - descriptor + - value + - if: + ? properties + : ? descriptor + : ? properties + : ? code + : const: SETTLEMENT_AMOUNT + then: + ? properties + : value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - descriptor + - value + - properties: + message: + properties: + catalog: + properties: + providers: + items: + properties: + payments: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: BUYER_FINDER_FEES + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: SETTLEMENT_TERMS + required: + - code + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - context + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + - Beckn Gateway (BG) + /on_select: + post: + description: Send draft order object with quoted price for selected items + operationId: on_select + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_select + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - allOf: + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + required: + - id + required: + - fulfillments + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + state: + type: object + properties: + descriptor: + type: object + properties: + code: + type: string + enum: + - RIDE_ASSIGNED + - RIDE_ENROUTE_PICKUP + - RIDE_ARRIVED_PICKUP + - RIDE_STARTED + - RIDE_ENDED + - RIDE_CANCELLED + required: + - code + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + properties: + stops: + items: + properties: + authorization: + type: object + properties: + type: + type: string + enum: + - OTP + - QR + token: + type: string + pattern: ^-?\d+(\.\d+)?$ + required: + - type + - token + - properties: + message: + properties: + order: + properties: + fulfillments: + items: + properties: + stops: + allOf: + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: START + required: + - location + - type + - contains: + type: object + properties: + location: + type: object + properties: + gps: + type: string + required: + - gps + type: + const: END + required: + - location + - type + required: + - stops + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + vehicle: + properties: + category: + type: string + enum: + - AUTO_RICKSHAW + - CAB + required: + - category + required: + - vehicle + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - not: + required: + - agent + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_init: + post: + description: Send order object with payment details updated + operationId: on_init + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_init + - properties: + message: + properties: + order: + properties: + provider: + type: object + properties: + id: + type: string + required: + - id + required: + - provider + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - properties: + message: + properties: + order: + properties: + items: + items: + properties: + tags: + allOf: + - contains: + properties: + descriptor: + type: object + properties: + code: + const: FARE_POLICY + required: + - code + - contains: + properties: + descriptor: + type: object + properties: + code: + const: INFO + required: + - code + - properties: + message: + properties: + order: + properties: + items: + type: array + minItems: 1 + items: + type: object + properties: + fulfillment_ids: + minItems: 1 + location_ids: + minItems: 1 + required: + - fulfillment_ids + - location_ids + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + minItems: 1 + items: + type: object + properties: + type: + type: string + enum: + - DELIVERY + required: + - type + - allOf: + - properties: + message: + properties: + order: + properties: + quote: + type: object + properties: + price: + type: object + properties: + currency: + type: string + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - currency + - value + breakup: + type: array + items: + type: object + properties: + price: + type: object + properties: + currency: + type: string + value: + type: string + pattern: '^\d+(\.\d{1,2})?$' + required: + - currency + - value + title: + type: string + enum: + - BASE_FARE + - DISTANCE_FARE + - TAX + - DISCOUNT + - WAITING_CHARG + - CANCELLATION_CHARGES + required: + - price + - title + required: + - price + - breakup + required: + - quote + - properties: + message: + properties: + order: + properties: + quote: + properties: + breakup: + allOf: + - contains: + type: object + properties: + title: + const: BASE_FARE + price: + type: object + properties: + value: + type: string + required: + - value + required: + - title + - price + - contains: + type: object + properties: + title: + const: DISTANCE_FARE + price: + type: object + properties: + value: + type: string + required: + - value + required: + - title + - price + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + cancellation_terms: + items: + properties: + fulfillment_state: + properties: + descriptor: + properties: + code: + type: string + enum: + - RIDE_ASSIGNED + - RIDE_ENROUTE_PICKUP + - RIDE_ARRIVED_PICKUP + - RIDE_STARTED + required: + - code + cancellation_fee: + oneOf: + - properties: + percentage: + type: string + pattern: '^(100(\.0{1,2})?|(\d{1,2})(\.\d{1,2})?)$' + required: + - percentage + - properties: + amount: + properties: + value: + type: string + pattern: '^[+-]?(\d+(\.\d*)?|\.\d+)$' + required: + - currency + - value + required: + - amount + required: + - fulfillment_state + - cancellation_fee + required: + - cancellation_terms + - properties: + message: + type: object + required: + - message + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_confirm: + post: + description: Send active order object + operationId: on_confirm + requestBody: + content: + application/json: + schema: + allOf: + - type: object + properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + - message + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_confirm + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - COMPLETE + - ACTIVE + required: + - status + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - COMPLETE + - ACTIVE + - CANCELLED + - SOFT_CANCEL + required: + - status + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_status: + post: + description: Fetch the status of a Service + operationId: on_status + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_status + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - allOf: + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/3" + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + allOf: + - properties: + agent: + properties: + contact: + properties: + phone: + type: string + pattern: '^\+?[1-9]\d{1,14}$' + required: + - phone + person: + properties: + name: + type: string + required: + - name + required: + - contact + - person + required: + - agent + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - properties: + message: + properties: + order: + properties: + payments: + type: array + items: + properties: + type: + type: string + params: + type: object + properties: + transaction_id: + type: string + required: + - type + allOf: + - if: + properties: + type: + const: PRE-ORDER + then: + properties: + params: + required: + - transaction_id + - properties: + message: + properties: + order: + properties: + fulfillments: + type: array + items: + properties: + vehicle: + type: object + properties: + registration: + type: string + required: + - registration + - make + - model + required: + - vehicle + - properties: + message: + properties: + order: + properties: + fulfillments: + items: + required: + - state + - properties: + message: + properties: + order: + required: + - id + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_update: + post: + description: Returns updated service with updated runtime object + operationId: on_update + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_update + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_update + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_rating: + post: + description: Provide feedback on a service + operationId: on_rating + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_rating + error: + $ref: "#/components/schemas/Error" + message: + properties: + feedback_form: + allOf: + - $ref: "#/components/schemas/XInput" + description: A feedback form to allow the user to provide additional information on the rating provided + type: object + required: + - context + - message + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_rating + - properties: + message: + properties: + feedback_form: + type: object + properties: + required: + type: boolean + form: + type: object + required: + - required + allOf: + - if: + properties: + required: + const: true + then: + required: + - form + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_support: + post: + description: Contact Support + operationId: on_support + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_support + error: + $ref: "#/components/schemas/Error" + message: + properties: + support: + $ref: "#/components/schemas/Support" + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_support + - properties: + message: + properties: + support: + type: object + properties: + email: + type: string + format: email + phone: + type: string + url: + type: string + format: uri + anyOf: + - required: + - email + - required: + - phone + - required: + - url + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_track: + post: + description: Send tracking details of an active order + operationId: on_track + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_track + error: + $ref: "#/components/schemas/Error" + message: + properties: + tracking: + $ref: "#/components/schemas/Tracking" + required: + - tracking + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_track + - properties: + message: + properties: + tracking: + type: object + properties: + status: + type: string + url: + type: string + location: + type: object + properties: + latitude: + type: number + longitude: + type: number + required: + - status + oneOf: + - required: + - url + - required: + - location + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) + /on_cancel: + post: + description: Send cancellation request_id with reasons list in case of cancellation request. Else send cancelled order object + operationId: on_cancel + requestBody: + content: + application/json: + schema: + allOf: + - properties: + context: + allOf: + - $ref: "#/components/schemas/Context" + - properties: + action: + enum: + - on_cancel + error: + $ref: "#/components/schemas/Error" + message: + properties: + order: + allOf: + - $ref: "#/components/schemas/Order" + required: + - order + type: object + required: + - context + type: object + - allOf: + - $ref: "#/paths/~1init/post/requestBody/content/application~1json/schema/allOf/1/allOf/0" + - properties: + context: + properties: + action: + type: string + enum: + - on_cancel + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/2" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/4" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/6" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/7" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/8" + - $ref: "#/paths/~1confirm/post/requestBody/content/application~1json/schema/allOf/1/allOf/5" + - $ref: "#/paths/~1on_init/post/requestBody/content/application~1json/schema/allOf/1/allOf/10" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/11" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/12" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/13" + - $ref: "#/paths/~1on_status/post/requestBody/content/application~1json/schema/allOf/1/allOf/14" + - properties: + message: + properties: + order: + properties: + status: + type: string + enum: + - CANCELLED + - SOFT_CANCEL + required: + - status + - properties: + message: + properties: + order: + properties: + cancellation_terms: + items: + required: + - reason_required + required: + - cancellation_terms + description: TODO + responses: + "200": + content: + application/json: + schema: + properties: + error: + $ref: "#/components/schemas/Error" + message: + properties: + ack: + $ref: "#/components/schemas/Ack" + required: + - ack + type: object + required: + - message + type: object + description: Acknowledgement of message received + tags: + - Beckn App Platform (BAP) +components: + securitySchemes: + SubscriberAuth: + description: 'Signature of message body using BAP or BPP subscriber''s signing public key.

Format:

Authorization : Signature keyId="{subscriber_id}|{unique_key_id}|{algorithm}",algorithm="ed25519",created="1606970629",expires="1607030629",headers="(created) (expires) digest",signature="Base64(BLAKE-512(signing string))"' + in: header + name: Authorization + type: apiKey + schemas: + Ack: + additionalProperties: false + description: "Describes the acknowledgement sent in response to an API call. If the implementation uses HTTP/S, then Ack must be returned in the same session. Every API call to a BPP must be responded to with an Ack whether the BPP intends to respond with a callback or not. This has one property called `status` that indicates the status of the Acknowledgement." + properties: + status: + description: "The status of the acknowledgement. If the request passes the validation criteria of the BPP, then this is set to ACK. If a BPP responds with status = `ACK` to a request, it is required to respond with a callback. If the request fails the validation criteria, then this is set to NACK. Additionally, if a BPP does not intend to respond with a callback even after the request meets the validation criteria, it should set this value to `NACK`." + enum: + - ACK + - NACK + type: string + tags: + description: A list of tags containing any additional information sent along with the Acknowledgement. + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: object + AddOn: + additionalProperties: false + description: Describes an add-on + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + description: "ID of the add-on. This follows the syntax {item.id}/add-on/{add-on unique id} for item specific add-on OR " + type: string + price: + $ref: "#/components/schemas/Price" + type: object + Address: + description: Describes a postal address. + type: string + Agent: + additionalProperties: false + description: "Describes the direct performer, driver or executor that fulfills an order. It is usually a person. But in some rare cases, it could be a non-living entity like a drone, or a bot. Some examples of agents are Doctor in the healthcare sector, a driver in the mobility sector, or a delivery person in the logistics sector. This object can be set at any stage of the order lifecycle. This can be set at the discovery stage when the BPP wants to provide details on the agent fulfilling the order, like in healthcare, where the doctor's name appears during search. This object can also used to search for a particular person that the customer wants fulfilling an order. Sometimes, this object gets instantiated after the order is confirmed, like in the case of on-demand taxis, where the driver is assigned after the user confirms the ride." + properties: + contact: + $ref: "#/components/schemas/Contact" + organization: + $ref: "#/components/schemas/Organization" + person: + $ref: "#/components/schemas/Person" + rating: + $ref: "#/components/schemas/Rating/properties/value" + type: object + Authorization: + additionalProperties: false + description: Describes an authorization mechanism + properties: + status: + description: Status of the token + type: string + token: + description: Token used for authorization + type: string + type: + description: Type of authorization mechanism used + type: string + valid_from: + description: Timestamp in RFC3339 format from which token is valid + format: date-time + type: string + valid_to: + description: Timestamp in RFC3339 format until which token is valid + format: date-time + type: string + type: object + Billing: + additionalProperties: false + description: "Describes the billing details of an entity.
This has properties like name,organization,address,email,phone,time,tax_number, created_at,updated_at" + properties: + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The address of the billable entity + city: + allOf: + - $ref: "#/components/schemas/City" + description: The city where the billable entity resides. + email: + description: Email address where the bill is sent to + format: email + type: string + name: + description: Name of the billable entity + type: string + organization: + allOf: + - $ref: "#/components/schemas/Organization" + description: Details of the organization being billed. + phone: + description: Phone number of the billable entity + type: string + state: + allOf: + - $ref: "#/components/schemas/State" + description: The state where the billable entity resides. This is important for state-level tax calculation + tax_id: + description: ID of the billable entity as recognized by the taxation authority + type: string + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Details regarding the billing period + type: object + Cancellation: + additionalProperties: false + description: Describes a cancellation event + properties: + additional_description: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Any additional information regarding the nature of cancellation + cancelled_by: + type: string + reason: + allOf: + - $ref: "#/components/schemas/Option" + description: The reason for cancellation + time: + description: Date-time when the order was cancelled by the buyer + format: date-time + type: string + type: object + CancellationTerm: + additionalProperties: false + description: Describes the cancellation terms of an item or an order. This can be referenced at an item or order level. Item-level cancellation terms can override the terms at the order level. + properties: + cancel_by: + allOf: + - $ref: "#/components/schemas/Time" + description: Information related to the time of cancellation. + cancellation_fee: + $ref: "#/components/schemas/Fee" + external_ref: + $ref: "#/components/schemas/MediaFile" + fulfillment_state: + allOf: + - $ref: "#/components/schemas/FulfillmentState" + description: The state of fulfillment during which this term is applicable. + reason_required: + description: Indicates whether a reason is required to cancel the order + type: boolean + xinput: + $ref: "#/components/schemas/XInput" + required: + - cancellation_fee + type: object + Catalog: + additionalProperties: false + description: "Describes the products or services offered by a BPP. This is typically sent as the response to a search intent from a BAP. The payment terms, offers and terms of fulfillment supported by the BPP can also be included here. The BPP can show hierarchical nature of products/services in its catalog using the parent_category_id in categories. The BPP can also send a ttl (time to live) in the context which is the duration for which a BAP can cache the catalog and use the cached catalog.
This has properties like bbp/descriptor,bbp/categories,bbp/fulfillments,bbp/payments,bbp/offers,bbp/providers and exp
This is used in the following situations.
" + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + exp: + description: Timestamp after which catalog will expire + format: date-time + type: string + fulfillments: + description: Fulfillment modes offered at the BPP level. This is used when a BPP itself offers fulfillments on behalf of the providers it has onboarded. + items: + $ref: "#/components/schemas/Fulfillment" + type: array + offers: + description: Offers at the BPP-level. This is common across all providers onboarded by the BPP. + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + description: Payment terms offered by the BPP for all transactions. This can be overriden at the provider level. + items: + $ref: "#/components/schemas/Payment" + type: array + providers: + items: + $ref: "#/components/schemas/Provider" + type: array + ttl: + description: Duration in seconds after which this catalog will expire + type: string + type: object + Category: + additionalProperties: false + description: A label under which a collection of items can be grouped. + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + description: ID of the category + type: string + parent_category_id: + $ref: "#/components/schemas/Category/properties/id" + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + ttl: + description: Time to live for an instance of this schema + type: object + Circle: + additionalProperties: false + description: Describes a circular region of a specified radius centered at a specified GPS coordinate. + properties: + gps: + $ref: "#/components/schemas/Gps" + radius: + $ref: "#/components/schemas/Scalar" + type: object + City: + additionalProperties: false + description: Describes a city + properties: + code: + description: City code + type: string + name: + description: Name of the city + type: string + type: object + Contact: + additionalProperties: false + properties: + email: + type: string + jcard: + description: A Jcard object as per draft-ietf-jcardcal-jcard-03 specification + type: object + phone: + type: string + type: object + Context: + additionalProperties: false + description: "Every API call in beckn protocol has a context. It provides a high-level overview to the receiver about the nature of the intended transaction. Typically, it is the BAP that sets the transaction context based on the consumer's location and action on their UI. But sometimes, during unsolicited callbacks, the BPP also sets the transaction context but it is usually the same as the context of a previous full-cycle, request-callback interaction between the BAP and the BPP. The context object contains four types of fields.
  1. Demographic information about the transaction using fields like `domain`, `country`, and `region`.
  2. Addressing details like the sending and receiving platform's ID and API URL.
  3. Interoperability information like the protocol version that implemented by the sender and,
  4. Transaction details like the method being called at the receiver's endpoint, the transaction_id that represents an end-to-end user session at the BAP, a message ID to pair requests with callbacks, a timestamp to capture sending times, a ttl to specifiy the validity of the request, and a key to encrypt information if necessary.
This object must be passed in every interaction between a BAP and a BPP. In HTTP/S implementations, it is not necessary to send the context during the synchronous response. However, in asynchronous protocols, the context must be sent during all interactions," + properties: + action: + description: The Beckn protocol method being called by the sender and executed at the receiver. + type: string + bap_id: + allOf: + - description: "A globally unique identifier of the platform, Typically it is the fully qualified domain name (FQDN) of the platform." + type: string + description: Subscriber ID of the BAP + bap_uri: + allOf: + - description: The callback URL of the Subscriber. This should necessarily contain the same domain name as set in `subscriber_id``. + format: uri + type: string + description: Subscriber URL of the BAP for accepting callbacks from BPPs. + bpp_id: + allOf: + - $ref: "#/components/schemas/Context/properties/bap_id/allOf/0" + description: Subscriber ID of the BPP + bpp_uri: + allOf: + - $ref: "#/components/schemas/Context/properties/bap_uri/allOf/0" + description: Subscriber URL of the BPP for accepting calls from BAPs. + domain: + allOf: + - $ref: "#/components/schemas/Domain/properties/code" + description: Domain code that is relevant to this transaction context + key: + description: The encryption public key of the sender + type: string + location: + allOf: + - $ref: "#/components/schemas/Location" + description: The location where the transaction is intended to be fulfilled. + required: + - country + - city + message_id: + description: "This is a unique value which persists during a request / callback cycle. Since beckn protocol APIs are asynchronous, BAPs need a common value to match an incoming callback from a BPP to an earlier call. This value can also be used to ignore duplicate messages coming from the BPP. It is recommended to generate a fresh message_id for every new interaction. When sending unsolicited callbacks, BPPs must generate a new message_id." + format: uuid + type: string + timestamp: + description: Time of request generation in RFC3339 format + format: date-time + type: string + transaction_id: + description: "This is a unique value which persists across all API calls from `search` through `confirm`. This is done to indicate an active user session across multiple requests. The BPPs can use this value to push personalized recommendations, and dynamic offerings related to an ongoing transaction despite being unaware of the user active on the BAP." + format: uuid + type: string + ttl: + description: The duration in ISO8601 format after timestamp for which this message holds valid + type: string + version: + description: Version of transaction protocol being used by the sender. + type: string + type: object + Country: + additionalProperties: false + description: Describes a country. + properties: + code: + description: Country code as per ISO 3166-1 and ISO 3166-2 format + type: string + name: + description: Name of the country + type: string + type: object + Credential: + additionalProperties: false + description: Describes a credential of an entity - Person or Organization + properties: + id: + type: string + type: + default: VerifiableCredential + type: string + url: + description: URL of the credential + format: uri + type: string + type: object + Customer: + additionalProperties: false + description: Describes a customer buying/availing a product or a service + properties: + contact: + $ref: "#/components/schemas/Contact" + person: + $ref: "#/components/schemas/Person" + type: object + DecimalValue: + description: Describes a decimal value + pattern: "^[+-]?([0-9]*[.])?[0-9]+" + type: string + Descriptor: + additionalProperties: false + description: Physical description of something. + properties: + additional_desc: + properties: + content_type: + enum: + - text/plain + - text/html + - application/json + type: string + url: + type: string + type: object + code: + type: string + images: + items: + $ref: "#/components/schemas/Image" + type: array + long_desc: + type: string + media: + items: + $ref: "#/components/schemas/MediaFile" + type: array + name: + type: string + short_desc: + type: string + type: object + Domain: + additionalProperties: false + description: "Described the industry sector or sub-sector. The network policy should contain codes for all the industry sectors supported by the network. Domains can be created in varying levels of granularity. The granularity of a domain can be decided by the participants of the network. Too broad domains will result in irrelevant search broadcast calls to BPPs that don't have services supporting the domain. Too narrow domains will result in a large number of registry entries for each BPP. It is recommended that network facilitators actively collaborate with various working groups and network participants to carefully choose domain codes keeping in mind relevance, performance, and opportunity cost. It is recommended that networks choose broad domains like mobility, logistics, healthcare etc, and progressively granularize them as and when the number of network participants for each domain grows large." + properties: + additional_info: + allOf: + - $ref: "#/components/schemas/MediaFile" + description: A url that contains addtional information about that domain. + code: + description: "Standard code representing the domain. The standard is usually published as part of the network policy. Furthermore, the network facilitator should also provide a mechanism to provide the supported domains of a network." + type: string + name: + description: Name of the domain + type: string + type: object + Duration: + description: Describes duration as per ISO8601 format + type: string + Error: + additionalProperties: false + description: "Describes an error object that is returned by a BAP, BPP or BG as a response or callback to an action by another network participant. This object is sent when any request received by a network participant is unacceptable. This object can be sent either during Ack or with the callback." + properties: + code: + description: 'Standard error code. For full list of error codes, refer to docs/protocol-drafts/BECKN-005-ERROR-CODES-DRAFT-01.md of this repo"' + type: string + message: + description: Human readable message describing the error. Used mainly for logging. Not recommended to be shown to the user. + type: string + paths: + description: Path to json schema generating the error. Used only during json schema validation errors + type: string + type: object + Fee: + additionalProperties: false + description: A fee applied on a particular entity + properties: + amount: + allOf: + - $ref: "#/components/schemas/Price" + description: A fixed value + percentage: + allOf: + - $ref: "#/components/schemas/DecimalValue" + description: Percentage of a value + type: object + Form: + additionalProperties: false + description: Describes a form + properties: + data: + additionalProperties: + type: string + description: The form submission data + type: object + mime_type: + description: This field indicates the nature and format of the form received by querying the url. MIME types are defined and standardized in IETF's RFC 6838. + enum: + - text/html + - application/xml + type: string + submission_id: + format: uuid + type: string + url: + description: "The URL from where the form can be fetched. The content fetched from the url must be processed as per the mime_type specified in this object. Once fetched, the rendering platform can choosed to render the form as-is as an embeddable element; or process it further to blend with the theme of the application. In case the interface is non-visual, the the render can process the form data and reproduce it as per the standard specified in the form." + format: uri + type: string + type: object + Fulfillment: + additionalProperties: false + description: Describes how a an order will be rendered/fulfilled to the end-customer + properties: + agent: + allOf: + - $ref: "#/components/schemas/Agent" + description: The agent that is currently handling the fulfillment of the order + contact: + $ref: "#/components/schemas/Contact" + customer: + allOf: + - $ref: "#/components/schemas/Customer" + description: The person that will ultimately receive the order + id: + description: Unique reference ID to the fulfillment of an order + type: string + path: + description: The physical path taken by the agent that can be rendered on a map. The allowed format of this property can be set by the network. + type: string + rateable: + description: Whether the fulfillment can be rated or not + type: boolean + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating value of the fulfullment service. + state: + allOf: + - $ref: "#/components/schemas/FulfillmentState" + description: The current state of fulfillment. The BPP must set this value whenever the state of the order fulfillment changes and fire an unsolicited `on_status` call. + stops: + description: The list of logical stops encountered during the fulfillment of an order. + items: + $ref: "#/components/schemas/Stop" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + tracking: + default: false + description: Indicates whether the fulfillment allows tracking + type: boolean + type: + description: "A code that describes the mode of fulfillment. This is typically set when there are multiple ways an order can be fulfilled. For example, a retail order can be fulfilled either via store pickup or a home delivery. Similarly, a medical consultation can be provided either in-person or via tele-consultation. The network policy must publish standard fulfillment type codes for the different modes of fulfillment." + type: string + vehicle: + $ref: "#/components/schemas/Vehicle" + type: object + FulfillmentState: + additionalProperties: false + description: Describes the state of fulfillment + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + updated_at: + format: date-time + type: string + updated_by: + description: ID of entity which changed the state + type: string + type: object + Gps: + description: Describes a gps coordinate + pattern: '^[-+]?([1-8]?\d(\.\d{6,})?|90(\.0{6,})?),\s*[-+]?(180(\.0{6,})?|((1[0-7]\d)|([1-9]?\d))(\.\d{6,})?)$' + type: string + Image: + additionalProperties: false + description: Describes an image + properties: + height: + description: Height of the image in pixels + type: string + size_type: + description: The size of the image. The network policy can define the default dimensions of each type + enum: + - xs + - sm + - md + - lg + - xl + - custom + type: string + url: + description: URL to the image. This can be a data url or an remote url + format: uri + type: string + width: + description: Width of the image in pixels + type: string + required: + - url + type: object + Intent: + additionalProperties: false + description: "The intent to buy or avail a product or a service. The BAP can declare the intent of the consumer containing
This has properties like descriptor,provider,fulfillment,payment,category,offer,item,tags
This is typically used by the BAP to send the purpose of the user's search to the BPP. This will be used by the BPP to find products or services it offers that may match the user's intent.
For example, in Mobility, the mobility consumer declares a mobility intent. In this case, the mobility consumer declares information that describes various aspects of their journey like,
For example, in health domain, a consumer declares the intent for a lab booking the describes various aspects of their booking like," + properties: + category: + allOf: + - $ref: "#/components/schemas/Category" + description: Details on the item category + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "A raw description of the search intent. Free text search strings, raw audio, etc can be sent in this object." + fulfillment: + allOf: + - $ref: "#/components/schemas/Fulfillment" + description: Details on how the customer wants their order fulfilled + item: + allOf: + - $ref: "#/components/schemas/Item" + description: Details of the item that the consumer wants to order + offer: + allOf: + - $ref: "#/components/schemas/Offer" + description: details on the offer the customer wants to avail + payment: + allOf: + - $ref: "#/components/schemas/Payment" + description: Details on how the customer wants to pay for the order + provider: + allOf: + - $ref: "#/components/schemas/Provider" + description: The provider from which the customer wants to place to the order from + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: object + Item: + additionalProperties: false + description: "Describes a product or a service offered to the end consumer by the provider. In the mobility sector, it can represent a fare product like one way journey. In the logistics sector, it can represent the delivery service offering. In the retail domain it can represent a product like a grocery item." + properties: + add_ons: + items: + $ref: "#/components/schemas/AddOn" + type: array + cancellation_terms: + description: Cancellation terms of this item + items: + $ref: "#/components/schemas/CancellationTerm" + type: array + category_ids: + description: Categories this item can be listed under + items: + allOf: + - $ref: "#/components/schemas/Category/properties/id" + type: array + creator: + allOf: + - $ref: "#/components/schemas/Organization" + description: The creator of this item + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Physical description of the item + fulfillment_ids: + description: Modes through which this item can be fulfilled + items: + allOf: + - $ref: "#/components/schemas/Fulfillment/properties/id" + type: array + id: + description: ID of the item. + type: string + location_ids: + description: Provider Locations this item is available in + items: + allOf: + - $ref: "#/components/schemas/Location/properties/id" + type: array + matched: + description: Whether this item is an exact match of the request + type: boolean + parent_item_id: + allOf: + - $ref: "#/components/schemas/Item/properties/id" + description: "ID of the item, this item is a variant of" + parent_item_quantity: + allOf: + - $ref: "#/components/schemas/ItemQuantity" + description: The number of units of the parent item this item is a multiple of + payment_ids: + description: Payment modalities through which this item can be ordered + items: + allOf: + - $ref: "#/components/schemas/Payment/properties/id" + type: array + price: + allOf: + - $ref: "#/components/schemas/Price" + description: "The price of this item, if it has intrinsic value" + quantity: + allOf: + - $ref: "#/components/schemas/ItemQuantity" + description: The selling quantity of the item + rateable: + description: Whether this item can be rated + type: boolean + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating of the item + recommended: + description: Whether this item is a recommended item to a response + type: boolean + refund_terms: + description: Refund terms of this item + items: + description: Refund term of an item or an order + properties: + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term is applicable. + refund_amount: + $ref: "#/components/schemas/Price" + refund_eligible: + description: Indicates if cancellation will result in a refund + type: boolean + refund_within: + allOf: + - $ref: "#/components/schemas/Time" + description: Time within which refund will be processed after successful cancellation. + type: object + type: array + related: + description: Whether this item is a related item to the exactly matched item + type: boolean + replacement_terms: + description: Terms that are applicable be met when this item is replaced + items: + $ref: "#/components/schemas/ReplacementTerm" + type: array + return_terms: + description: Terms that are applicable when this item is returned + items: + $ref: "#/components/schemas/ReturnTerm" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Temporal attributes of this item. This property is used when the item exists on the catalog only for a limited period of time. + ttl: + description: Time to live in seconds for an instance of this schema + type: string + xinput: + allOf: + - $ref: "#/components/schemas/XInput" + description: Additional input required from the customer to purchase / avail this item + type: object + ItemQuantity: + additionalProperties: false + description: Describes the count or amount of an item + properties: + allocated: + description: This represents the exact quantity allocated for purchase of the item. + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + available: + description: This represents the exact quantity available for purchase of the item. The buyer can only purchase multiples of this + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + maximum: + description: This represents the maximum quantity allowed for purchase of the item + properties: + count: + minimum: 1 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + minimum: + description: This represents the minimum quantity allowed for purchase of the item + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + selected: + description: This represents the quantity selected for purchase of the item + properties: + count: + minimum: 0 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + unitized: + description: This represents the quantity available in a single unit of the item + properties: + count: + maximum: 1 + minimum: 1 + type: integer + measure: + $ref: "#/components/schemas/Scalar" + type: object + type: object + Location: + additionalProperties: false + description: The physical location of something + properties: + 3dspace: + description: The three dimensional region describing this location + type: string + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The address of this location. + area_code: + type: string + circle: + $ref: "#/components/schemas/Circle" + city: + allOf: + - $ref: "#/components/schemas/City" + description: "The city this location is, or is located within" + country: + allOf: + - $ref: "#/components/schemas/Country" + description: "The country this location is, or is located within" + descriptor: + $ref: "#/components/schemas/Descriptor" + district: + description: "The state this location is, or is located within" + type: string + gps: + allOf: + - $ref: "#/components/schemas/Gps" + description: The GPS co-ordinates of this location. + id: + type: string + map_url: + description: The url to the map of the location. This can be a globally recognized map url or the one specified by the network policy. + format: uri + type: string + polygon: + description: The boundary polygon of this location + type: string + rating: + allOf: + - $ref: "#/components/schemas/Rating/properties/value" + description: The rating of this location + state: + allOf: + - $ref: "#/components/schemas/State" + description: "The state this location is, or is located within" + type: object + MediaFile: + additionalProperties: false + description: This object contains a url to a media file. + properties: + dsa: + description: The signing algorithm used by the sender + type: string + mimetype: + description: "indicates the nature and format of the document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838" + type: string + signature: + description: The digital signature of the file signed by the sender + type: string + url: + description: The URL of the file + format: uri + type: string + type: object + Offer: + additionalProperties: false + description: An offer associated with a catalog. This is typically used to promote a particular product and enable more purchases. + properties: + category_ids: + items: + $ref: "#/components/schemas/Category/properties/id" + type: array + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + type: string + item_ids: + items: + $ref: "#/components/schemas/Item/properties/id" + type: array + location_ids: + items: + $ref: "#/components/schemas/Location/properties/id" + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + type: object + Option: + additionalProperties: false + description: Describes a selectable option + properties: + descriptor: + $ref: "#/components/schemas/Descriptor" + id: + type: string + type: object + Order: + additionalProperties: false + description: Describes a legal purchase order. It contains the complete details of the legal contract created between the buyer and the seller. + properties: + add_ons: + description: The add-ons purchased / availed in this order + items: + $ref: "#/components/schemas/AddOn" + type: array + billing: + allOf: + - $ref: "#/components/schemas/Billing" + description: The billing details of this order + cancellation: + allOf: + - $ref: "#/components/schemas/Cancellation" + description: The cancellation details of this order + cancellation_terms: + description: Cancellation terms of this item + items: + $ref: "#/components/schemas/CancellationTerm" + type: array + created_at: + description: The date-time of creation of this order + format: date-time + type: string + fulfillments: + description: The fulfillments involved in completing this order + items: + $ref: "#/components/schemas/Fulfillment" + type: array + id: + description: Human-readable ID of the order. This is generated at the BPP layer. The BPP can either generate order id within its system or forward the order ID created at the provider level. + type: string + items: + description: The items purchased / availed in this order + items: + $ref: "#/components/schemas/Item" + type: array + offers: + description: The offers applied in this order + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + description: The terms of settlement for this order + items: + $ref: "#/components/schemas/Payment" + type: array + provider: + allOf: + - $ref: "#/components/schemas/Provider" + description: Details of the provider whose catalog items have been selected. + quote: + allOf: + - $ref: "#/components/schemas/Quotation" + description: The mutually agreed upon quotation for this order. + ref_order_ids: + description: A list of order IDs to link this order to previous orders. + items: + description: ID of a previous order + type: string + type: array + refund_terms: + description: Refund terms of this item + items: + $ref: "#/components/schemas/Item/properties/refund_terms/items" + type: array + replacement_terms: + description: Replacement terms of this item + items: + $ref: "#/components/schemas/ReplacementTerm" + type: array + return_terms: + description: Return terms of this item + items: + $ref: "#/components/schemas/ReturnTerm" + type: array + status: + description: Status of the order. Allowed values can be defined by the network policy + type: string + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + type: + default: DEFAULT + description: "This is used to indicate the type of order being created to BPPs. Sometimes orders can be linked to previous orders, like a replacement order in a retail domain. A follow-up consultation in healthcare domain. A single order part of a subscription order. The list of order types can be standardized at the network level." + enum: + - DRAFT + - DEFAULT + type: string + updated_at: + description: The date-time of updated of this order + format: date-time + type: string + xinput: + allOf: + - $ref: "#/components/schemas/XInput" + description: Additional input required from the customer to confirm this order + type: object + Organization: + additionalProperties: false + description: An organization. Usually a recognized business entity. + properties: + address: + allOf: + - $ref: "#/components/schemas/Address" + description: The postal address of the organization + city: + allOf: + - $ref: "#/components/schemas/City" + description: The city where the the organization's address is registered + contact: + $ref: "#/components/schemas/Contact" + descriptor: + $ref: "#/components/schemas/Descriptor" + state: + allOf: + - $ref: "#/components/schemas/State" + description: The state where the organization's address is registered + type: object + Payment: + additionalProperties: false + description: "Describes the terms of settlement between the BAP and the BPP for a single transaction. When instantiated, this object contains
  1. the amount that has to be settled,
  2. The payment destination destination details
  3. When the settlement should happen, and
  4. A transaction reference ID
. During a transaction, the BPP reserves the right to decide the terms of payment. However, the BAP can send its terms to the BPP first. If the BPP does not agree to those terms, it must overwrite the terms and return them to the BAP. If overridden, the BAP must either agree to the terms sent by the BPP in order to preserve the provider's autonomy, or abort the transaction. In case of such disagreements, the BAP and the BPP can perform offline negotiations on the payment terms. Once an agreement is reached, the BAP and BPP can resume transactions." + properties: + collected_by: + description: "This field indicates who is the collector of payment. The BAP can set this value to 'bap' if it wants to collect the payment first and settle it to the BPP. If the BPP agrees to those terms, the BPP should not send the payment url. Alternatively, the BPP can set this field with the value 'bpp' if it wants the payment to be made directly." + type: string + id: + description: ID of the payment term that can be referred at an item or an order level in a catalog + type: string + params: + properties: + amount: + type: string + bank_account_number: + type: string + bank_code: + type: string + currency: + type: string + source_bank_account_number: + type: string + source_bank_code: + type: string + source_virtual_payment_address: + type: string + transaction_id: + description: The reference transaction ID associated with a payment activity + type: string + virtual_payment_address: + type: string + type: object + status: + type: string + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + type: + type: string + url: + description: "A payment url to be called by the BAP. If empty, then the payment is to be done offline. The details of payment should be present in the params object. If tl_method = http/get, then the payment details will be sent as url params. Two url param values, ```$transaction_id``` and ```$amount``` are mandatory." + format: uri + type: string + type: object + Person: + additionalProperties: false + description: Describes a person as any individual + properties: + age: + allOf: + - $ref: "#/components/schemas/Duration" + description: Age of the person + creds: + items: + $ref: "#/components/schemas/Credential" + type: array + dob: + description: Date of birth of the person + format: date + type: string + gender: + description: "Gender of something, typically a Person, but possibly also fictional characters, animals, etc. While Male and Female may be used, text strings are also acceptable for people who do not identify as a binary gender.Allowed values for this field can be published in the network policy" + type: string + id: + description: Describes the identity of the person + type: string + image: + $ref: "#/components/schemas/Image" + languages: + items: + description: Describes a language known to the person. + properties: + code: + type: string + name: + type: string + type: object + type: array + name: + description: the name of the person + type: string + skills: + items: + description: Describes a skill of the person. + properties: + code: + type: string + name: + type: string + type: object + type: array + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + url: + description: Profile url of the person + format: uri + type: string + type: object + Price: + additionalProperties: false + description: Describes the price of an item. Allows for domain extension. + properties: + computed_value: + $ref: "#/components/schemas/DecimalValue" + currency: + type: string + estimated_value: + $ref: "#/components/schemas/DecimalValue" + listed_value: + $ref: "#/components/schemas/DecimalValue" + maximum_value: + $ref: "#/components/schemas/DecimalValue" + minimum_value: + $ref: "#/components/schemas/DecimalValue" + offered_value: + $ref: "#/components/schemas/DecimalValue" + value: + $ref: "#/components/schemas/DecimalValue" + type: object + Provider: + additionalProperties: false + description: Describes the catalog of a business. + properties: + categories: + items: + $ref: "#/components/schemas/Category" + type: array + category_id: + description: Category Id of the provider at the BPP-level catalog + type: string + descriptor: + $ref: "#/components/schemas/Descriptor" + exp: + description: Time after which catalog has to be refreshed + format: date-time + type: string + fulfillments: + items: + $ref: "#/components/schemas/Fulfillment" + type: array + id: + description: Id of the provider + type: string + items: + items: + $ref: "#/components/schemas/Item" + type: array + locations: + items: + $ref: "#/components/schemas/Location" + type: array + offers: + items: + $ref: "#/components/schemas/Offer" + type: array + payments: + items: + $ref: "#/components/schemas/Payment" + type: array + rateable: + description: Whether this provider can be rated or not + type: boolean + rating: + $ref: "#/components/schemas/Rating/properties/value" + tags: + items: + $ref: "#/components/schemas/TagGroup" + type: array + time: + $ref: "#/components/schemas/Time" + ttl: + description: "The time-to-live in seconds, for this object. This can be overriden at deeper levels. A value of -1 indicates that this object is not cacheable." + minimum: -1 + type: integer + type: object + Quotation: + additionalProperties: false + description: "Describes a quote. It is the estimated price of products or services from the BPP.
This has properties like price, breakup, ttl" + properties: + breakup: + description: the breakup of the total quoted price + items: + properties: + item: + $ref: "#/components/schemas/Item" + price: + $ref: "#/components/schemas/Price" + title: + type: string + type: object + type: array + id: + description: ID of the quote. + format: uuid + type: string + price: + allOf: + - $ref: "#/components/schemas/Price" + description: The total quoted price + ttl: + $ref: "#/components/schemas/Duration" + type: object + Rating: + additionalProperties: false + description: Describes the rating of an entity + properties: + id: + description: Id of the object being rated + type: string + rating_category: + description: Category of the entity being rated + type: string + value: + description: "Rating value given to the object. This can be a single value or can also contain an inequality operator like gt, gte, lt, lte. This can also contain an inequality expression containing logical operators like && and ||." + type: string + type: object + Region: + additionalProperties: false + description: Describes an arbitrary region of space. The network policy should contain a published list of supported regions by the network. + properties: + boundary: + description: "A string representing the boundary of the region. One-dimensional regions are represented by polylines. Two-dimensional regions are represented by polygons, and three-dimensional regions can represented by polyhedra." + type: string + code: + description: A standard code representing the region. This should be interpreted in the same way by all network participants. + type: string + dimensions: + description: "The number of dimensions that are used to describe any point inside that region. The most common dimensionality of a region is 2, that represents an area on a map. There are regions on the map that can be approximated to one-dimensional regions like roads, railway lines, or shipping lines. 3 dimensional regions are rarer, but are gaining popularity as flying drones are being adopted for various fulfillment services." + enum: + - "1" + - "2" + - "3" + type: string + map_url: + description: The url to the map of the region. This can be a globally recognized map or the one specified by the network policy. + type: string + name: + description: Name of the region as specified on the map where that region exists. + type: string + type: + description: "The type of region. This is used to specify the granularity of the region represented by this object. Various examples of two-dimensional region types are city, country, state, district, and so on. The network policy should contain a list of all possible region types supported by the network." + type: string + type: object + ReplacementTerm: + additionalProperties: false + description: The replacement policy of an item or an order + properties: + external_ref: + $ref: "#/components/schemas/MediaFile" + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term is applicable. + replace_within: + allOf: + - $ref: "#/components/schemas/Time" + description: "Applicable only for buyer managed returns where the buyer has to replace the item before a certain date-time, failing which they will not be eligible for replacement" + type: object + ReturnTerm: + additionalProperties: false + description: Describes the return policy of an item or an order + properties: + fulfillment_managed_by: + description: The entity that will perform the return + type: string + fulfillment_state: + allOf: + - $ref: "#/components/schemas/State" + description: The state of fulfillment during which this term IETF''s applicable. + return_eligible: + description: Indicates whether the item is eligible for return + type: boolean + return_location: + allOf: + - $ref: "#/components/schemas/Location" + description: The location where the item or order must / will be returned to + return_time: + allOf: + - $ref: "#/components/schemas/Time" + description: "Applicable only for buyer managed returns where the buyer has to return the item to the origin before a certain date-time, failing which they will not be eligible for refund." + type: object + Scalar: + additionalProperties: false + description: Describes a scalar + properties: + computed_value: + $ref: "#/components/schemas/DecimalValue" + estimated_value: + $ref: "#/components/schemas/DecimalValue" + range: + properties: + max: + $ref: "#/components/schemas/DecimalValue" + min: + $ref: "#/components/schemas/DecimalValue" + type: object + type: + enum: + - CONSTANT + - VARIABLE + type: string + unit: + type: string + value: + $ref: "#/components/schemas/DecimalValue" + type: object + Schedule: + additionalProperties: false + description: Describes a schedule + properties: + frequency: + $ref: "#/components/schemas/Duration" + holidays: + items: + format: date-time + type: string + type: array + times: + items: + format: date-time + type: string + type: array + type: object + State: + additionalProperties: false + description: A bounded geopolitical region of governance inside a country. + properties: + code: + description: State code as per country or international standards + type: string + name: + description: Name of the state + type: string + type: object + Stop: + additionalProperties: false + description: A logical point in space and time during the fulfillment of an order. + properties: + authorization: + $ref: "#/components/schemas/Authorization" + contact: + allOf: + - $ref: "#/components/schemas/Contact" + description: Contact details of the stop + id: + type: string + instructions: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: Instructions that need to be followed at the stop + location: + allOf: + - $ref: "#/components/schemas/Location" + description: Location of the stop + parent_stop_id: + type: string + person: + allOf: + - $ref: "#/components/schemas/Person" + description: The details of the person present at the stop + time: + allOf: + - $ref: "#/components/schemas/Time" + description: Timings applicable at the stop. + type: + description: The type of stop. Allowed values of this property can be defined by the network policy. + enum: + - START + - END + type: string + type: object + Support: + additionalProperties: false + description: Details of customer support + properties: + callback_phone: + pattern: '^\+?[1-9]\d{1,14}$' + type: string + email: + format: email + type: string + phone: + pattern: '^\+?[1-9]\d{1,14}$' + type: string + ref_id: + type: string + url: + format: uri + type: string + type: object + Tag: + additionalProperties: false + description: "Describes a tag. This is used to contain extended metadata. This object can be added as a property to any schema to describe extended attributes. For BAPs, tags can be sent during search to optimize and filter search results. BPPs can use tags to index their catalog to allow better search functionality. Tags are sent by the BPP as part of the catalog response in the `on_search` callback. Tags are also meant for display purposes. Upon receiving a tag, BAPs are meant to render them as name-value pairs. This is particularly useful when rendering tabular information about a product or service." + properties: + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "Description of the Tag, can be used to store detailed information." + display: + description: "This value indicates if the tag is intended for display purposes. If set to `true`, then this tag must be displayed. If it is set to `false`, it should not be displayed. This value can override the group display value." + type: boolean + value: + description: The value of the tag. This set by the BPP and rendered as-is by the BAP. + type: string + type: object + TagGroup: + additionalProperties: false + description: "A collection of tag objects with group level attributes. For detailed documentation on the Tags and Tag Groups schema go to https://github.com/beckn/protocol-specifications/discussions/316" + properties: + descriptor: + allOf: + - $ref: "#/components/schemas/Descriptor" + description: "Description of the TagGroup, can be used to store detailed information." + display: + default: true + description: "Indicates the display properties of the tag group. If display is set to false, then the group will not be displayed. If it is set to true, it should be displayed. However, group-level display properties can be overriden by individual tag-level display property. As this schema is purely for catalog display purposes, it is not recommended to send this value during search." + type: boolean + list: + description: "An array of Tag objects listed under this group. This property can be set by BAPs during search to narrow the `search` and achieve more relevant results. When received during `on_search`, BAPs must render this list under the heading described by the `name` property of this schema." + items: + $ref: "#/components/schemas/Tag" + type: array + type: object + Time: + additionalProperties: false + description: Describes time in its various forms. It can be a single point in time; duration; or a structured timetable of operations + properties: + days: + description: comma separated values representing days of the week + type: string + duration: + $ref: "#/components/schemas/Duration" + label: + type: string + range: + properties: + end: + format: date-time + type: string + start: + format: date-time + type: string + type: object + schedule: + $ref: "#/components/schemas/Schedule" + timestamp: + format: date-time + type: string + type: object + Tracking: + additionalProperties: false + description: Contains tracking information that can be used by the BAP to track the fulfillment of an order in real-time. which is useful for knowing the location of time sensitive deliveries. + properties: + id: + description: A unique tracking reference number + type: string + location: + allOf: + - $ref: "#/components/schemas/Location" + description: "In case there is no real-time tracking endpoint available, this field will contain the latest location of the entity being tracked. The BPP will update this value everytime the BAP calls the track API." + status: + description: "This value indicates if the tracking is currently active or not. If this value is `active`, then the BAP can begin tracking the order. If this value is `inactive`, the tracking URL is considered to be expired and the BAP should stop tracking the order." + enum: + - ACTIVE + - INACTIVE + type: string + url: + description: "A URL to the tracking endpoint. This can be a link to a tracking webpage, a webhook URL created by the BAP where BPP can push the tracking data, or a GET url creaed by the BPP which the BAP can poll to get the tracking data. It can also be a websocket URL where the BPP can push real-time tracking data." + format: uri + type: string + type: object + Vehicle: + additionalProperties: false + description: "Describes a vehicle is a device that is designed or used to transport people or cargo over land, water, air, or through space.
This has properties like category, capacity, make, model, size,variant,color,energy_type,registration" + properties: + capacity: + type: integer + cargo_volumne: + type: string + category: + type: string + code: + type: string + color: + type: string + emission_standard: + type: string + energy_type: + type: string + make: + type: string + model: + type: string + registration: + type: string + size: + type: string + variant: + type: string + wheelchair_access: + type: string + wheels_count: + type: string + type: object + XInput: + additionalProperties: false + description: "Contains any additional or extended inputs required to confirm an order. This is typically a Form Input. Sometimes, selection of catalog elements is not enough for the BPP to confirm an order. For example, to confirm a flight ticket, the airline requires details of the passengers along with information on baggage, identity, in addition to the class of ticket. Similarly, a logistics company may require details on the nature of shipment in order to confirm the shipping. A recruiting firm may require additional details on the applicant in order to confirm a job application. For all such purposes, the BPP can choose to send this object attached to any object in the catalog that is required to be sent while placing the order. This object can typically be sent at an item level or at the order level. The item level XInput will override the Order level XInput as it indicates a special requirement of information for that particular item. Hence the BAP must render a separate form for the Item and another form at the Order level before confirmation." + properties: + form: + $ref: "#/components/schemas/Form" + required: + description: Indicates whether the form data is mandatorily required by the BPP to confirm the order. + type: boolean + type: object diff --git a/src/app.ts b/src/app.ts index b423f30..600918e 100644 --- a/src/app.ts +++ b/src/app.ts @@ -13,6 +13,7 @@ import { getConfig } from "./utils/config.utils"; import { GatewayUtils } from "./utils/gateway.utils"; import logger from "./utils/logger.utils"; import { OpenApiValidatorMiddleware } from "./middlewares/schemaValidator.middleware"; +import { Validator } from "./middlewares/schemaValidatorAjv.middleware"; const app = Express(); @@ -135,6 +136,7 @@ const main = async () => { getConfig().app.gateway.mode.toLocaleUpperCase().substring(1) ); await OpenApiValidatorMiddleware.getInstance().initOpenApiMiddleware(); + await Validator.getInstance(false).initialize() logger.info('Initialized openapi validator middleware'); } catch (err) { if (err instanceof Exception) { diff --git a/src/middlewares/schemaValidator.middleware.ts b/src/middlewares/schemaValidator.middleware.ts index 8533acf..0c461ba 100644 --- a/src/middlewares/schemaValidator.middleware.ts +++ b/src/middlewares/schemaValidator.middleware.ts @@ -8,7 +8,7 @@ import { v4 as uuid_v4 } from "uuid"; import { Exception, ExceptionType } from "../models/exception.model"; import { Locals } from "../interfaces/locals.interface"; import { getConfig } from "../utils/config.utils"; -import { OpenAPIV3 } from "express-openapi-validator/dist/framework/types"; +import { OpenAPIV3 } from 'openapi-types'; import logger from "../utils/logger.utils"; import { AppMode } from "../schemas/configs/app.config.schema"; import { GatewayMode } from "../schemas/configs/gateway.app.config.schema"; @@ -16,8 +16,8 @@ import { RequestActions, ResponseActions } from "../schemas/configs/actions.app.config.schema"; +import { Validator } from './schemaValidatorAjv.middleware'; -const protocolServerLevel = `${getConfig().app.mode.toUpperCase()}-${getConfig().app.gateway.mode.toUpperCase()}`; const specFolder = 'schemas'; export class OpenApiValidatorMiddleware { @@ -72,6 +72,7 @@ export class OpenApiValidatorMiddleware { logger.info(`Intially cache Not found loadApiSpec file. Loading.... ${file}`); const apiSpec = this.getApiSpec(file); const requestHandler = OpenApiValidator.middleware({ + // @ts-ignore apiSpec, validateRequests: true, validateResponses: false, @@ -116,6 +117,7 @@ export class OpenApiValidatorMiddleware { apiSpec, count: 1, requestHandler: OpenApiValidator.middleware({ + // @ts-ignore apiSpec, validateRequests: true, validateResponses: false, @@ -278,6 +280,17 @@ export const openApiValidatorMiddleware = async ( } } } - const openApiValidator = OpenApiValidatorMiddleware.getInstance().getOpenApiMiddleware(specFile); - walkSubstack([...openApiValidator], req, res, next); + const apiSpecYAML = fs.readFileSync(specFile, "utf8"); + const apiSpec = YAML.parse(apiSpecYAML); + if (apiSpec.openapi === '3.1.0') { + const ajvValidatorInstance = Validator.getInstance(false); + const openApiValidator = ajvValidatorInstance.getValidationMiddleware(); + openApiValidator(req, res, () => { + console.log('Validation Success'); + next() + }); + } else { + const openApiValidator = OpenApiValidatorMiddleware.getInstance().getOpenApiMiddleware(specFile); + walkSubstack([...openApiValidator], req, res, next); + } }; diff --git a/src/middlewares/schemaValidatorAjv.middleware.ts b/src/middlewares/schemaValidatorAjv.middleware.ts new file mode 100644 index 0000000..932af89 --- /dev/null +++ b/src/middlewares/schemaValidatorAjv.middleware.ts @@ -0,0 +1,285 @@ +import fs from 'fs'; +import YAML from 'yaml'; +import Ajv, { ValidateFunction } from 'ajv'; +import addFormats from 'ajv-formats'; +import { OpenAPIV3 } from 'openapi-types'; +import $RefParser from '@apidevtools/json-schema-ref-parser'; +import path from "path"; +import logger from '../utils/logger.utils'; +import { NextFunction, Request, Response } from 'express'; +import { Worker } from 'worker_threads'; +import { Locals } from "../interfaces/locals.interface"; +const specFolder = 'schemas'; +export class Validator { + private static instance: Validator; + private ajv: Ajv; + private schemaCache: Map; + private initialized: boolean = false; + private shouldRunWorker: boolean = false; + private constructor() { + this.ajv = new Ajv({ allErrors: true, coerceTypes: true, useDefaults: true, strict: false }); + addFormats(this.ajv); + this.schemaCache = new Map(); + } + + public static getInstance(shouldRunWorker: boolean): Validator { + if (!Validator.instance) { + Validator.instance = new Validator(); + } + Validator.instance.shouldRunWorker = shouldRunWorker; + return Validator.instance; + } + + async initialize() { + if (this.initialized) return; + console.time('SchemaValidation'); + if (this.shouldRunWorker) { + await this.initializeWorker(); + } else { + console.log('Running in main thread...'); + await this.compileEachSpecFiles(); + } + + console.timeEnd('SchemaValidation'); + this.initialized = true; + } + async initializeWorker() { + console.log('Running in worker thread...'); + const files = fs.readdirSync(specFolder); + const fileNames = files.filter(file => fs.lstatSync(path.join(specFolder, file)).isFile() && (file.endsWith('.yaml') || file.endsWith('.yml'))); + console.log('File names: ', fileNames); + // for (const specPath of fileNames) { + // const serializedEntries: any = await this.runWorker(specPath); + // //console.log('Serialized entries: ', serializedEntries); + + // let deserializedEntries: any; + // try { + // deserializedEntries = JSON.parse(serializedEntries); + // } catch (error) { + // console.error('Error deserializing entries:', error); + // continue; // Skip this entry if deserialization fails + // } + + // deserializedEntries.forEach(([key, value]: [string, any]) => { + // this.schemaCache.set(key, value); + // }); + // } + const workerPromises = fileNames.map(specPath => this.runWorker(specPath)); + let schemaEntries: any = await Promise.all(workerPromises); + console.log('Schema entries: ', typeof schemaEntries); + if (typeof schemaEntries == 'string') { + schemaEntries = JSON.parse(schemaEntries); + } + schemaEntries.forEach((entries: any) => { + let deserializedCache; + console.log('Enteries type : ', typeof entries); + if (typeof entries == 'string') { + console.log('XX'); + logger.info(`Parsing: , ${entries}`); + deserializedCache = JSON.parse(entries); + } + console.log('Decentralized cache type: ', typeof deserializedCache); + + deserializedCache.forEach(([key, value]: [string, any]) => { + this.schemaCache.set(key, value); + }); + }); + } + + private runWorker(specPath: string): Promise<[string, any][]> { + return new Promise((resolve, reject) => { + const worker = new Worker(path.resolve(__dirname, 'schema-compiler-worker.js'), { + workerData: { + specPath, + path: './schema-compiler-worker.ts' + } + }); + + worker.on('message', (message) => { + try { + // Assuming message is already serialized, directly resolve it + resolve(message); + } catch (error) { + reject(error); + } + }); + + worker.on('exit', (code) => { + if (code !== 0) { + reject(new Error(`Worker stopped with exit code ${code}`)); + } + }); + }); + } + + private getApiSpec(specFile: string): OpenAPIV3.Document { + const apiSpecYAML = fs.readFileSync(specFile, "utf8"); + const apiSpec = YAML.parse(apiSpecYAML); + return apiSpec; + }; + + async compileEachSpecFiles() { + const cachedFileLimit: number = 20; + const files = fs.readdirSync(specFolder); + const fileNames = files.filter(file => fs.lstatSync(path.join(specFolder, file)).isFile() && (file.endsWith('.yaml') || file.endsWith('.yml'))); + logger.info(`OpenAPIValidator loaded spec files ${fileNames}`); + logger.info(`OpenAPIValidator Cache count ${cachedFileLimit}`); + for (let i = 0; (i < cachedFileLimit && fileNames[i]); i++) { + const file = `${specFolder}/${fileNames[i]}`; + + const options = { + continueOnError: true, // Continue dereferencing despite errors + }; + let dereferencedSpec: any; + dereferencedSpec = await $RefParser.dereference(this.getApiSpec(file), options) as OpenAPIV3.Document; + //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); + + try { + + await this.compileSchemas(dereferencedSpec, fileNames[i]); + } catch (error) { + console.log('Error derefencing doc: ', error); + } + //const dereferencedSpec = await $RefParser.dereference(this.getApiSpec(file), options) as OpenAPIV3.Document; + + + } + console.log('Schema cache size: ', this.schemaCache.size); + for (const [key, _] of this.schemaCache) { + //logger.info(`Set all cache for validation key and its value : ${key}`); + console.log(`Set all cache for validation key and its value : ${key}`); + } + + } + + private async compileSchemas(spec: OpenAPIV3.Document, file: string) { + //logger.info(`OpenAPIValidator compile schema file: ${file}`); + //logger.info(`OpenAPIValidator compile schema specfile: ${spec}`); + const regex = /\.(yml|yaml)$/; + const fileName = file.split(regex)[0]; + logger.info(`OpenAPIValidator compile schema fileName: ${fileName}`); + Object.keys(spec.paths).forEach(path => { + const methods: any = spec.paths[path]; + Object.keys(methods).forEach(method => { + const operation = methods[method]; + + // Compile request body schema + const requestBodySchema = operation.requestBody && (operation.requestBody as any).content['application/json'].schema; + if (requestBodySchema) { + const key = `${fileName}-${path}-${method}-requestBody`; + this.schemaCache.set(key, this.ajv.compile(requestBodySchema)); + } + + // Compile query parameters schema + const queryParameters = (operation.parameters || []).filter((param: any) => param.in === 'query'); + if (queryParameters.length > 0) { + const key = `${fileName}-${path}-${method}-queryParameters`; + this.schemaCache.set(key, this.ajv.compile({ + type: 'object', properties: queryParameters.reduce((acc: { [x: string]: any; }, param: { name: string | number; schema: any; }) => { + acc[param.name] = param.schema; + return acc; + }, {} as any) + })); + } + + // Compile headers schema + const headers = (operation.parameters || []).filter((param: any) => param.in === 'header'); + if (headers.length > 0) { + const key = `${fileName}-${path}-${method}-headers`; + this.schemaCache.set(key, this.ajv.compile({ + type: 'object', properties: headers.reduce((acc: { [x: string]: any; }, param: { name: string | number; schema: any; }) => { + acc[param.name] = param.schema; + return acc; + }, {} as any) + })); + } + + // Compile response schema + // const responseSchema = operation.responses && (operation.responses['200'] as any).content['application/json'].schema; + // if (responseSchema) { + // const key = `${path}-${method}-response`; + // this.schemaCache.set(key, this.ajv.compile(responseSchema)); + // } + }); + }); + } + + getValidationMiddleware() { + return (req: Request, + res: Response<{}, Locals>, + next: NextFunction) => { + let version = req?.body?.context?.core_version + ? req?.body?.context?.core_version + : req?.body?.context?.version; + let domain = req?.body?.context?.domain; + domain = domain.replace(/:/g, '_'); + const formattedVersion = `${domain.trim()}_${version.trim()}`; + console.log('Formatted version: ', formattedVersion); + + const action = `/${req?.body?.context?.action}`; + const method = req.method.toLowerCase(); + + // Validate request body + const requestBodyKey = `${formattedVersion}-${action}-${method}-requestBody`; + logger.info(`requestBodyKey for incoming req: ${requestBodyKey}`) + if (this.schemaCache.has(requestBodyKey)) { + const validateRequestBody: any = this.schemaCache.get(requestBodyKey); + if (!validateRequestBody(req.body)) { + return res.status(400).json({ error: validateRequestBody.errors }); + } + } else { + //compile schema + //Find the spec file + //load the spec file + //parse and destructure the spec file + //call this.compileSchema(specFile) + const validateRequestBody: any = this.schemaCache.get(requestBodyKey); + if (!validateRequestBody(req.body)) { + return res.status(400).json({ error: validateRequestBody.errors }); + } + } + + // Validate query parameters + const queryParametersKey = `${formattedVersion}-${action}-${method}-queryParameters`; + if (this.schemaCache.has(queryParametersKey)) { + const validateQueryParameters: any = this.schemaCache.get(queryParametersKey); + if (!validateQueryParameters(req.query)) { + return res.status(400).json({ error: validateQueryParameters.errors }); + } + } else { + //compile schema + //Find the spec file + //load the spec file + //parse and destructure the spec file + //call this.compileSchema(specFile) + const validateRequestBody: any = this.schemaCache.get(requestBodyKey); + if (!validateRequestBody(req.body)) { + return res.status(400).json({ error: validateRequestBody.errors }); + } + } + + // Validate headers + const headersKey = `${formattedVersion}-${action}-${method}-headers`; + if (this.schemaCache.has(headersKey)) { + const validateHeaders: any = this.schemaCache.get(headersKey); + if (!validateHeaders(req.headers)) { + return res.status(400).json({ error: validateHeaders.errors }); + } + } else { + //compile schema + //Find the spec file + //load the spec file + //parse and destructure the spec file + //call this.compileSchema(specFile) + const validateRequestBody: any = this.schemaCache.get(requestBodyKey); + if (!validateRequestBody(req.body)) { + return res.status(400).json({ error: validateRequestBody.errors }); + } + } + + next(); + }; + } +} + + From 97c51fae8283e5dfb82a15660b3e05f59cea80a2 Mon Sep 17 00:00:00 2001 From: alephseven Date: Tue, 1 Oct 2024 09:37:09 +0530 Subject: [PATCH 2/3] Removed worker support in AGV and added support for openapi 3.1 --- src/app.ts | 2 +- src/middlewares/schemaValidator.middleware.ts | 4 +- .../schemaValidatorAjv.middleware.ts | 208 +++++++++--------- 3 files changed, 102 insertions(+), 112 deletions(-) diff --git a/src/app.ts b/src/app.ts index 600918e..7db4d09 100644 --- a/src/app.ts +++ b/src/app.ts @@ -136,7 +136,7 @@ const main = async () => { getConfig().app.gateway.mode.toLocaleUpperCase().substring(1) ); await OpenApiValidatorMiddleware.getInstance().initOpenApiMiddleware(); - await Validator.getInstance(false).initialize() + await Validator.getInstance().initialize(); logger.info('Initialized openapi validator middleware'); } catch (err) { if (err instanceof Exception) { diff --git a/src/middlewares/schemaValidator.middleware.ts b/src/middlewares/schemaValidator.middleware.ts index 0c461ba..f2b59d9 100644 --- a/src/middlewares/schemaValidator.middleware.ts +++ b/src/middlewares/schemaValidator.middleware.ts @@ -283,9 +283,9 @@ export const openApiValidatorMiddleware = async ( const apiSpecYAML = fs.readFileSync(specFile, "utf8"); const apiSpec = YAML.parse(apiSpecYAML); if (apiSpec.openapi === '3.1.0') { - const ajvValidatorInstance = Validator.getInstance(false); + const ajvValidatorInstance = Validator.getInstance(); const openApiValidator = ajvValidatorInstance.getValidationMiddleware(); - openApiValidator(req, res, () => { + (await openApiValidator)(req, res, () => { console.log('Validation Success'); next() }); diff --git a/src/middlewares/schemaValidatorAjv.middleware.ts b/src/middlewares/schemaValidatorAjv.middleware.ts index 932af89..c2c7d92 100644 --- a/src/middlewares/schemaValidatorAjv.middleware.ts +++ b/src/middlewares/schemaValidatorAjv.middleware.ts @@ -7,110 +7,37 @@ import $RefParser from '@apidevtools/json-schema-ref-parser'; import path from "path"; import logger from '../utils/logger.utils'; import { NextFunction, Request, Response } from 'express'; -import { Worker } from 'worker_threads'; import { Locals } from "../interfaces/locals.interface"; +import { getConfig } from '../utils/config.utils'; +import { Exception, ExceptionType } from '../models/exception.model'; const specFolder = 'schemas'; export class Validator { private static instance: Validator; private ajv: Ajv; private schemaCache: Map; private initialized: boolean = false; - private shouldRunWorker: boolean = false; private constructor() { this.ajv = new Ajv({ allErrors: true, coerceTypes: true, useDefaults: true, strict: false }); addFormats(this.ajv); this.schemaCache = new Map(); } - public static getInstance(shouldRunWorker: boolean): Validator { + public static getInstance(): Validator { + if (!Validator.instance) { Validator.instance = new Validator(); } - Validator.instance.shouldRunWorker = shouldRunWorker; return Validator.instance; } async initialize() { if (this.initialized) return; console.time('SchemaValidation'); - if (this.shouldRunWorker) { - await this.initializeWorker(); - } else { - console.log('Running in main thread...'); - await this.compileEachSpecFiles(); - } - + console.log('Running in main thread...'); + await this.compileEachSpecFiles(); console.timeEnd('SchemaValidation'); this.initialized = true; } - async initializeWorker() { - console.log('Running in worker thread...'); - const files = fs.readdirSync(specFolder); - const fileNames = files.filter(file => fs.lstatSync(path.join(specFolder, file)).isFile() && (file.endsWith('.yaml') || file.endsWith('.yml'))); - console.log('File names: ', fileNames); - // for (const specPath of fileNames) { - // const serializedEntries: any = await this.runWorker(specPath); - // //console.log('Serialized entries: ', serializedEntries); - - // let deserializedEntries: any; - // try { - // deserializedEntries = JSON.parse(serializedEntries); - // } catch (error) { - // console.error('Error deserializing entries:', error); - // continue; // Skip this entry if deserialization fails - // } - - // deserializedEntries.forEach(([key, value]: [string, any]) => { - // this.schemaCache.set(key, value); - // }); - // } - const workerPromises = fileNames.map(specPath => this.runWorker(specPath)); - let schemaEntries: any = await Promise.all(workerPromises); - console.log('Schema entries: ', typeof schemaEntries); - if (typeof schemaEntries == 'string') { - schemaEntries = JSON.parse(schemaEntries); - } - schemaEntries.forEach((entries: any) => { - let deserializedCache; - console.log('Enteries type : ', typeof entries); - if (typeof entries == 'string') { - console.log('XX'); - logger.info(`Parsing: , ${entries}`); - deserializedCache = JSON.parse(entries); - } - console.log('Decentralized cache type: ', typeof deserializedCache); - - deserializedCache.forEach(([key, value]: [string, any]) => { - this.schemaCache.set(key, value); - }); - }); - } - - private runWorker(specPath: string): Promise<[string, any][]> { - return new Promise((resolve, reject) => { - const worker = new Worker(path.resolve(__dirname, 'schema-compiler-worker.js'), { - workerData: { - specPath, - path: './schema-compiler-worker.ts' - } - }); - - worker.on('message', (message) => { - try { - // Assuming message is already serialized, directly resolve it - resolve(message); - } catch (error) { - reject(error); - } - }); - - worker.on('exit', (code) => { - if (code !== 0) { - reject(new Error(`Worker stopped with exit code ${code}`)); - } - }); - }); - } private getApiSpec(specFile: string): OpenAPIV3.Document { const apiSpecYAML = fs.readFileSync(specFile, "utf8"); @@ -119,7 +46,7 @@ export class Validator { }; async compileEachSpecFiles() { - const cachedFileLimit: number = 20; + const cachedFileLimit: number = 4; const files = fs.readdirSync(specFolder); const fileNames = files.filter(file => fs.lstatSync(path.join(specFolder, file)).isFile() && (file.endsWith('.yaml') || file.endsWith('.yml'))); logger.info(`OpenAPIValidator loaded spec files ${fileNames}`); @@ -132,7 +59,6 @@ export class Validator { }; let dereferencedSpec: any; dereferencedSpec = await $RefParser.dereference(this.getApiSpec(file), options) as OpenAPIV3.Document; - //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); try { @@ -140,21 +66,18 @@ export class Validator { } catch (error) { console.log('Error derefencing doc: ', error); } - //const dereferencedSpec = await $RefParser.dereference(this.getApiSpec(file), options) as OpenAPIV3.Document; } console.log('Schema cache size: ', this.schemaCache.size); for (const [key, _] of this.schemaCache) { - //logger.info(`Set all cache for validation key and its value : ${key}`); + logger.info(`Set all cache for validation key and its value : ${key}`); console.log(`Set all cache for validation key and its value : ${key}`); } } private async compileSchemas(spec: OpenAPIV3.Document, file: string) { - //logger.info(`OpenAPIValidator compile schema file: ${file}`); - //logger.info(`OpenAPIValidator compile schema specfile: ${spec}`); const regex = /\.(yml|yaml)$/; const fileName = file.split(regex)[0]; logger.info(`OpenAPIValidator compile schema fileName: ${fileName}`); @@ -164,17 +87,17 @@ export class Validator { const operation = methods[method]; // Compile request body schema + const bodyKey = `${fileName}-${path}-${method}-requestBody`; const requestBodySchema = operation.requestBody && (operation.requestBody as any).content['application/json'].schema; - if (requestBodySchema) { - const key = `${fileName}-${path}-${method}-requestBody`; - this.schemaCache.set(key, this.ajv.compile(requestBodySchema)); + if (!this.schemaCache.has(bodyKey) && requestBodySchema) { + this.schemaCache.set(bodyKey, this.ajv.compile(requestBodySchema)); } // Compile query parameters schema + const queryKey = `${fileName}-${path}-${method}-queryParameters`; const queryParameters = (operation.parameters || []).filter((param: any) => param.in === 'query'); - if (queryParameters.length > 0) { - const key = `${fileName}-${path}-${method}-queryParameters`; - this.schemaCache.set(key, this.ajv.compile({ + if (!this.schemaCache.has(queryKey) && queryParameters.length) { + this.schemaCache.set(queryKey, this.ajv.compile({ type: 'object', properties: queryParameters.reduce((acc: { [x: string]: any; }, param: { name: string | number; schema: any; }) => { acc[param.name] = param.schema; return acc; @@ -184,9 +107,9 @@ export class Validator { // Compile headers schema const headers = (operation.parameters || []).filter((param: any) => param.in === 'header'); - if (headers.length > 0) { - const key = `${fileName}-${path}-${method}-headers`; - this.schemaCache.set(key, this.ajv.compile({ + const headerKey = `${fileName}-${path}-${method}-headers`; + if (!this.schemaCache.has(headerKey) && headers.length) { + this.schemaCache.set(headerKey, this.ajv.compile({ type: 'object', properties: headers.reduce((acc: { [x: string]: any; }, param: { name: string | number; schema: any; }) => { acc[param.name] = param.schema; return acc; @@ -204,8 +127,8 @@ export class Validator { }); } - getValidationMiddleware() { - return (req: Request, + async getValidationMiddleware() { + return async (req: Request, res: Response<{}, Locals>, next: NextFunction) => { let version = req?.body?.context?.core_version @@ -215,10 +138,46 @@ export class Validator { domain = domain.replace(/:/g, '_'); const formattedVersion = `${domain.trim()}_${version.trim()}`; console.log('Formatted version: ', formattedVersion); - const action = `/${req?.body?.context?.action}`; const method = req.method.toLowerCase(); - + let specFile = `${specFolder}/core_${version}.yaml`; + let specFileName = `core_${version}.yaml`; + for (const [key, _] of this.schemaCache) { + //logger.info(`Set all cache for validation key and its value : ${key}`); + console.log(`Cache key: ${key}`); + } + if (getConfig().app.useLayer2Config) { + let doesLayer2ConfigExist = false; + let layer2ConfigFilename = `${req?.body?.context?.domain}_${version}.yaml`; + let specialCharsRe = /[:\/]/gi; + layer2ConfigFilename = layer2ConfigFilename.replace(specialCharsRe, "_"); + try { + doesLayer2ConfigExist = ( + await fs.promises.readdir( + `${path.join(path.resolve(__dirname, "../../"))}/${specFolder}` + ) + ).includes(layer2ConfigFilename); + } catch (error) { + doesLayer2ConfigExist = false; + } + if (doesLayer2ConfigExist) { + specFile = `${specFolder}/${layer2ConfigFilename}`; + specFileName = layer2ConfigFilename; + } + else { + if (getConfig().app.mandateLayer2Config) { + const message = `Layer 2 config file ${layer2ConfigFilename} is not installed and it is marked as required in configuration` + logger.error(message); + return next( + new Exception( + ExceptionType.Config_AppConfig_Layer2_Missing, + message, + 422 + ) + ); + } + } + } // Validate request body const requestBodyKey = `${formattedVersion}-${action}-${method}-requestBody`; logger.info(`requestBodyKey for incoming req: ${requestBodyKey}`) @@ -228,18 +187,27 @@ export class Validator { return res.status(400).json({ error: validateRequestBody.errors }); } } else { - //compile schema - //Find the spec file - //load the spec file + console.log(`AGV Validation Cache miss for ${specFileName} and request body: ${requestBodyKey}`); + const apiSpecYAML = this.getApiSpec(specFile); //parse and destructure the spec file - //call this.compileSchema(specFile) + const options = { + continueOnError: true, // Continue dereferencing despite errors + }; + let dereferencedSpec: any; + dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; + + try { + await this.compileSchemas(dereferencedSpec, specFileName); + } catch (error) { + console.log('Error derefencing doc: ', error); + } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) { return res.status(400).json({ error: validateRequestBody.errors }); } } - // Validate query parameters + //Validate query parameters const queryParametersKey = `${formattedVersion}-${action}-${method}-queryParameters`; if (this.schemaCache.has(queryParametersKey)) { const validateQueryParameters: any = this.schemaCache.get(queryParametersKey); @@ -249,9 +217,21 @@ export class Validator { } else { //compile schema //Find the spec file - //load the spec file + console.log(`AGV Validation Cache miss for ${specFileName} and query-param-key: ${queryParametersKey}`); + const apiSpecYAML = this.getApiSpec(specFile); //parse and destructure the spec file - //call this.compileSchema(specFile) + const options = { + continueOnError: true, // Continue dereferencing despite errors + }; + let dereferencedSpec: any; + dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; + //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); + + try { + await this.compileSchemas(dereferencedSpec, specFileName); + } catch (error) { + console.log('Error derefencing doc: ', error); + } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) { return res.status(400).json({ error: validateRequestBody.errors }); @@ -268,18 +248,28 @@ export class Validator { } else { //compile schema //Find the spec file - //load the spec file + console.log(`AGV Validation Cache miss for ${specFileName} and header-key: ${headersKey}`); + const apiSpecYAML = this.getApiSpec(specFile); //parse and destructure the spec file - //call this.compileSchema(specFile) + const options = { + continueOnError: true, // Continue dereferencing despite errors + }; + let dereferencedSpec: any; + dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; + //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); + + try { + await this.compileSchemas(dereferencedSpec, specFileName); + } catch (error) { + console.log('Error derefencing doc: ', error); + } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) { return res.status(400).json({ error: validateRequestBody.errors }); } } - next(); }; } } - From b98f7e4430fa3775c5536490cd65d05d689aabda Mon Sep 17 00:00:00 2001 From: alephseven Date: Tue, 1 Oct 2024 13:31:38 +0530 Subject: [PATCH 3/3] Optimised and cleaned up the unwanted code --- src/middlewares/schemaValidator.middleware.ts | 11 ++- .../schemaValidatorAjv.middleware.ts | 80 +++---------------- 2 files changed, 20 insertions(+), 71 deletions(-) diff --git a/src/middlewares/schemaValidator.middleware.ts b/src/middlewares/schemaValidator.middleware.ts index f2b59d9..435afcf 100644 --- a/src/middlewares/schemaValidator.middleware.ts +++ b/src/middlewares/schemaValidator.middleware.ts @@ -250,7 +250,7 @@ export const openApiValidatorMiddleware = async ( ? req?.body?.context?.core_version : req?.body?.context?.version; let specFile = `${specFolder}/core_${version}.yaml`; - + let specFileName = `core_${version}.yaml`; if (getConfig().app.useLayer2Config) { let doesLayer2ConfigExist = false; let layer2ConfigFilename = `${req?.body?.context?.domain}_${version}.yaml`; @@ -265,7 +265,10 @@ export const openApiValidatorMiddleware = async ( } catch (error) { doesLayer2ConfigExist = false; } - if (doesLayer2ConfigExist) specFile = `${specFolder}/${layer2ConfigFilename}`; + if (doesLayer2ConfigExist) { + specFile = `${specFolder}/${layer2ConfigFilename}`; + specFileName = layer2ConfigFilename; + } else { if (getConfig().app.mandateLayer2Config) { const message = `Layer 2 config file ${layer2ConfigFilename} is not installed and it is marked as required in configuration` @@ -284,9 +287,9 @@ export const openApiValidatorMiddleware = async ( const apiSpec = YAML.parse(apiSpecYAML); if (apiSpec.openapi === '3.1.0') { const ajvValidatorInstance = Validator.getInstance(); - const openApiValidator = ajvValidatorInstance.getValidationMiddleware(); + const openApiValidator = await ajvValidatorInstance.getValidationMiddleware(specFile, specFileName); (await openApiValidator)(req, res, () => { - console.log('Validation Success'); + logger.info('Validation Success'); next() }); } else { diff --git a/src/middlewares/schemaValidatorAjv.middleware.ts b/src/middlewares/schemaValidatorAjv.middleware.ts index c2c7d92..250fd75 100644 --- a/src/middlewares/schemaValidatorAjv.middleware.ts +++ b/src/middlewares/schemaValidatorAjv.middleware.ts @@ -9,7 +9,6 @@ import logger from '../utils/logger.utils'; import { NextFunction, Request, Response } from 'express'; import { Locals } from "../interfaces/locals.interface"; import { getConfig } from '../utils/config.utils'; -import { Exception, ExceptionType } from '../models/exception.model'; const specFolder = 'schemas'; export class Validator { private static instance: Validator; @@ -23,7 +22,6 @@ export class Validator { } public static getInstance(): Validator { - if (!Validator.instance) { Validator.instance = new Validator(); } @@ -33,7 +31,6 @@ export class Validator { async initialize() { if (this.initialized) return; console.time('SchemaValidation'); - console.log('Running in main thread...'); await this.compileEachSpecFiles(); console.timeEnd('SchemaValidation'); this.initialized = true; @@ -46,11 +43,11 @@ export class Validator { }; async compileEachSpecFiles() { - const cachedFileLimit: number = 4; + const cachedFileLimit: number = getConfig().app?.openAPIValidator?.cachedFileLimit || 3; + logger.info(`OpenAPIValidator Cache count ${cachedFileLimit}`); const files = fs.readdirSync(specFolder); const fileNames = files.filter(file => fs.lstatSync(path.join(specFolder, file)).isFile() && (file.endsWith('.yaml') || file.endsWith('.yml'))); logger.info(`OpenAPIValidator loaded spec files ${fileNames}`); - logger.info(`OpenAPIValidator Cache count ${cachedFileLimit}`); for (let i = 0; (i < cachedFileLimit && fileNames[i]); i++) { const file = `${specFolder}/${fileNames[i]}`; @@ -61,18 +58,16 @@ export class Validator { dereferencedSpec = await $RefParser.dereference(this.getApiSpec(file), options) as OpenAPIV3.Document; try { - await this.compileSchemas(dereferencedSpec, fileNames[i]); } catch (error) { - console.log('Error derefencing doc: ', error); + logger.error(`Error derefencing doc: ${error}`); } } - console.log('Schema cache size: ', this.schemaCache.size); + logger.info(`Schema cache size: ${this.schemaCache.size}`); for (const [key, _] of this.schemaCache) { logger.info(`Set all cache for validation key and its value : ${key}`); - console.log(`Set all cache for validation key and its value : ${key}`); } } @@ -127,7 +122,7 @@ export class Validator { }); } - async getValidationMiddleware() { + async getValidationMiddleware(specFile: string, specFileName: string) { return async (req: Request, res: Response<{}, Locals>, next: NextFunction) => { @@ -137,47 +132,9 @@ export class Validator { let domain = req?.body?.context?.domain; domain = domain.replace(/:/g, '_'); const formattedVersion = `${domain.trim()}_${version.trim()}`; - console.log('Formatted version: ', formattedVersion); + logger.info(`Formatted version: ${formattedVersion}`); const action = `/${req?.body?.context?.action}`; const method = req.method.toLowerCase(); - let specFile = `${specFolder}/core_${version}.yaml`; - let specFileName = `core_${version}.yaml`; - for (const [key, _] of this.schemaCache) { - //logger.info(`Set all cache for validation key and its value : ${key}`); - console.log(`Cache key: ${key}`); - } - if (getConfig().app.useLayer2Config) { - let doesLayer2ConfigExist = false; - let layer2ConfigFilename = `${req?.body?.context?.domain}_${version}.yaml`; - let specialCharsRe = /[:\/]/gi; - layer2ConfigFilename = layer2ConfigFilename.replace(specialCharsRe, "_"); - try { - doesLayer2ConfigExist = ( - await fs.promises.readdir( - `${path.join(path.resolve(__dirname, "../../"))}/${specFolder}` - ) - ).includes(layer2ConfigFilename); - } catch (error) { - doesLayer2ConfigExist = false; - } - if (doesLayer2ConfigExist) { - specFile = `${specFolder}/${layer2ConfigFilename}`; - specFileName = layer2ConfigFilename; - } - else { - if (getConfig().app.mandateLayer2Config) { - const message = `Layer 2 config file ${layer2ConfigFilename} is not installed and it is marked as required in configuration` - logger.error(message); - return next( - new Exception( - ExceptionType.Config_AppConfig_Layer2_Missing, - message, - 422 - ) - ); - } - } - } // Validate request body const requestBodyKey = `${formattedVersion}-${action}-${method}-requestBody`; logger.info(`requestBodyKey for incoming req: ${requestBodyKey}`) @@ -187,9 +144,8 @@ export class Validator { return res.status(400).json({ error: validateRequestBody.errors }); } } else { - console.log(`AGV Validation Cache miss for ${specFileName} and request body: ${requestBodyKey}`); + logger.info(`AGV Validation Cache miss for ${specFileName} and request body: ${requestBodyKey}`); const apiSpecYAML = this.getApiSpec(specFile); - //parse and destructure the spec file const options = { continueOnError: true, // Continue dereferencing despite errors }; @@ -199,7 +155,7 @@ export class Validator { try { await this.compileSchemas(dereferencedSpec, specFileName); } catch (error) { - console.log('Error derefencing doc: ', error); + logger.error(`Error derefencing doc: ${error}`); } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) { @@ -215,22 +171,17 @@ export class Validator { return res.status(400).json({ error: validateQueryParameters.errors }); } } else { - //compile schema - //Find the spec file - console.log(`AGV Validation Cache miss for ${specFileName} and query-param-key: ${queryParametersKey}`); + logger.info(`AGV Validation Cache miss for ${specFileName} and query-param-key: ${queryParametersKey}`); const apiSpecYAML = this.getApiSpec(specFile); - //parse and destructure the spec file const options = { continueOnError: true, // Continue dereferencing despite errors }; let dereferencedSpec: any; - dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; - //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); - + dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; try { await this.compileSchemas(dereferencedSpec, specFileName); } catch (error) { - console.log('Error derefencing doc: ', error); + logger.error(`Error derefencing doc: ${error}`); } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) { @@ -246,22 +197,17 @@ export class Validator { return res.status(400).json({ error: validateHeaders.errors }); } } else { - //compile schema - //Find the spec file - console.log(`AGV Validation Cache miss for ${specFileName} and header-key: ${headersKey}`); + logger.info(`AGV Validation Cache miss for ${specFileName} and header-key: ${headersKey}`); const apiSpecYAML = this.getApiSpec(specFile); - //parse and destructure the spec file const options = { continueOnError: true, // Continue dereferencing despite errors }; let dereferencedSpec: any; dereferencedSpec = await $RefParser.dereference(apiSpecYAML, options) as OpenAPIV3.Document; - //console.log('Dereferenced spec file: ', JSON.stringify(dereferencedSpec)); - try { await this.compileSchemas(dereferencedSpec, specFileName); } catch (error) { - console.log('Error derefencing doc: ', error); + logger.error(`Error derefencing doc: ${error}`); } const validateRequestBody: any = this.schemaCache.get(requestBodyKey); if (!validateRequestBody(req.body)) {