ondc-code-generator 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/.idea/code-generator.iml +12 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/LICENSE +21 -0
  5. package/README.md +0 -0
  6. package/custom-loader.js +4 -0
  7. package/dist/Generator/config-compiler.js +53 -0
  8. package/dist/Generator/config-validator.js +21 -0
  9. package/dist/Generator/generators/classes/abstract-generator.js +16 -0
  10. package/dist/Generator/generators/documentation/markdown-message-generator.js +37 -0
  11. package/dist/Generator/generators/documentation/md-generator.js +57 -0
  12. package/dist/Generator/generators/markdown-message-generator.js +25 -0
  13. package/dist/Generator/generators/python/py-generator.js +1 -0
  14. package/dist/Generator/generators/typescript/templates/json-path-utils.js +15 -0
  15. package/dist/Generator/generators/typescript/templates/validation-utils.js +91 -0
  16. package/dist/Generator/generators/typescript/ts-ast.js +50 -0
  17. package/dist/Generator/generators/typescript/ts-generator.js +184 -0
  18. package/dist/Generator/pipline.js +1 -0
  19. package/dist/Generator/validators/abstract-validator.js +6 -0
  20. package/dist/Generator/validators/config-validator.js +32 -0
  21. package/dist/Generator/validators/session-data-config/session-data-validator.js +35 -0
  22. package/dist/Generator/validators/tests-config/sub-validations.js +194 -0
  23. package/dist/Generator/validators/tests-config/test-list-validator.js +36 -0
  24. package/dist/Generator/validators/tests-config/test-validator.js +24 -0
  25. package/dist/Generator/validators/validation-error.js +9 -0
  26. package/dist/constants/operations.js +17 -0
  27. package/dist/constants/syntax.js +75 -0
  28. package/dist/index.js +39 -0
  29. package/dist/services/rename-later/main.js +1 -0
  30. package/dist/services/rename-later/parser.js +22 -0
  31. package/dist/services/rename-later/tokens.js +32 -0
  32. package/dist/services/rename-later/tokens1.js +33 -0
  33. package/dist/services/return-complier/ast-functions/compile-to-markdown.js +66 -0
  34. package/dist/services/return-complier/ast-functions/semantic-validations.js +30 -0
  35. package/dist/services/return-complier/ast.js +92 -0
  36. package/dist/services/return-complier/combined.js +7 -0
  37. package/dist/services/return-complier/parser.js +95 -0
  38. package/dist/services/return-complier/tokens.js +144 -0
  39. package/dist/services/schema-service.js +29 -0
  40. package/dist/types/build.js +1 -0
  41. package/dist/types/compiler-types.js +4 -0
  42. package/dist/types/config-types.js +1 -0
  43. package/dist/types/error-codes.js +1 -0
  44. package/dist/types/general-types.js +1 -0
  45. package/dist/utils/config-utils/json-schema-utils.js +91 -0
  46. package/dist/utils/config-utils/yaml.js +16 -0
  47. package/dist/utils/file-system.js +1 -0
  48. package/dist/utils/fs-utils.js +20 -0
  49. package/dist/utils/general-utils/string-utils.js +56 -0
  50. package/dist/utils/general-utils/test-object-utils.js +12 -0
  51. package/dist/utils/general-utils/validation-utils.js +21 -0
  52. package/dist/utils/json-path-utils/extract-string-paths.js +113 -0
  53. package/dist/utils/json-path-utils/paths.js +46 -0
  54. package/dist/utils/logger.js +41 -0
  55. package/docs/error-gen.md +33 -0
  56. package/docs/return-grammer.md +23 -0
  57. package/docs/sampleConfig.md +39 -0
  58. package/generated/L1-validations/api-tests/cancel.ts +569 -0
  59. package/generated/L1-validations/api-tests/confirm.ts +1162 -0
  60. package/generated/L1-validations/api-tests/init.ts +1063 -0
  61. package/generated/L1-validations/api-tests/on_cancel.ts +2069 -0
  62. package/generated/L1-validations/api-tests/on_confirm.ts +2219 -0
  63. package/generated/L1-validations/api-tests/on_init.ts +1949 -0
  64. package/generated/L1-validations/api-tests/on_search.ts +1574 -0
  65. package/generated/L1-validations/api-tests/on_select.ts +1723 -0
  66. package/generated/L1-validations/api-tests/on_status.ts +2221 -0
  67. package/generated/L1-validations/api-tests/on_update.ts +1969 -0
  68. package/generated/L1-validations/api-tests/search.ts +695 -0
  69. package/generated/L1-validations/api-tests/select.ts +994 -0
  70. package/generated/L1-validations/api-tests/status.ts +443 -0
  71. package/generated/L1-validations/api-tests/update.ts +898 -0
  72. package/generated/L1-validations/error.ts +64 -0
  73. package/generated/L1-validations/index.ts +138 -0
  74. package/generated/L1-validations/page/index.html +2118 -0
  75. package/generated/L1-validations/page/style.css +225 -0
  76. package/generated/L1-validations/readme.md +1779 -0
  77. package/generated/L1-validations/types/test-config.ts +27 -0
  78. package/generated/L1-validations/utils/json-path-utils.ts +17 -0
  79. package/generated/L1-validations/utils/validation-utils.ts +116 -0
  80. package/generated-structure/api-tests/search.ts +24 -0
  81. package/generated-structure/error.ts +0 -0
  82. package/generated-structure/index.ts +0 -0
  83. package/generated-structure/types/test-config.ts +21 -0
  84. package/nodemon.json +5 -0
  85. package/package.json +40 -0
  86. package/samples/build.yaml +24799 -0
  87. package/samples/output.md +91 -0
  88. package/samples/output.ts +27 -0
  89. package/samples/selections.json +216 -0
  90. package/samples/validation-config.json +3422 -0
  91. package/samples/x-validations.yaml +2893 -0
  92. package/src/constants/operations.ts +19 -0
  93. package/src/constants/syntax.ts +81 -0
  94. package/src/example.ts +25 -0
  95. package/src/generator/config-compiler.ts +122 -0
  96. package/src/generator/generators/classes/abstract-generator.ts +29 -0
  97. package/src/generator/generators/documentation/markdown-message-generator.ts +43 -0
  98. package/src/generator/generators/documentation/md-generator.ts +76 -0
  99. package/src/generator/generators/documentation/templates/index.mustache +36 -0
  100. package/src/generator/generators/documentation/templates/style.css +204 -0
  101. package/src/generator/generators/python/py-generator.ts +0 -0
  102. package/src/generator/generators/typescript/templates/api-test.mustache +7 -0
  103. package/src/generator/generators/typescript/templates/json-path-utils.ts +17 -0
  104. package/src/generator/generators/typescript/templates/schema-template.mustache +18 -0
  105. package/src/generator/generators/typescript/templates/test-config.mustache +28 -0
  106. package/src/generator/generators/typescript/templates/test-object.mustache +20 -0
  107. package/src/generator/generators/typescript/templates/validation-code.mustache +39 -0
  108. package/src/generator/generators/typescript/templates/validation-utils.ts +117 -0
  109. package/src/generator/generators/typescript/ts-ast.ts +72 -0
  110. package/src/generator/generators/typescript/ts-generator.ts +275 -0
  111. package/src/generator/validators/abstract-validator.ts +23 -0
  112. package/src/generator/validators/config-validator.ts +55 -0
  113. package/src/generator/validators/session-data-config/session-data-validator.ts +58 -0
  114. package/src/generator/validators/tests-config/sub-validations.ts +302 -0
  115. package/src/generator/validators/tests-config/test-list-validator.ts +59 -0
  116. package/src/generator/validators/tests-config/test-validator.ts +69 -0
  117. package/src/index.ts +2 -0
  118. package/src/services/return-complier/ast-functions/compile-to-markdown.ts +152 -0
  119. package/src/services/return-complier/ast-functions/semantic-validations.ts +44 -0
  120. package/src/services/return-complier/ast.ts +147 -0
  121. package/src/services/return-complier/combined.ts +8 -0
  122. package/src/services/return-complier/parser.ts +128 -0
  123. package/src/services/return-complier/tokens.ts +184 -0
  124. package/src/services/schema-service.ts +42 -0
  125. package/src/types/build.ts +51 -0
  126. package/src/types/compiler-types.ts +3 -0
  127. package/src/types/config-types.ts +27 -0
  128. package/src/types/error-codes.ts +6 -0
  129. package/src/types/general-types.ts +2 -0
  130. package/src/utils/config-utils/json-schema-utils.ts +150 -0
  131. package/src/utils/config-utils/yaml.ts +17 -0
  132. package/src/utils/fs-utils.ts +32 -0
  133. package/src/utils/general-utils/string-utils.ts +76 -0
  134. package/src/utils/general-utils/test-object-utils.ts +14 -0
  135. package/src/utils/general-utils/validation-utils.ts +30 -0
  136. package/src/utils/json-path-utils/extract-string-paths.ts +139 -0
  137. package/src/utils/json-path-utils/paths.ts +44 -0
  138. package/src/utils/logger.ts +53 -0
  139. package/tsconfig.json +17 -0
