ondc-code-generator 0.0.1 → 0.0.3
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.
- package/dist/constants/syntax.js +2 -0
- package/{src/example.ts → dist/example.js} +1 -4
- package/dist/{Generator → generator}/config-compiler.js +25 -4
- package/dist/{Generator → generator}/generators/documentation/markdown-message-generator.js +0 -13
- package/dist/{Generator → generator}/generators/typescript/ts-generator.js +3 -4
- package/dist/{Generator → generator}/validators/abstract-validator.js +1 -1
- package/dist/{Generator → generator}/validators/config-validator.js +4 -4
- package/dist/{Generator → generator}/validators/session-data-config/session-data-validator.js +2 -2
- package/dist/{Generator → generator}/validators/tests-config/sub-validations.js +38 -33
- package/dist/{Generator → generator}/validators/tests-config/test-list-validator.js +3 -3
- package/dist/{Generator → generator}/validators/tests-config/test-validator.js +7 -7
- package/dist/index.js +1 -38
- package/dist/services/return-complier/tokens.js +3 -0
- package/dist/utils/general-utils/string-utils.js +10 -2
- package/package.json +6 -4
- package/dist/Generator/config-validator.js +0 -21
- package/dist/Generator/generators/markdown-message-generator.js +0 -25
- package/dist/Generator/pipline.js +0 -1
- package/dist/Generator/validators/validation-error.js +0 -9
- package/dist/services/rename-later/main.js +0 -1
- package/dist/services/rename-later/parser.js +0 -22
- package/dist/services/rename-later/tokens.js +0 -32
- package/dist/services/rename-later/tokens1.js +0 -33
- package/dist/utils/file-system.js +0 -1
- package/src/constants/operations.ts +0 -19
- package/src/constants/syntax.ts +0 -81
- package/src/generator/config-compiler.ts +0 -122
- package/src/generator/generators/classes/abstract-generator.ts +0 -29
- package/src/generator/generators/documentation/markdown-message-generator.ts +0 -43
- package/src/generator/generators/documentation/md-generator.ts +0 -76
- package/src/generator/generators/documentation/templates/index.mustache +0 -36
- package/src/generator/generators/documentation/templates/style.css +0 -204
- package/src/generator/generators/python/py-generator.ts +0 -0
- package/src/generator/generators/typescript/templates/api-test.mustache +0 -7
- package/src/generator/generators/typescript/templates/json-path-utils.ts +0 -17
- package/src/generator/generators/typescript/templates/schema-template.mustache +0 -18
- package/src/generator/generators/typescript/templates/test-config.mustache +0 -28
- package/src/generator/generators/typescript/templates/test-object.mustache +0 -20
- package/src/generator/generators/typescript/templates/validation-code.mustache +0 -39
- package/src/generator/generators/typescript/templates/validation-utils.ts +0 -117
- package/src/generator/generators/typescript/ts-ast.ts +0 -72
- package/src/generator/generators/typescript/ts-generator.ts +0 -275
- package/src/generator/validators/abstract-validator.ts +0 -23
- package/src/generator/validators/config-validator.ts +0 -55
- package/src/generator/validators/session-data-config/session-data-validator.ts +0 -58
- package/src/generator/validators/tests-config/sub-validations.ts +0 -302
- package/src/generator/validators/tests-config/test-list-validator.ts +0 -59
- package/src/generator/validators/tests-config/test-validator.ts +0 -69
- package/src/index.ts +0 -2
- package/src/services/return-complier/ast-functions/compile-to-markdown.ts +0 -152
- package/src/services/return-complier/ast-functions/semantic-validations.ts +0 -44
- package/src/services/return-complier/ast.ts +0 -147
- package/src/services/return-complier/combined.ts +0 -8
- package/src/services/return-complier/parser.ts +0 -128
- package/src/services/return-complier/tokens.ts +0 -184
- package/src/services/schema-service.ts +0 -42
- package/src/types/build.ts +0 -51
- package/src/types/compiler-types.ts +0 -3
- package/src/types/config-types.ts +0 -27
- package/src/types/error-codes.ts +0 -6
- package/src/types/general-types.ts +0 -2
- package/src/utils/config-utils/json-schema-utils.ts +0 -150
- package/src/utils/config-utils/yaml.ts +0 -17
- package/src/utils/fs-utils.ts +0 -32
- package/src/utils/general-utils/string-utils.ts +0 -76
- package/src/utils/general-utils/test-object-utils.ts +0 -14
- package/src/utils/general-utils/validation-utils.ts +0 -30
- package/src/utils/json-path-utils/extract-string-paths.ts +0 -139
- package/src/utils/json-path-utils/paths.ts +0 -44
- package/src/utils/logger.ts +0 -53
- package/tsconfig.json +0 -17
- /package/dist/{Generator → generator}/generators/classes/abstract-generator.js +0 -0
- /package/dist/{Generator → generator}/generators/documentation/md-generator.js +0 -0
- /package/dist/{Generator → generator}/generators/python/py-generator.js +0 -0
- /package/dist/{Generator → generator}/generators/typescript/templates/json-path-utils.js +0 -0
- /package/dist/{Generator → generator}/generators/typescript/templates/validation-utils.js +0 -0
- /package/dist/{Generator → generator}/generators/typescript/ts-ast.js +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CstParser } from "chevrotain";
|
|
2
|
-
import { allTokens, NumberLiteral, PlusMinusOperator } from "./tokens.js";
|
|
3
|
-
export default class CalculatorParser extends CstParser {
|
|
4
|
-
constructor() {
|
|
5
|
-
super(allTokens);
|
|
6
|
-
const $ = this;
|
|
7
|
-
$.RULE("expression", () => {
|
|
8
|
-
$.SUBRULE($.additionExpression);
|
|
9
|
-
});
|
|
10
|
-
$.RULE("additionExpression", () => {
|
|
11
|
-
$.SUBRULE($.atomicExpression, { LABEL: "lhs" });
|
|
12
|
-
$.MANY(() => {
|
|
13
|
-
$.CONSUME(PlusMinusOperator);
|
|
14
|
-
$.SUBRULE2($.atomicExpression, { LABEL: "rhs" });
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
$.RULE("atomicExpression", () => {
|
|
18
|
-
$.CONSUME(NumberLiteral);
|
|
19
|
-
});
|
|
20
|
-
$.performSelfAnalysis();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { createToken, Lexer } from "chevrotain";
|
|
2
|
-
export const NumberLiteral = createToken({
|
|
3
|
-
name: "NumberLiteral",
|
|
4
|
-
pattern: /[0-9]+/,
|
|
5
|
-
});
|
|
6
|
-
export const PlusMinusOperator = createToken({
|
|
7
|
-
name: "PlusMinusOperator",
|
|
8
|
-
pattern: Lexer.NA,
|
|
9
|
-
});
|
|
10
|
-
export const Plus = createToken({
|
|
11
|
-
name: "Plus",
|
|
12
|
-
pattern: /\+/,
|
|
13
|
-
categories: PlusMinusOperator,
|
|
14
|
-
});
|
|
15
|
-
export const Minus = createToken({
|
|
16
|
-
name: "Minus",
|
|
17
|
-
pattern: /-/,
|
|
18
|
-
categories: PlusMinusOperator,
|
|
19
|
-
});
|
|
20
|
-
export const WhiteSpace = createToken({
|
|
21
|
-
name: "WhiteSpace",
|
|
22
|
-
pattern: /\s+/,
|
|
23
|
-
line_breaks: true,
|
|
24
|
-
group: Lexer.SKIPPED,
|
|
25
|
-
});
|
|
26
|
-
export const allTokens = [
|
|
27
|
-
Plus,
|
|
28
|
-
Minus,
|
|
29
|
-
NumberLiteral,
|
|
30
|
-
PlusMinusOperator,
|
|
31
|
-
WhiteSpace,
|
|
32
|
-
];
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createToken, Lexer } from "chevrotain";
|
|
2
|
-
export const NumberLiteral = createToken({
|
|
3
|
-
name: "NumberLiteral",
|
|
4
|
-
pattern: /[0-9]+/,
|
|
5
|
-
});
|
|
6
|
-
export const PlusMinusOperator = createToken({
|
|
7
|
-
name: "PlusMinusOperator",
|
|
8
|
-
pattern: Lexer.NA,
|
|
9
|
-
});
|
|
10
|
-
export const Plus = createToken({
|
|
11
|
-
name: "Plus",
|
|
12
|
-
pattern: /\+/,
|
|
13
|
-
categories: PlusMinusOperator,
|
|
14
|
-
});
|
|
15
|
-
export const Minus = createToken({
|
|
16
|
-
name: "Minus",
|
|
17
|
-
pattern: /-/,
|
|
18
|
-
categories: PlusMinusOperator,
|
|
19
|
-
});
|
|
20
|
-
export const WhiteSpace = createToken({
|
|
21
|
-
name: "WhiteSpace",
|
|
22
|
-
pattern: /\s+/,
|
|
23
|
-
line_breaks: true,
|
|
24
|
-
group: Lexer.SKIPPED,
|
|
25
|
-
});
|
|
26
|
-
export const allTokens = [
|
|
27
|
-
Plus,
|
|
28
|
-
Minus,
|
|
29
|
-
NumberLiteral,
|
|
30
|
-
PlusMinusOperator,
|
|
31
|
-
WhiteSpace,
|
|
32
|
-
];
|
|
33
|
-
console.log(allTokens);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
];
|
package/src/constants/syntax.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
]);
|
|
@@ -1,122 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
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>
|