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,19 @@
1
+ export const LOGICAL_OPERATORS = ["&&", "||"];
2
+ export const COMPARISON_OPERATORS = ["==", "!=", ">", ">=", "<", "<="];
3
+ export const ARITHMETIC_OPERATORS = ["+", "-", "*", "/"];
4
+ export const UNARY_OPERATORS = ["!"];
5
+
6
+ export const PREDEFINED_CONDITIONS = [
7
+ "ALL_IN",
8
+ "ANY_IN",
9
+ "NONE_IN",
10
+ "ARE_UNIQUE",
11
+ "FOLLOW_REGEX",
12
+ ];
13
+
14
+ export const OPERATORS = [
15
+ ...LOGICAL_OPERATORS,
16
+ ...COMPARISON_OPERATORS,
17
+ ...ARITHMETIC_OPERATORS,
18
+ ...UNARY_OPERATORS,
19
+ ];
@@ -0,0 +1,81 @@
1
+ export enum TestObjectSyntax {
2
+ Name = "_NAME_",
3
+ Return = "_RETURN_",
4
+ Scope = "_SCOPE_",
5
+ Continue = "_CONTINUE_",
6
+ ErrorCode = "_ERROR_CODE_",
7
+ SuccessCode = "_SUCCESS_CODE_",
8
+ }
9
+
10
+ export const ExternalDataSyntax = "_EXTERNAL";
11
+
12
+ export enum ConfigSyntax {
13
+ Tests = "_TESTS_",
14
+ SessionData = "_SESSION_DATA_",
15
+ }
16
+
17
+ export const ConfigKeyWords = [
18
+ TestObjectSyntax.Name,
19
+ TestObjectSyntax.Return,
20
+ TestObjectSyntax.Scope,
21
+ TestObjectSyntax.Continue,
22
+ TestObjectSyntax.ErrorCode,
23
+ TestObjectSyntax.SuccessCode,
24
+ ConfigSyntax.Tests,
25
+ ConfigSyntax.SessionData,
26
+ ];
27
+
28
+ // JavaScript/Node.js keywords
29
+ export const nodeReservedKeywords = new Set([
30
+ "break",
31
+ "case",
32
+ "catch",
33
+ "class",
34
+ "const",
35
+ "continue",
36
+ "debugger",
37
+ "default",
38
+ "delete",
39
+ "do",
40
+ "else",
41
+ "export",
42
+ "extends",
43
+ "finally",
44
+ "for",
45
+ "function",
46
+ "if",
47
+ "import",
48
+ "in",
49
+ "instanceof",
50
+ "let",
51
+ "new",
52
+ "return",
53
+ "super",
54
+ "switch",
55
+ "this",
56
+ "throw",
57
+ "try",
58
+ "typeof",
59
+ "var",
60
+ "void",
61
+ "while",
62
+ "with",
63
+ "yield",
64
+
65
+ // Additional Node.js/ECMAScript-specific keywords
66
+ "async",
67
+ "await",
68
+ "arguments",
69
+ "eval",
70
+ "of",
71
+
72
+ // Reserved but may not yet be used in JavaScript
73
+ "enum",
74
+ "implements",
75
+ "interface",
76
+ "package",
77
+ "private",
78
+ "protected",
79
+ "public",
80
+ "static",
81
+ ]);
package/src/example.ts ADDED
@@ -0,0 +1,25 @@
1
+ // import { readFileSync } from "fs";
2
+
3
+ // import path from "path";
4
+ // import { fileURLToPath } from "url";
5
+ // import { SupportedLanguages } from "./types/compiler-types.js";
6
+
7
+ // const __filename = fileURLToPath(import.meta.url);
8
+ // const __dirname = path.dirname(__filename);
9
+
10
+ // const main = async () => {
11
+ // const compiler = new ConfigCompiler(SupportedLanguages.Typescript);
12
+ // const buildPath = path.resolve(__dirname, "../samples/build.yaml");
13
+ // const valConfigPath = path.resolve(
14
+ // __dirname,
15
+ // "../samples/validation-config.json"
16
+ // );
17
+ // const buildYaml = readFileSync(buildPath, "utf-8");
18
+ // const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
19
+ // await compiler.initialize(buildYaml);
20
+ // await compiler.generateCode(valConfig);
21
+ // };
22
+
23
+ // (async () => {
24
+ // await main();
25
+ // })();
@@ -0,0 +1,122 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ import { BUID_TYPE } from "../types/build.js";
3
+ import { loadAndDereferenceYaml } from "../utils/config-utils/yaml.js";
4
+ import { SchemaExtactionService } from "../services/schema-service.js";
5
+ import { ErrorDefinition } from "../types/error-codes.js";
6
+ import { ValidationConfig } from "../types/config-types.js";
7
+ import logger from "../utils/logger.js";
8
+ import { SupportedLanguages } from "../types/compiler-types.js";
9
+
10
+ import { TypescriptGenerator } from "./generators/typescript/ts-generator.js";
11
+ import { ConfigValidator } from "./validators/config-validator.js";
12
+ import { writeAndFormatCode } from "../utils/fs-utils.js";
13
+ import { readFileSync } from "fs";
14
+ import path from "path";
15
+ import Mustache from "mustache";
16
+
17
+ type CodeGeneratorConfig = {
18
+ removeRequiredfromSchema: boolean;
19
+ removeEnumsfromSchema: boolean;
20
+ };
21
+
22
+ const defaultConfig: CodeGeneratorConfig = {
23
+ removeRequiredfromSchema: true,
24
+ removeEnumsfromSchema: true,
25
+ };
26
+
27
+ export class ConfigCompiler {
28
+ buildData: BUID_TYPE | undefined;
29
+ jsonSchemas: Record<string, JSONSchema7> | undefined;
30
+ possibleJsonPaths: Record<string, string[]> | undefined;
31
+ errorDefinitions: ErrorDefinition[] | undefined;
32
+ language: SupportedLanguages;
33
+ private SchemaExtactionService: SchemaExtactionService;
34
+ constructor(language: SupportedLanguages) {
35
+ this.language = language;
36
+ this.SchemaExtactionService = new SchemaExtactionService();
37
+ }
38
+ // 1. extract build, create schemas , extract possible paths , extract errorcodes
39
+ initialize = async (
40
+ buildYaml: string,
41
+ generatorConfig: Partial<CodeGeneratorConfig> = {}
42
+ ) => {
43
+ const finalConfig = { ...defaultConfig, ...generatorConfig };
44
+ this.buildData = await loadAndDereferenceYaml<BUID_TYPE>(buildYaml);
45
+ this.jsonSchemas = await this.SchemaExtactionService.extractSchemas(
46
+ this.buildData,
47
+ finalConfig.removeRequiredfromSchema,
48
+ finalConfig.removeEnumsfromSchema
49
+ );
50
+ this.possibleJsonPaths = this.SchemaExtactionService.extractPossiblePaths(
51
+ this.jsonSchemas
52
+ );
53
+ const errors = this.buildData["x-errorcodes"];
54
+ this.errorDefinitions = errors.code;
55
+ };
56
+
57
+ performValidations = async (valConfig: ValidationConfig) => {
58
+ try {
59
+ if (!this.buildData) throw new Error("Build data not initialized");
60
+ if (!this.jsonSchemas) throw new Error("Schemas not initialized");
61
+ if (!this.possibleJsonPaths)
62
+ throw new Error("Possible paths not initialized");
63
+ if (!this.errorDefinitions)
64
+ throw new Error("Error definitions not initialized");
65
+
66
+ await new ConfigValidator(
67
+ "",
68
+ valConfig,
69
+ this.possibleJsonPaths,
70
+ this.errorDefinitions
71
+ ).validate();
72
+ } catch (e) {
73
+ logger.error(e);
74
+ throw new Error("Validation failed");
75
+ }
76
+ };
77
+
78
+ generateCode = async (valConfig: ValidationConfig) => {
79
+ await this.performValidations(valConfig);
80
+ // Generate code based on the language
81
+ switch (this.language) {
82
+ case SupportedLanguages.Typescript:
83
+ await new TypescriptGenerator(
84
+ valConfig,
85
+ this.errorDefinitions ?? [],
86
+ "./generated/L1-validations"
87
+ ).generateCode();
88
+ break;
89
+ default:
90
+ throw new Error("Language not supported");
91
+ }
92
+ };
93
+
94
+ generateL0Schema = async () => {
95
+ if (!this.jsonSchemas) {
96
+ throw new Error("Schemas not initialized");
97
+ }
98
+
99
+ for (const schema in this.jsonSchemas) {
100
+ const json = this.jsonSchemas[schema];
101
+ writeAndFormatCode(
102
+ `./generated/L0-schemas`,
103
+ `${schema}.ts`,
104
+ `export const ${schema} = ${JSON.stringify(json, null, 2)}`,
105
+ "typescript"
106
+ );
107
+ }
108
+
109
+ const actions = Object.keys(this.jsonSchemas).map((schema) => {
110
+ return {
111
+ action: schema,
112
+ };
113
+ });
114
+ const template = readFileSync(
115
+ "/Users/rudranshsinghal/ondc/automation-utility/official-code/code-generator/src/generator/generators/typescript/templates/schema-template.mustache",
116
+ "utf-8"
117
+ );
118
+ console.log(actions);
119
+ const l0 = Mustache.render(template, { actions });
120
+ writeAndFormatCode(`./generated/L0-schemas`, `index.ts`, l0, "typescript");
121
+ };
122
+ }
@@ -0,0 +1,29 @@
1
+ import { ValidationConfig } from "../../../types/config-types";
2
+ import { ErrorDefinition } from "../../../types/error-codes";
3
+
4
+ /*
5
+ 1. generate code for session_data
6
+ 1. a function take in payload and update the session_data in cache
7
+ 2. get function which returns the session_data object
8
+ 2. generate code for test-objects
9
+ 1. single test object generation
10
+ 1. handle nested
11
+ 2. combine all the tests
12
+ */
13
+ export abstract class CodeGenerator {
14
+ validationConfig: ValidationConfig;
15
+ rootPath: string;
16
+ errorCodes: ErrorDefinition[];
17
+ constructor(
18
+ validationConfig: ValidationConfig,
19
+ errorCodes: ErrorDefinition[],
20
+ rootPath = "./"
21
+ ) {
22
+ this.validationConfig = validationConfig;
23
+ this.rootPath = rootPath;
24
+ this.errorCodes = errorCodes;
25
+ }
26
+ abstract generateSessionDataCode(): Promise<void>;
27
+ abstract generateValidationCode(): Promise<void>;
28
+ abstract generateCode(): Promise<void>;
29
+ }
@@ -0,0 +1,43 @@
1
+ import { CompileToMarkdown } from "../../../services/return-complier/ast-functions/compile-to-markdown.js";
2
+ import { buildAstFromInput } from "../../../services/return-complier/combined.js";
3
+ import { TestObject } from "../../../types/config-types.js";
4
+ import Mustache from "mustache";
5
+ import {
6
+ addBlockquoteToMarkdown,
7
+ addTabToMarkdown,
8
+ ConvertArrayToStringsInTestObject,
9
+ } from "../../../utils/general-utils/string-utils.js";
10
+
11
+ export function markdownMessageGenerator(
12
+ returnInput: string,
13
+ variableValues: TestObject,
14
+ startingPointer: string,
15
+ skipInput?: string[]
16
+ ) {
17
+ const ast = buildAstFromInput(returnInput);
18
+ const returnTemplate = CompileToMarkdown(ast, startingPointer, 0, false);
19
+
20
+ let finalReturn = Mustache.render(
21
+ returnTemplate,
22
+ ConvertArrayToStringsInTestObject(variableValues)
23
+ );
24
+ if (skipInput) {
25
+ let skipMarkdown = `Note: **Condition ${startingPointer}** can be skipped if the following conditions are met:`;
26
+ const letters = "BCDEFGHIJKLMNOPQRSTUVWXYZ";
27
+ let index = 0;
28
+ for (const skip of skipInput) {
29
+ const skipAst = buildAstFromInput(skip);
30
+ const skipTemplate = CompileToMarkdown(skipAst, letters[index], 0, false);
31
+ const finalSkip = Mustache.render(
32
+ skipTemplate,
33
+ ConvertArrayToStringsInTestObject(variableValues)
34
+ );
35
+ skipMarkdown += `\n\n${finalSkip}`;
36
+ index++;
37
+ }
38
+ const blockSkip = addTabToMarkdown(addBlockquoteToMarkdown(skipMarkdown));
39
+ finalReturn += `\n\n${blockSkip}`;
40
+ }
41
+
42
+ return finalReturn;
43
+ }
@@ -0,0 +1,76 @@
1
+ import { ConfigSyntax, TestObjectSyntax } from "../../../constants/syntax.js";
2
+ import { TestObject } from "../../../types/config-types.js";
3
+ import { CodeGenerator } from "../classes/abstract-generator.js";
4
+ import { markdownMessageGenerator } from "./markdown-message-generator.js";
5
+ import { writeFileWithFsExtra } from "../../../utils/fs-utils.js";
6
+ import { marked } from "marked";
7
+
8
+ import Mustache from "mustache";
9
+
10
+ import { readFileSync } from "fs";
11
+ import path from "path";
12
+ import { fileURLToPath } from "url";
13
+ import { addTabToMarkdown } from "../../../utils/general-utils/string-utils.js";
14
+
15
+ const __filename = fileURLToPath(import.meta.url);
16
+ const __dirname = path.dirname(__filename);
17
+ export class MarkdownDocGenerator extends CodeGenerator {
18
+ generateSessionDataCode(): Promise<void> {
19
+ throw new Error("Method not implemented.");
20
+ }
21
+ generateValidationCode = async () => {
22
+ const testConfig = this.validationConfig[ConfigSyntax.Tests];
23
+ let finalMarkdown = "";
24
+ for (const key in testConfig) {
25
+ const testObjects = testConfig[key];
26
+ const betaConfig = {
27
+ [TestObjectSyntax.Name]: key,
28
+ [TestObjectSyntax.Return]: testObjects,
29
+ };
30
+ const md = this.generateMarkdownForTest(betaConfig);
31
+ finalMarkdown += `\n\n${md}`;
32
+ }
33
+ const cssData = readFileSync(
34
+ path.resolve(__dirname, "./templates/style.css"),
35
+ "utf-8"
36
+ );
37
+ const htmlTemplate = readFileSync(
38
+ path.resolve(__dirname, "./templates/index.mustache"),
39
+ "utf-8"
40
+ );
41
+ writeFileWithFsExtra(this.rootPath, "./readme.md", finalMarkdown);
42
+ writeFileWithFsExtra(
43
+ this.rootPath,
44
+ "./page/index.html",
45
+ Mustache.render(htmlTemplate, {
46
+ content: await this.generateHtmlCode(finalMarkdown),
47
+ })
48
+ );
49
+ writeFileWithFsExtra(this.rootPath, "./page/style.css", cssData);
50
+ };
51
+ generateCode = async () => {
52
+ await this.generateValidationCode();
53
+ };
54
+
55
+ generateMarkdownForTest = (testObject: TestObject): string => {
56
+ const ret = testObject[TestObjectSyntax.Return];
57
+ if (typeof ret === "string") {
58
+ const skip = testObject[TestObjectSyntax.Continue];
59
+ return markdownMessageGenerator(
60
+ ret,
61
+ testObject,
62
+ testObject[TestObjectSyntax.Name],
63
+ skip ? [skip] : undefined
64
+ );
65
+ }
66
+ const subMardowns = ret.map((r) => {
67
+ return this.generateMarkdownForTest(r);
68
+ });
69
+
70
+ return `- **${testObject[TestObjectSyntax.Name]}** : All the following sub conditions must pass as per the api requirement\n\n${addTabToMarkdown(subMardowns.join("\n\n"))}`;
71
+ };
72
+
73
+ generateHtmlCode = async (markdownData: string) => {
74
+ return await marked(markdownData);
75
+ };
76
+ }
@@ -0,0 +1,36 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>API SERVICE VALIDATIONS</title>
7
+ <!-- Link to the CSS file -->
8
+ <link rel="stylesheet" href="./style.css">
9
+ </head>
10
+ <body>
11
+ <div id="content">
12
+ <h2>List of validations of api</h2>
13
+ {{{content}}}
14
+ </div>
15
+ </body>
16
+ <script>
17
+ document.addEventListener('DOMContentLoaded', function() {
18
+ // Select all list items that have a nested <ul> (collapsible items)
19
+ const collapsibleItems = document.querySelectorAll('li > ul');
20
+
21
+ collapsibleItems.forEach(function(nestedList) {
22
+ const parentLi = nestedList.parentElement;
23
+ parentLi.classList.add('collapsible', 'collapsed');
24
+
25
+ // Add click event listener to the <p> inside the list item
26
+ const clickableArea = parentLi.querySelector('p');
27
+ clickableArea.addEventListener('click', function(e) {
28
+ // Prevent click events on links inside the <p>
29
+ if (e.target.tagName !== 'A') {
30
+ parentLi.classList.toggle('collapsed');
31
+ }
32
+ });
33
+ });
34
+ });
35
+ </script>
36
+ </html>
@@ -0,0 +1,204 @@
1
+ /* RESET DEFAULT STYLES */
2
+ body, ul, li, p, blockquote {
3
+ margin: 0;
4
+ padding: 0;
5
+ }
6
+ ul, li {
7
+ list-style: none;
8
+ }
9
+
10
+ /* BODY STYLES */
11
+ body {
12
+ font-family: "Helvetica Neue", Arial, sans-serif;
13
+ background-color: #ffffff; /* Light background */
14
+ color: #333333; /* Dark text */
15
+ line-height: 1.8;
16
+ padding: 20px;
17
+ }
18
+
19
+ /* LIST STYLES */
20
+ ul {
21
+ padding-left: 20px;
22
+ }
23
+
24
+ li {
25
+ margin-bottom: 16px;
26
+ position: relative;
27
+ }
28
+
29
+ li > p {
30
+ margin-bottom: 8px;
31
+ background-color: #f7f7f7; /* Light background */
32
+ color: #555555; /* Dark text */
33
+ padding: 10px 15px;
34
+ border: 1px solid #ddd;
35
+ border-radius: 5px;
36
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
37
+ transition: background-color 0.3s, border 0.3s, box-shadow 0.3s;
38
+ }
39
+
40
+ li > p:hover {
41
+ background-color: #e8e8e8;
42
+ border-color: #1296d9; /* Updated to blue accent color */
43
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
44
+ }
45
+
46
+ /* NESTED LIST ITEMS */
47
+ ul ul li > p {
48
+ background-color: #f0f0f0; /* Slightly darker than parent */
49
+ }
50
+
51
+ ul ul li > p:hover {
52
+ background-color: #e0e0e0;
53
+ }
54
+
55
+ /* HEADINGS AND EMPHASIS TEXT */
56
+ h2,
57
+ li > p > strong {
58
+ color: #1296d9; /* Changed header color to match blue theme */
59
+ font-weight: 600;
60
+ }
61
+
62
+ li > p > strong {
63
+ font-size: 1.1em;
64
+ }
65
+
66
+ /* BLOCKQUOTE STYLES */
67
+ blockquote {
68
+ margin: 15px 0;
69
+ padding: 15px 20px;
70
+ background-color: #f7f7f7;
71
+ border-left: 5px solid #1296d9; /* Updated border to blue */
72
+ color: #555555;
73
+ font-style: italic;
74
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
75
+ transition: background-color 0.3s, border-left-color 0.3s, box-shadow 0.3s;
76
+ }
77
+
78
+ blockquote:hover {
79
+ background-color: #e8e8e8;
80
+ border-left-color: #1296d9; /* Updated hover border to blue */
81
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
82
+ }
83
+
84
+ /* BLOCKQUOTE INTERNAL ELEMENTS */
85
+ blockquote > p {
86
+ margin-bottom: 12px;
87
+ padding: 10px 15px;
88
+ background-color: #f7f7f7;
89
+ border-radius: 5px;
90
+ font-size: 1em;
91
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
92
+ transition: background-color 0.3s, border 0.3s, box-shadow 0.3s;
93
+ }
94
+
95
+ blockquote > p:hover {
96
+ background-color: #e8e8e8;
97
+ border: 1px solid #1296d9; /* Updated border to blue on hover */
98
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
99
+ }
100
+
101
+ blockquote > ul {
102
+ padding-left: 20px;
103
+ margin-top: 10px;
104
+ }
105
+
106
+ blockquote > ul > li {
107
+ margin-bottom: 16px;
108
+ position: relative;
109
+ background-color: #f7f7f7;
110
+ padding: 10px 15px;
111
+ border: 1px solid #ddd;
112
+ border-radius: 5px;
113
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
114
+ transition: background-color 0.3s, border 0.3s, box-shadow 0.3s;
115
+ }
116
+
117
+ blockquote > ul > li:hover {
118
+ background-color: #e8e8e8;
119
+ border-color: #1296d9; /* Updated border to blue on hover */
120
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
121
+ }
122
+
123
+ blockquote > ul > li > strong {
124
+ color: #1296d9; /* Changed to blue for emphasis */
125
+ font-weight: 600;
126
+ font-size: 1.1em;
127
+ }
128
+
129
+ blockquote > ul > li > ul {
130
+ padding-left: 20px;
131
+ margin-top: 8px;
132
+ }
133
+
134
+ blockquote > ul > li > ul > li {
135
+ background-color: #f0f0f0;
136
+ padding: 8px 12px;
137
+ border: 1px solid #ccc;
138
+ border-radius: 4px;
139
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
140
+ transition: background-color 0.3s, border 0.3s, box-shadow 0.3s;
141
+ }
142
+
143
+ blockquote > ul > li > ul > li:hover {
144
+ background-color: #e0e0e0;
145
+ border-color: #1296d9; /* Updated border to blue on hover */
146
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
147
+ }
148
+
149
+ /* COLLAPSIBLE INDICATORS */
150
+ li.collapsible > p {
151
+ cursor: pointer;
152
+ }
153
+
154
+ li.collapsible > p::before {
155
+ content: "▼";
156
+ display: inline-block;
157
+ margin-right: 8px;
158
+ transition: transform 0.3s, color 0.3s;
159
+ color: #1296d9; /* Updated color to blue */
160
+ }
161
+
162
+ li.collapsible.collapsed > p::before {
163
+ transform: rotate(-90deg);
164
+ }
165
+
166
+ li.collapsible > p:hover::before {
167
+ color: #1296d9; /* Lighter blue on hover */
168
+ }
169
+
170
+ /* Hide nested lists by default */
171
+ li.collapsible.collapsed > ul {
172
+ display: none;
173
+ }
174
+
175
+ /* RESPONSIVE DESIGN */
176
+ @media only screen and (max-width: 768px) {
177
+ body {
178
+ padding: 15px;
179
+ }
180
+ ul {
181
+ padding-left: 15px;
182
+ }
183
+ li > p,
184
+ blockquote > p,
185
+ blockquote > ul > li {
186
+ font-size: 0.95em;
187
+ padding: 8px 12px;
188
+ }
189
+ }
190
+
191
+ /* CUSTOM SCROLLBAR */
192
+ ::-webkit-scrollbar {
193
+ width: 8px;
194
+ background-color: #ffffff;
195
+ }
196
+
197
+ ::-webkit-scrollbar-thumb {
198
+ background-color: #ccc;
199
+ border-radius: 10px;
200
+ }
201
+
202
+ ::-webkit-scrollbar-thumb:hover {
203
+ background-color: #bbb;
204
+ }
@@ -0,0 +1,7 @@
1
+ import payloadUtils from "../utils/json-path-utils";
2
+ import validations from "../utils/validation-utils";
3
+ import { testFunctionArray, validationInput, validationOutput } from "../types/test-config";
4
+
5
+
6
+
7
+ export default {{{functionCode}}}
@@ -0,0 +1,17 @@
1
+ import jsonpath from "jsonpath";
2
+ function getJsonPath(payload: any, path: string) {
3
+ let output = jsonpath.query(payload, path);
4
+ if (isListOfStringsOrNull(output)) {
5
+ output = output.map((o) => (o === null ? "null" : o));
6
+ }
7
+ return output.length === 0 ? [] : output;
8
+ }
9
+ function isListOfStringsOrNull(variable: any): boolean {
10
+ return (
11
+ Array.isArray(variable) &&
12
+ variable.every((item) => item === null || typeof item === "string")
13
+ );
14
+ }
15
+ export default {
16
+ getJsonPath,
17
+ };
@@ -0,0 +1,18 @@
1
+
2
+
3
+ {{#actions}}
4
+ import { {{{action}}} } from './{{{action}}}'
5
+ {{/actions}}
6
+
7
+
8
+ export default function getSchema(action : string){
9
+ switch(action){
10
+ {{#actions}}
11
+ case '{{{action}}}':
12
+ return {{{action}}};
13
+ {{/actions}}
14
+ default:
15
+ throw new Error('Action not found');
16
+ }
17
+ }
18
+