@@ -0,0 +1,994 @@
1
+ import payloadUtils from "../utils/json-path-utils";
2
+ import validations from "../utils/validation-utils";
3
+ import {
4
+ testFunctionArray,
5
+ validationInput,
6
+ validationOutput,
7
+ } from "../types/test-config";
8
+
9
+ export default function select(input: validationInput): validationOutput {
10
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
11
+ let subResults: validationOutput = [];
12
+ let valid = true;
13
+ for (const testObj of scope) {
14
+ testObj._EXTERNAL = input.externalData;
15
+
16
+ function Attri_Required_1_CONTEXT_TIMESTAMP(
17
+ input: validationInput,
18
+ ): validationOutput {
19
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
20
+ let subResults: validationOutput = [];
21
+ let valid = true;
22
+ for (const testObj of scope) {
23
+ testObj._EXTERNAL = input.externalData;
24
+ const attr = payloadUtils.getJsonPath(
25
+ testObj,
26
+ "$.context.timestamp",
27
+ );
28
+
29
+ const validate = validations.arePresent(attr);
30
+
31
+ if (!validate) {
32
+ return [
33
+ {
34
+ valid: false,
35
+ code: 30000,
36
+ description: `- **condition Attri_Required_1_CONTEXT_TIMESTAMP**: $.context.timestamp must be present in the payload`,
37
+ },
38
+ ];
39
+ }
40
+
41
+ delete testObj._EXTERNAL;
42
+ }
43
+ return [{ valid: valid, code: 200 }, ...subResults];
44
+ }
45
+ function Attri_Required_2_CONTEXT_BAP_ID(
46
+ input: validationInput,
47
+ ): validationOutput {
48
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
49
+ let subResults: validationOutput = [];
50
+ let valid = true;
51
+ for (const testObj of scope) {
52
+ testObj._EXTERNAL = input.externalData;
53
+ const attr = payloadUtils.getJsonPath(
54
+ testObj,
55
+ "$.context.bap_id",
56
+ );
57
+
58
+ const validate = validations.arePresent(attr);
59
+
60
+ if (!validate) {
61
+ return [
62
+ {
63
+ valid: false,
64
+ code: 30000,
65
+ description: `- **condition Attri_Required_2_CONTEXT_BAP_ID**: $.context.bap_id must be present in the payload`,
66
+ },
67
+ ];
68
+ }
69
+
70
+ delete testObj._EXTERNAL;
71
+ }
72
+ return [{ valid: valid, code: 200 }, ...subResults];
73
+ }
74
+ function Attri_Required_3_CONTEXT_TRANSACTION_ID(
75
+ input: validationInput,
76
+ ): validationOutput {
77
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
78
+ let subResults: validationOutput = [];
79
+ let valid = true;
80
+ for (const testObj of scope) {
81
+ testObj._EXTERNAL = input.externalData;
82
+ const attr = payloadUtils.getJsonPath(
83
+ testObj,
84
+ "$.context.transaction_id",
85
+ );
86
+
87
+ const validate = validations.arePresent(attr);
88
+
89
+ if (!validate) {
90
+ return [
91
+ {
92
+ valid: false,
93
+ code: 30000,
94
+ description: `- **condition Attri_Required_3_CONTEXT_TRANSACTION_ID**: $.context.transaction_id must be present in the payload`,
95
+ },
96
+ ];
97
+ }
98
+
99
+ delete testObj._EXTERNAL;
100
+ }
101
+ return [{ valid: valid, code: 200 }, ...subResults];
102
+ }
103
+ function Attri_Required_4_CONTEXT_MESSAGE_ID(
104
+ input: validationInput,
105
+ ): validationOutput {
106
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
107
+ let subResults: validationOutput = [];
108
+ let valid = true;
109
+ for (const testObj of scope) {
110
+ testObj._EXTERNAL = input.externalData;
111
+ const attr = payloadUtils.getJsonPath(
112
+ testObj,
113
+ "$.context.message_id",
114
+ );
115
+
116
+ const validate = validations.arePresent(attr);
117
+
118
+ if (!validate) {
119
+ return [
120
+ {
121
+ valid: false,
122
+ code: 30000,
123
+ description: `- **condition Attri_Required_4_CONTEXT_MESSAGE_ID**: $.context.message_id must be present in the payload`,
124
+ },
125
+ ];
126
+ }
127
+
128
+ delete testObj._EXTERNAL;
129
+ }
130
+ return [{ valid: valid, code: 200 }, ...subResults];
131
+ }
132
+ function Attri_Required_5_CONTEXT_VERSION(
133
+ input: validationInput,
134
+ ): validationOutput {
135
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
136
+ let subResults: validationOutput = [];
137
+ let valid = true;
138
+ for (const testObj of scope) {
139
+ testObj._EXTERNAL = input.externalData;
140
+ const attr = payloadUtils.getJsonPath(
141
+ testObj,
142
+ "$.context.version",
143
+ );
144
+
145
+ const validate = validations.arePresent(attr);
146
+
147
+ if (!validate) {
148
+ return [
149
+ {
150
+ valid: false,
151
+ code: 30000,
152
+ description: `- **condition Attri_Required_5_CONTEXT_VERSION**: $.context.version must be present in the payload`,
153
+ },
154
+ ];
155
+ }
156
+
157
+ delete testObj._EXTERNAL;
158
+ }
159
+ return [{ valid: valid, code: 200 }, ...subResults];
160
+ }
161
+ function Attri_Required_6_CONTEXT_BAP_URI(
162
+ input: validationInput,
163
+ ): validationOutput {
164
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
165
+ let subResults: validationOutput = [];
166
+ let valid = true;
167
+ for (const testObj of scope) {
168
+ testObj._EXTERNAL = input.externalData;
169
+ const attr = payloadUtils.getJsonPath(
170
+ testObj,
171
+ "$.context.bap_uri",
172
+ );
173
+
174
+ const validate = validations.arePresent(attr);
175
+
176
+ if (!validate) {
177
+ return [
178
+ {
179
+ valid: false,
180
+ code: 30000,
181
+ description: `- **condition Attri_Required_6_CONTEXT_BAP_URI**: $.context.bap_uri must be present in the payload`,
182
+ },
183
+ ];
184
+ }
185
+
186
+ delete testObj._EXTERNAL;
187
+ }
188
+ return [{ valid: valid, code: 200 }, ...subResults];
189
+ }
190
+ function Attri_Required_7_CONTEXT_TTL(
191
+ input: validationInput,
192
+ ): validationOutput {
193
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
194
+ let subResults: validationOutput = [];
195
+ let valid = true;
196
+ for (const testObj of scope) {
197
+ testObj._EXTERNAL = input.externalData;
198
+ const attr = payloadUtils.getJsonPath(testObj, "$.context.ttl");
199
+
200
+ const validate = validations.arePresent(attr);
201
+
202
+ if (!validate) {
203
+ return [
204
+ {
205
+ valid: false,
206
+ code: 30000,
207
+ description: `- **condition Attri_Required_7_CONTEXT_TTL**: $.context.ttl must be present in the payload`,
208
+ },
209
+ ];
210
+ }
211
+
212
+ delete testObj._EXTERNAL;
213
+ }
214
+ return [{ valid: valid, code: 200 }, ...subResults];
215
+ }
216
+ function Attri_Required_8_CONTEXT_BPP_ID(
217
+ input: validationInput,
218
+ ): validationOutput {
219
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
220
+ let subResults: validationOutput = [];
221
+ let valid = true;
222
+ for (const testObj of scope) {
223
+ testObj._EXTERNAL = input.externalData;
224
+ const attr = payloadUtils.getJsonPath(
225
+ testObj,
226
+ "$.context.bpp_id",
227
+ );
228
+
229
+ const validate = validations.arePresent(attr);
230
+
231
+ if (!validate) {
232
+ return [
233
+ {
234
+ valid: false,
235
+ code: 30000,
236
+ description: `- **condition Attri_Required_8_CONTEXT_BPP_ID**: $.context.bpp_id must be present in the payload`,
237
+ },
238
+ ];
239
+ }
240
+
241
+ delete testObj._EXTERNAL;
242
+ }
243
+ return [{ valid: valid, code: 200 }, ...subResults];
244
+ }
245
+ function Attri_Required_9_CONTEXT_BPP_URI(
246
+ input: validationInput,
247
+ ): validationOutput {
248
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
249
+ let subResults: validationOutput = [];
250
+ let valid = true;
251
+ for (const testObj of scope) {
252
+ testObj._EXTERNAL = input.externalData;
253
+ const attr = payloadUtils.getJsonPath(
254
+ testObj,
255
+ "$.context.bpp_uri",
256
+ );
257
+
258
+ const validate = validations.arePresent(attr);
259
+
260
+ if (!validate) {
261
+ return [
262
+ {
263
+ valid: false,
264
+ code: 30000,
265
+ description: `- **condition Attri_Required_9_CONTEXT_BPP_URI**: $.context.bpp_uri must be present in the payload`,
266
+ },
267
+ ];
268
+ }
269
+
270
+ delete testObj._EXTERNAL;
271
+ }
272
+ return [{ valid: valid, code: 200 }, ...subResults];
273
+ }
274
+ function Attri_Required_10_ITEMS_ID(
275
+ input: validationInput,
276
+ ): validationOutput {
277
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
278
+ let subResults: validationOutput = [];
279
+ let valid = true;
280
+ for (const testObj of scope) {
281
+ testObj._EXTERNAL = input.externalData;
282
+ const attr = payloadUtils.getJsonPath(
283
+ testObj,
284
+ "$.message.order.items[*].id",
285
+ );
286
+
287
+ const validate = validations.arePresent(attr);
288
+
289
+ if (!validate) {
290
+ return [
291
+ {
292
+ valid: false,
293
+ code: 30000,
294
+ description: `- **condition Attri_Required_10_ITEMS_ID**: $.message.order.items[*].id must be present in the payload`,
295
+ },
296
+ ];
297
+ }
298
+
299
+ delete testObj._EXTERNAL;
300
+ }
301
+ return [{ valid: valid, code: 200 }, ...subResults];
302
+ }
303
+ function Attri_Required_11_SELECTED_COUNT(
304
+ input: validationInput,
305
+ ): validationOutput {
306
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
307
+ let subResults: validationOutput = [];
308
+ let valid = true;
309
+ for (const testObj of scope) {
310
+ testObj._EXTERNAL = input.externalData;
311
+ const attr = payloadUtils.getJsonPath(
312
+ testObj,
313
+ "$.message.order.items[*].quantity.selected.count",
314
+ );
315
+
316
+ const validate = validations.arePresent(attr);
317
+
318
+ if (!validate) {
319
+ return [
320
+ {
321
+ valid: false,
322
+ code: 30000,
323
+ description: `- **condition Attri_Required_11_SELECTED_COUNT**: $.message.order.items[*].quantity.selected.count must be present in the payload`,
324
+ },
325
+ ];
326
+ }
327
+
328
+ delete testObj._EXTERNAL;
329
+ }
330
+ return [{ valid: valid, code: 200 }, ...subResults];
331
+ }
332
+ function Attri_Required_12_PROVIDER_ID(
333
+ input: validationInput,
334
+ ): validationOutput {
335
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
336
+ let subResults: validationOutput = [];
337
+ let valid = true;
338
+ for (const testObj of scope) {
339
+ testObj._EXTERNAL = input.externalData;
340
+ const attr = payloadUtils.getJsonPath(
341
+ testObj,
342
+ "$.message.order.provider.id",
343
+ );
344
+
345
+ const validate = validations.arePresent(attr);
346
+
347
+ if (!validate) {
348
+ return [
349
+ {
350
+ valid: false,
351
+ code: 30000,
352
+ description: `- **condition Attri_Required_12_PROVIDER_ID**: $.message.order.provider.id must be present in the payload`,
353
+ },
354
+ ];
355
+ }
356
+
357
+ delete testObj._EXTERNAL;
358
+ }
359
+ return [{ valid: valid, code: 200 }, ...subResults];
360
+ }
361
+ function Enum_Required_13_CONTEXT_ACTION(
362
+ input: validationInput,
363
+ ): validationOutput {
364
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
365
+ let subResults: validationOutput = [];
366
+ let valid = true;
367
+ for (const testObj of scope) {
368
+ testObj._EXTERNAL = input.externalData;
369
+ const enumList = ["select"];
370
+ const enumPath = payloadUtils.getJsonPath(
371
+ testObj,
372
+ "$.context.action",
373
+ );
374
+
375
+ const validate =
376
+ validations.allIn(enumPath, enumList) &&
377
+ validations.arePresent(enumPath);
378
+
379
+ if (!validate) {
380
+ return [
381
+ {
382
+ valid: false,
383
+ code: 30000,
384
+ description: `- **condition Enum_Required_13_CONTEXT_ACTION**: all of the following sub conditions must be met:
385
+
386
+ - **condition Enum_Required_13_CONTEXT_ACTION.1**: every element of $.context.action must be in ["select"]
387
+ - **condition Enum_Required_13_CONTEXT_ACTION.2**: $.context.action must be present in the payload`,
388
+ },
389
+ ];
390
+ }
391
+
392
+ delete testObj._EXTERNAL;
393
+ }
394
+ return [{ valid: valid, code: 200 }, ...subResults];
395
+ }
396
+ function Enum_Required_14_COUNTRY_CODE(
397
+ input: validationInput,
398
+ ): validationOutput {
399
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
400
+ let subResults: validationOutput = [];
401
+ let valid = true;
402
+ for (const testObj of scope) {
403
+ testObj._EXTERNAL = input.externalData;
404
+ const enumList = ["IND"];
405
+ const enumPath = payloadUtils.getJsonPath(
406
+ testObj,
407
+ "$.context.location.country.code",
408
+ );
409
+
410
+ const validate =
411
+ validations.allIn(enumPath, enumList) &&
412
+ validations.arePresent(enumPath);
413
+
414
+ if (!validate) {
415
+ return [
416
+ {
417
+ valid: false,
418
+ code: 30000,
419
+ description: `- **condition Enum_Required_14_COUNTRY_CODE**: all of the following sub conditions must be met:
420
+
421
+ - **condition Enum_Required_14_COUNTRY_CODE.1**: every element of $.context.location.country.code must be in ["IND"]
422
+ - **condition Enum_Required_14_COUNTRY_CODE.2**: $.context.location.country.code must be present in the payload`,
423
+ },
424
+ ];
425
+ }
426
+
427
+ delete testObj._EXTERNAL;
428
+ }
429
+ return [{ valid: valid, code: 200 }, ...subResults];
430
+ }
431
+ function Enum_Required_15_CITY_CODE(
432
+ input: validationInput,
433
+ ): validationOutput {
434
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
435
+ let subResults: validationOutput = [];
436
+ let valid = true;
437
+ for (const testObj of scope) {
438
+ testObj._EXTERNAL = input.externalData;
439
+ const enumPath = payloadUtils.getJsonPath(
440
+ testObj,
441
+ "$.context.location.city.code",
442
+ );
443
+
444
+ const validate = validations.arePresent(enumPath);
445
+
446
+ if (!validate) {
447
+ return [
448
+ {
449
+ valid: false,
450
+ code: 30000,
451
+ description: `- **condition Enum_Required_15_CITY_CODE**: $.context.location.city.code must be present in the payload`,
452
+ },
453
+ ];
454
+ }
455
+
456
+ delete testObj._EXTERNAL;
457
+ }
458
+ return [{ valid: valid, code: 200 }, ...subResults];
459
+ }
460
+ function Enum_Required_16_CONTEXT_DOMAIN(
461
+ input: validationInput,
462
+ ): validationOutput {
463
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
464
+ let subResults: validationOutput = [];
465
+ let valid = true;
466
+ for (const testObj of scope) {
467
+ testObj._EXTERNAL = input.externalData;
468
+ const enumList = ["ONDC:TRV11"];
469
+ const enumPath = payloadUtils.getJsonPath(
470
+ testObj,
471
+ "$.context.domain",
472
+ );
473
+
474
+ const validate =
475
+ validations.allIn(enumPath, enumList) &&
476
+ validations.arePresent(enumPath);
477
+
478
+ if (!validate) {
479
+ return [
480
+ {
481
+ valid: false,
482
+ code: 30000,
483
+ description: `- **condition Enum_Required_16_CONTEXT_DOMAIN**: all of the following sub conditions must be met:
484
+
485
+ - **condition Enum_Required_16_CONTEXT_DOMAIN.1**: every element of $.context.domain must be in ["ONDC:TRV11"]
486
+ - **condition Enum_Required_16_CONTEXT_DOMAIN.2**: $.context.domain must be present in the payload`,
487
+ },
488
+ ];
489
+ }
490
+
491
+ delete testObj._EXTERNAL;
492
+ }
493
+ return [{ valid: valid, code: 200 }, ...subResults];
494
+ }
495
+ function Enum_Required_17_DESCRIPTOR_CODE(
496
+ input: validationInput,
497
+ ): validationOutput {
498
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
499
+ let subResults: validationOutput = [];
500
+ let valid = true;
501
+ for (const testObj of scope) {
502
+ testObj._EXTERNAL = input.externalData;
503
+ const enumList = ["SJT", "SFSJT", "RJT", "PASS"];
504
+ const enumPath = payloadUtils.getJsonPath(
505
+ testObj,
506
+ "$.message.order.items[*].descriptor.code",
507
+ );
508
+
509
+ const skipCheck = !validations.arePresent(enumPath);
510
+ if (skipCheck) continue;
511
+
512
+ const validate = validations.allIn(enumPath, enumList);
513
+
514
+ if (!validate) {
515
+ return [
516
+ {
517
+ valid: false,
518
+ code: 30000,
519
+ description: `- **condition Enum_Required_17_DESCRIPTOR_CODE**: every element of $.message.order.items[*].descriptor.code must be in ["SJT", "SFSJT", "RJT", "PASS"]
520
+
521
+ > Note: **Condition Enum_Required_17_DESCRIPTOR_CODE** can be skipped if the following conditions are met:
522
+ >
523
+ > - **condition B**: $.message.order.items[*].descriptor.code must **not** be present in the payload`,
524
+ },
525
+ ];
526
+ }
527
+
528
+ delete testObj._EXTERNAL;
529
+ }
530
+ return [{ valid: valid, code: 200 }, ...subResults];
531
+ }
532
+ function Enum_Required_18_VEHICLE_CATEGORY(
533
+ input: validationInput,
534
+ ): validationOutput {
535
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
536
+ let subResults: validationOutput = [];
537
+ let valid = true;
538
+ for (const testObj of scope) {
539
+ testObj._EXTERNAL = input.externalData;
540
+ const enumList = ["BUS", "METRO"];
541
+ const enumPath = payloadUtils.getJsonPath(
542
+ testObj,
543
+ "$.message.order.fulfillments[*].vehicle.category",
544
+ );
545
+
546
+ const skipCheck = !validations.arePresent(enumPath);
547
+ if (skipCheck) continue;
548
+
549
+ const validate = validations.allIn(enumPath, enumList);
550
+
551
+ if (!validate) {
552
+ return [
553
+ {
554
+ valid: false,
555
+ code: 30000,
556
+ description: `- **condition Enum_Required_18_VEHICLE_CATEGORY**: every element of $.message.order.fulfillments[*].vehicle.category must be in ["BUS", "METRO"]
557
+
558
+ > Note: **Condition Enum_Required_18_VEHICLE_CATEGORY** can be skipped if the following conditions are met:
559
+ >
560
+ > - **condition B**: $.message.order.fulfillments[*].vehicle.category must **not** be present in the payload`,
561
+ },
562
+ ];
563
+ }
564
+
565
+ delete testObj._EXTERNAL;
566
+ }
567
+ return [{ valid: valid, code: 200 }, ...subResults];
568
+ }
569
+ function Enum_Required_19_FULFILLMENTS_TYPE(
570
+ input: validationInput,
571
+ ): validationOutput {
572
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
573
+ let subResults: validationOutput = [];
574
+ let valid = true;
575
+ for (const testObj of scope) {
576
+ testObj._EXTERNAL = input.externalData;
577
+ const enumList = ["ROUTE", "TRIP"];
578
+ const enumPath = payloadUtils.getJsonPath(
579
+ testObj,
580
+ "$.message.order.fulfillments[*].type",
581
+ );
582
+
583
+ const skipCheck = !validations.arePresent(enumPath);
584
+ if (skipCheck) continue;
585
+
586
+ const validate = validations.allIn(enumPath, enumList);
587
+
588
+ if (!validate) {
589
+ return [
590
+ {
591
+ valid: false,
592
+ code: 30000,
593
+ description: `- **condition Enum_Required_19_FULFILLMENTS_TYPE**: every element of $.message.order.fulfillments[*].type must be in ["ROUTE", "TRIP"]
594
+
595
+ > Note: **Condition Enum_Required_19_FULFILLMENTS_TYPE** can be skipped if the following conditions are met:
596
+ >
597
+ > - **condition B**: $.message.order.fulfillments[*].type must **not** be present in the payload`,
598
+ },
599
+ ];
600
+ }
601
+
602
+ delete testObj._EXTERNAL;
603
+ }
604
+ return [{ valid: valid, code: 200 }, ...subResults];
605
+ }
606
+ function Enum_Required_20_FULFILLMENTS_TYPE(
607
+ input: validationInput,
608
+ ): validationOutput {
609
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
610
+ let subResults: validationOutput = [];
611
+ let valid = true;
612
+ for (const testObj of scope) {
613
+ testObj._EXTERNAL = input.externalData;
614
+ const enumList = [
615
+ "START",
616
+ "END",
617
+ "INTERMEDIATE_STOP",
618
+ "TRANSIT_STOP",
619
+ ];
620
+ const enumPath = payloadUtils.getJsonPath(
621
+ testObj,
622
+ "$.message.order.fulfillments[*].type",
623
+ );
624
+
625
+ const skipCheck = !validations.arePresent(enumPath);
626
+ if (skipCheck) continue;
627
+
628
+ const validate = validations.allIn(enumPath, enumList);
629
+
630
+ if (!validate) {
631
+ return [
632
+ {
633
+ valid: false,
634
+ code: 30000,
635
+ description: `- **condition Enum_Required_20_FULFILLMENTS_TYPE**: every element of $.message.order.fulfillments[*].type must be in ["START", "END", "INTERMEDIATE_STOP", "TRANSIT_STOP"]
636
+
637
+ > Note: **Condition Enum_Required_20_FULFILLMENTS_TYPE** can be skipped if the following conditions are met:
638
+ >
639
+ > - **condition B**: $.message.order.fulfillments[*].type must **not** be present in the payload`,
640
+ },
641
+ ];
642
+ }
643
+
644
+ delete testObj._EXTERNAL;
645
+ }
646
+ return [{ valid: valid, code: 200 }, ...subResults];
647
+ }
648
+ function Enum_Required_21_AUTHORIZATION_TYPE(
649
+ input: validationInput,
650
+ ): validationOutput {
651
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
652
+ let subResults: validationOutput = [];
653
+ let valid = true;
654
+ for (const testObj of scope) {
655
+ testObj._EXTERNAL = input.externalData;
656
+ const enumList = ["QR"];
657
+ const enumPath = payloadUtils.getJsonPath(
658
+ testObj,
659
+ "$.message.order.fulfillments[*].stops[*].authorization.type",
660
+ );
661
+
662
+ const skipCheck = !validations.arePresent(enumPath);
663
+ if (skipCheck) continue;
664
+
665
+ const validate = validations.allIn(enumPath, enumList);
666
+
667
+ if (!validate) {
668
+ return [
669
+ {
670
+ valid: false,
671
+ code: 30000,
672
+ description: `- **condition Enum_Required_21_AUTHORIZATION_TYPE**: every element of $.message.order.fulfillments[*].stops[*].authorization.type must be in ["QR"]
673
+
674
+ > Note: **Condition Enum_Required_21_AUTHORIZATION_TYPE** can be skipped if the following conditions are met:
675
+ >
676
+ > - **condition B**: $.message.order.fulfillments[*].stops[*].authorization.type must **not** be present in the payload`,
677
+ },
678
+ ];
679
+ }
680
+
681
+ delete testObj._EXTERNAL;
682
+ }
683
+ return [{ valid: valid, code: 200 }, ...subResults];
684
+ }
685
+ function Enum_Required_22_AUTHORIZATION_STATUS(
686
+ input: validationInput,
687
+ ): validationOutput {
688
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
689
+ let subResults: validationOutput = [];
690
+ let valid = true;
691
+ for (const testObj of scope) {
692
+ testObj._EXTERNAL = input.externalData;
693
+ const enumList = ["UNCLAIMED", "CLAIMED"];
694
+ const enumPath = payloadUtils.getJsonPath(
695
+ testObj,
696
+ "$.message.order.fulfillments[*].stops[*].authorization.status",
697
+ );
698
+
699
+ const skipCheck = !validations.arePresent(enumPath);
700
+ if (skipCheck) continue;
701
+
702
+ const validate = validations.allIn(enumPath, enumList);
703
+
704
+ if (!validate) {
705
+ return [
706
+ {
707
+ valid: false,
708
+ code: 30000,
709
+ description: `- **condition Enum_Required_22_AUTHORIZATION_STATUS**: every element of $.message.order.fulfillments[*].stops[*].authorization.status must be in ["UNCLAIMED", "CLAIMED"]
710
+
711
+ > Note: **Condition Enum_Required_22_AUTHORIZATION_STATUS** can be skipped if the following conditions are met:
712
+ >
713
+ > - **condition B**: $.message.order.fulfillments[*].stops[*].authorization.status must **not** be present in the payload`,
714
+ },
715
+ ];
716
+ }
717
+
718
+ delete testObj._EXTERNAL;
719
+ }
720
+ return [{ valid: valid, code: 200 }, ...subResults];
721
+ }
722
+ function Enum_Required_23_ORDER_STATUS(
723
+ input: validationInput,
724
+ ): validationOutput {
725
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
726
+ let subResults: validationOutput = [];
727
+ let valid = true;
728
+ for (const testObj of scope) {
729
+ testObj._EXTERNAL = input.externalData;
730
+ const enumList = [
731
+ "SOFT_CANCEL",
732
+ "CONFIRM_CANCEL",
733
+ "ACTIVE",
734
+ "COMPLETE",
735
+ "CANCELLED",
736
+ ];
737
+ const enumPath = payloadUtils.getJsonPath(
738
+ testObj,
739
+ "$.message.order.status",
740
+ );
741
+
742
+ const skipCheck = !validations.arePresent(enumPath);
743
+ if (skipCheck) continue;
744
+
745
+ const validate = validations.allIn(enumPath, enumList);
746
+
747
+ if (!validate) {
748
+ return [
749
+ {
750
+ valid: false,
751
+ code: 30000,
752
+ description: `- **condition Enum_Required_23_ORDER_STATUS**: every element of $.message.order.status must be in ["SOFT_CANCEL", "CONFIRM_CANCEL", "ACTIVE", "COMPLETE", "CANCELLED"]
753
+
754
+ > Note: **Condition Enum_Required_23_ORDER_STATUS** can be skipped if the following conditions are met:
755
+ >
756
+ > - **condition B**: $.message.order.status must **not** be present in the payload`,
757
+ },
758
+ ];
759
+ }
760
+
761
+ delete testObj._EXTERNAL;
762
+ }
763
+ return [{ valid: valid, code: 200 }, ...subResults];
764
+ }
765
+ function Enum_Required_24_BREAKUP_TITLE(
766
+ input: validationInput,
767
+ ): validationOutput {
768
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
769
+ let subResults: validationOutput = [];
770
+ let valid = true;
771
+ for (const testObj of scope) {
772
+ testObj._EXTERNAL = input.externalData;
773
+ const enumList = [
774
+ "BASE_PRICE",
775
+ "REFUND",
776
+ "CANCELLATION_CHARGES",
777
+ "OFFER",
778
+ "TOLL",
779
+ ];
780
+ const enumPath = payloadUtils.getJsonPath(
781
+ testObj,
782
+ "$.message.order.quote.breakup[*].title",
783
+ );
784
+
785
+ const skipCheck = !validations.arePresent(enumPath);
786
+ if (skipCheck) continue;
787
+
788
+ const validate = validations.allIn(enumPath, enumList);
789
+
790
+ if (!validate) {
791
+ return [
792
+ {
793
+ valid: false,
794
+ code: 30000,
795
+ description: `- **condition Enum_Required_24_BREAKUP_TITLE**: every element of $.message.order.quote.breakup[*].title must be in ["BASE_PRICE", "REFUND", "CANCELLATION_CHARGES", "OFFER", "TOLL"]
796
+
797
+ > Note: **Condition Enum_Required_24_BREAKUP_TITLE** can be skipped if the following conditions are met:
798
+ >
799
+ > - **condition B**: $.message.order.quote.breakup[*].title must **not** be present in the payload`,
800
+ },
801
+ ];
802
+ }
803
+
804
+ delete testObj._EXTERNAL;
805
+ }
806
+ return [{ valid: valid, code: 200 }, ...subResults];
807
+ }
808
+ function ROUTE_INFO_Tag_Required_25_DESCRIPTOR_CODE(
809
+ input: validationInput,
810
+ ): validationOutput {
811
+ const scope = payloadUtils.getJsonPath(input.payload, "$");
812
+ let subResults: validationOutput = [];
813
+ let valid = true;
814
+ for (const testObj of scope) {
815
+ testObj._EXTERNAL = input.externalData;
816
+ const validTags = ["ROUTE_INFO", "TICKET_INFO", "TRIP_DETAILS"];
817
+ const tagPath = payloadUtils.getJsonPath(
818
+ testObj,
819
+ "$.message.order.fulfillments[*].tags[*].descriptor.code",
820
+ );
821
+
822
+ const skipCheck = !validations.arePresent(tagPath);
823
+ if (skipCheck) continue;
824
+
825
+ const validate = validations.allIn(tagPath, validTags);
826
+
827
+ if (!validate) {
828
+ return [
829
+ {
830
+ valid: false,
831
+ code: 30000,
832
+ description: `- **condition ROUTE_INFO_Tag_Required_25_DESCRIPTOR_CODE**: every element of $.message.order.fulfillments[*].tags[*].descriptor.code must be in ["ROUTE_INFO", "TICKET_INFO", "TRIP_DETAILS"]
833
+
834
+ > Note: **Condition ROUTE_INFO_Tag_Required_25_DESCRIPTOR_CODE** can be skipped if the following conditions are met:
835
+ >
836
+ > - **condition B**: $.message.order.fulfillments[*].tags[*].descriptor.code must **not** be present in the payload`,
837
+ },
838
+ ];
839
+ }
840
+
841
+ delete testObj._EXTERNAL;
842
+ }
843
+ return [{ valid: valid, code: 200 }, ...subResults];
844
+ }
845
+ function validate_tag_0_ROUTE_INFO(
846
+ input: validationInput,
847
+ ): validationOutput {
848
+ const scope = payloadUtils.getJsonPath(
849
+ input.payload,
850
+ "$.message.order.fulfillments[*].tags[?(@.descriptor.code=='ROUTE_INFO')]",
851
+ );
852
+ let subResults: validationOutput = [];
853
+ let valid = true;
854
+ for (const testObj of scope) {
855
+ testObj._EXTERNAL = input.externalData;
856
+ const subTags = payloadUtils.getJsonPath(
857
+ testObj,
858
+ "$.list[*].descriptor.code",
859
+ );
860
+ const validValues = ["ROUTE_ID", "ROUTE_DIRECTION"];
861
+
862
+ const validate = validations.allIn(subTags, validValues);
863
+
864
+ if (!validate) {
865
+ return [
866
+ {
867
+ valid: false,
868
+ code: 30000,
869
+ description: `- **condition validate_tag_0_ROUTE_INFO**: every element of $.message.order.fulfillments[*].tags[?(@.descriptor.code=='ROUTE_INFO')].list[*].descriptor.code must be in ["ROUTE_ID", "ROUTE_DIRECTION"]`,
870
+ },
871
+ ];
872
+ }
873
+
874
+ delete testObj._EXTERNAL;
875
+ }
876
+ return [{ valid: valid, code: 200 }, ...subResults];
877
+ }
878
+ function validate_tag_0_TICKET_INFO(
879
+ input: validationInput,
880
+ ): validationOutput {
881
+ const scope = payloadUtils.getJsonPath(
882
+ input.payload,
883
+ "$.message.order.fulfillments[*].tags[?(@.descriptor.code=='TICKET_INFO')]",
884
+ );
885
+ let subResults: validationOutput = [];
886
+ let valid = true;
887
+ for (const testObj of scope) {
888
+ testObj._EXTERNAL = input.externalData;
889
+ const subTags = payloadUtils.getJsonPath(
890
+ testObj,
891
+ "$.list[*].descriptor.code",
892
+ );
893
+ const validValues = ["NUMBER"];
894
+
895
+ const validate = validations.allIn(subTags, validValues);
896
+
897
+ if (!validate) {
898
+ return [
899
+ {
900
+ valid: false,
901
+ code: 30000,
902
+ description: `- **condition validate_tag_0_TICKET_INFO**: every element of $.message.order.fulfillments[*].tags[?(@.descriptor.code=='TICKET_INFO')].list[*].descriptor.code must be in ["NUMBER"]`,
903
+ },
904
+ ];
905
+ }
906
+
907
+ delete testObj._EXTERNAL;
908
+ }
909
+ return [{ valid: valid, code: 200 }, ...subResults];
910
+ }
911
+ function validate_tag_0_TRIP_DETAILS(
912
+ input: validationInput,
913
+ ): validationOutput {
914
+ const scope = payloadUtils.getJsonPath(
915
+ input.payload,
916
+ "$.message.order.fulfillments[*].tags[?(@.descriptor.code=='TRIP_DETAILS')]",
917
+ );
918
+ let subResults: validationOutput = [];
919
+ let valid = true;
920
+ for (const testObj of scope) {
921
+ testObj._EXTERNAL = input.externalData;
922
+ const subTags = payloadUtils.getJsonPath(
923
+ testObj,
924
+ "$.list[*].descriptor.code",
925
+ );
926
+ const validValues = ["AVAILABLE_TRIPS", "UTILIZED_TRIPS"];
927
+
928
+ const validate = validations.allIn(subTags, validValues);
929
+
930
+ if (!validate) {
931
+ return [
932
+ {
933
+ valid: false,
934
+ code: 30000,
935
+ description: `- **condition validate_tag_0_TRIP_DETAILS**: every element of $.message.order.fulfillments[*].tags[?(@.descriptor.code=='TRIP_DETAILS')].list[*].descriptor.code must be in ["AVAILABLE_TRIPS", "UTILIZED_TRIPS"]`,
936
+ },
937
+ ];
938
+ }
939
+
940
+ delete testObj._EXTERNAL;
941
+ }
942
+ return [{ valid: valid, code: 200 }, ...subResults];
943
+ }
944
+
945
+ const testFunctions: testFunctionArray = [
946
+ Attri_Required_1_CONTEXT_TIMESTAMP,
947
+ Attri_Required_2_CONTEXT_BAP_ID,
948
+ Attri_Required_3_CONTEXT_TRANSACTION_ID,
949
+ Attri_Required_4_CONTEXT_MESSAGE_ID,
950
+ Attri_Required_5_CONTEXT_VERSION,
951
+ Attri_Required_6_CONTEXT_BAP_URI,
952
+ Attri_Required_7_CONTEXT_TTL,
953
+ Attri_Required_8_CONTEXT_BPP_ID,
954
+ Attri_Required_9_CONTEXT_BPP_URI,
955
+ Attri_Required_10_ITEMS_ID,
956
+ Attri_Required_11_SELECTED_COUNT,
957
+ Attri_Required_12_PROVIDER_ID,
958
+ Enum_Required_13_CONTEXT_ACTION,
959
+ Enum_Required_14_COUNTRY_CODE,
960
+ Enum_Required_15_CITY_CODE,
961
+ Enum_Required_16_CONTEXT_DOMAIN,
962
+ Enum_Required_17_DESCRIPTOR_CODE,
963
+ Enum_Required_18_VEHICLE_CATEGORY,
964
+ Enum_Required_19_FULFILLMENTS_TYPE,
965
+ Enum_Required_20_FULFILLMENTS_TYPE,
966
+ Enum_Required_21_AUTHORIZATION_TYPE,
967
+ Enum_Required_22_AUTHORIZATION_STATUS,
968
+ Enum_Required_23_ORDER_STATUS,
969
+ Enum_Required_24_BREAKUP_TITLE,
970
+ ROUTE_INFO_Tag_Required_25_DESCRIPTOR_CODE,
971
+ validate_tag_0_ROUTE_INFO,
972
+ validate_tag_0_TICKET_INFO,
973
+ validate_tag_0_TRIP_DETAILS,
974
+ ];
975
+
976
+ let invalidResults: validationOutput = [];
977
+ for (const fn of testFunctions) {
978
+ const subResult = fn(input);
979
+ // .filter(r => !r.valid);
980
+ invalidResults = [...invalidResults, ...subResult];
981
+ if (!input.config.runAllValidations && invalidResults.length > 0) {
982
+ return invalidResults;
983
+ }
984
+ }
985
+ if (invalidResults.length > 0) {
986
+ // return invalidResults;
987
+ subResults = invalidResults;
988
+ valid = subResults.every((r) => r.valid);
989
+ }
990
+
991
+ delete testObj._EXTERNAL;
992
+ }
993
+ return [{ valid: valid, code: 200 }, ...subResults];
994
+ }