ondc-code-generator 0.3.0 → 0.3.2
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/generator/config-compiler.js +1 -1
- package/dist/generator/validators/abstract-validator.d.ts +1 -1
- package/dist/generator/validators/config-validator.d.ts +2 -2
- package/dist/generator/validators/config-validator.js +2 -1
- package/dist/generator/validators/tests-config/sub-validations.d.ts +6 -4
- package/dist/generator/validators/tests-config/sub-validations.js +16 -7
- package/dist/generator/validators/tests-config/test-validator.js +3 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -7,10 +7,10 @@ export declare class ConfigValidator implements IValidator {
|
|
|
7
7
|
stringJsonPaths: Record<string, string[]>;
|
|
8
8
|
errorDefinitions: ErrorDefinition[];
|
|
9
9
|
validatorSettings: {
|
|
10
|
-
|
|
10
|
+
minimal: boolean;
|
|
11
11
|
};
|
|
12
12
|
constructor(validationPath: string, config: ValidationConfig, stringJsonPaths: Record<string, string[]>, errorDefinitions: ErrorDefinition[], settings?: {
|
|
13
|
-
|
|
13
|
+
minimal: boolean;
|
|
14
14
|
});
|
|
15
15
|
validate: () => Promise<void>;
|
|
16
16
|
}
|
|
@@ -20,6 +20,7 @@ export class ConfigValidator {
|
|
|
20
20
|
stringJsonPaths: this.stringJsonPaths[api],
|
|
21
21
|
errorDefinitions: this.errorDefinitions,
|
|
22
22
|
externalVariables: externalVariables,
|
|
23
|
+
minimal: this.validatorSettings.minimal,
|
|
23
24
|
};
|
|
24
25
|
await new TestsValidator(testList, path, dependencies).validate();
|
|
25
26
|
}
|
|
@@ -33,7 +34,7 @@ export class ConfigValidator {
|
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
36
|
this.validatorSettings = {
|
|
36
|
-
|
|
37
|
+
minimal: false,
|
|
37
38
|
};
|
|
38
39
|
}
|
|
39
40
|
}
|
|
@@ -9,19 +9,21 @@ export declare class NameValidator extends TestObjectValidator {
|
|
|
9
9
|
}
|
|
10
10
|
export declare class ScopeValidator extends TestObjectValidator {
|
|
11
11
|
impossiblePaths: string[];
|
|
12
|
-
|
|
12
|
+
minimal: boolean;
|
|
13
|
+
constructor(testObject: TestObject, path: string, impossiblePaths: string[], minimal?: boolean);
|
|
13
14
|
validate: () => Promise<void>;
|
|
14
15
|
}
|
|
15
16
|
export declare class ErrorCodeValidator extends TestObjectValidator {
|
|
16
17
|
possibleErrorCodes: ErrorDefinition[];
|
|
17
|
-
|
|
18
|
+
minimal: boolean;
|
|
19
|
+
constructor(testObject: TestObject, path: string, possibleErrorCodes: ErrorDefinition[], minimal?: boolean);
|
|
18
20
|
validate: () => Promise<void>;
|
|
19
21
|
}
|
|
20
22
|
export declare class VariableValidator extends TestObjectValidator {
|
|
21
23
|
possibleJsonPaths: string[];
|
|
22
24
|
externalVariables: string[];
|
|
23
|
-
|
|
24
|
-
constructor(testObject: TestObject, path: string, posibleJsonPaths: string[], externalVariables: string[],
|
|
25
|
+
minimal: boolean;
|
|
26
|
+
constructor(testObject: TestObject, path: string, posibleJsonPaths: string[], externalVariables: string[], minimal?: boolean);
|
|
25
27
|
validate: () => Promise<void>;
|
|
26
28
|
validateKey(key: string): void;
|
|
27
29
|
validateExternalData(path: string, definedExternalValues: string[]): void;
|
|
@@ -41,8 +41,9 @@ export class NameValidator extends TestObjectValidator {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
export class ScopeValidator extends TestObjectValidator {
|
|
44
|
-
constructor(testObject, path, impossiblePaths) {
|
|
44
|
+
constructor(testObject, path, impossiblePaths, minimal = false) {
|
|
45
45
|
super(testObject, path);
|
|
46
|
+
this.minimal = false;
|
|
46
47
|
this.validate = async () => {
|
|
47
48
|
const path = this.targetObject[TestObjectSyntax.Scope];
|
|
48
49
|
if (typeof path !== "string") {
|
|
@@ -54,16 +55,20 @@ export class ScopeValidator extends TestObjectValidator {
|
|
|
54
55
|
if (!path.startsWith(`$.`)) {
|
|
55
56
|
throw new Error(`${TestObjectSyntax.Scope} json path should start with $. at ${this.validationPath}`);
|
|
56
57
|
}
|
|
58
|
+
if (this.minimal)
|
|
59
|
+
return;
|
|
57
60
|
if (this.impossiblePaths.includes(replaceBracketsWithAsteriskNested(path))) {
|
|
58
61
|
throw new Error(`${TestObjectSyntax.Scope} can't be a path that returns a array of string it must be a json path which returns a array of objects at path ${this.validationPath}`);
|
|
59
62
|
}
|
|
60
63
|
};
|
|
61
64
|
this.impossiblePaths = impossiblePaths;
|
|
65
|
+
this.minimal = minimal;
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
export class ErrorCodeValidator extends TestObjectValidator {
|
|
65
|
-
constructor(testObject, path, possibleErrorCodes) {
|
|
69
|
+
constructor(testObject, path, possibleErrorCodes, minimal = false) {
|
|
66
70
|
super(testObject, path);
|
|
71
|
+
this.minimal = false;
|
|
67
72
|
this.validate = async () => {
|
|
68
73
|
if (!this.targetObject[TestObjectSyntax.ErrorCode]) {
|
|
69
74
|
return;
|
|
@@ -74,6 +79,8 @@ export class ErrorCodeValidator extends TestObjectValidator {
|
|
|
74
79
|
if (typeof this.targetObject[TestObjectSyntax.ErrorCode] !== "number") {
|
|
75
80
|
throw new Error(`${TestObjectSyntax.ErrorCode} should be a number at path ${this.validationPath}`);
|
|
76
81
|
}
|
|
82
|
+
if (this.minimal)
|
|
83
|
+
return;
|
|
77
84
|
const errorCode = this.targetObject[TestObjectSyntax.ErrorCode];
|
|
78
85
|
if (!this.possibleErrorCodes.some((code) => code.code === errorCode)) {
|
|
79
86
|
throw new Error(`${TestObjectSyntax.ErrorCode} don't exist in error codes at path ${this.validationPath}`);
|
|
@@ -86,12 +93,13 @@ export class ErrorCodeValidator extends TestObjectValidator {
|
|
|
86
93
|
}
|
|
87
94
|
};
|
|
88
95
|
this.possibleErrorCodes = possibleErrorCodes;
|
|
96
|
+
this.minimal = minimal;
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
export class VariableValidator extends TestObjectValidator {
|
|
92
|
-
constructor(testObject, path, posibleJsonPaths, externalVariables,
|
|
100
|
+
constructor(testObject, path, posibleJsonPaths, externalVariables, minimal = false) {
|
|
93
101
|
super(testObject, path);
|
|
94
|
-
this.
|
|
102
|
+
this.minimal = false;
|
|
95
103
|
this.validate = async () => {
|
|
96
104
|
for (const key in this.targetObject) {
|
|
97
105
|
if (Object.values(TestObjectSyntax).includes(key)) {
|
|
@@ -120,8 +128,9 @@ export class VariableValidator extends TestObjectValidator {
|
|
|
120
128
|
path = `${scope}.${pathWithoutDollar}`;
|
|
121
129
|
}
|
|
122
130
|
const replaced = replaceBracketsWithAsteriskNested(path);
|
|
123
|
-
if (
|
|
124
|
-
|
|
131
|
+
if (this.minimal)
|
|
132
|
+
return;
|
|
133
|
+
if (!this.possibleJsonPaths.includes(replaced)) {
|
|
125
134
|
throw new Error(`Variable: ${key} should be a jsonPath that returns a array of strings or the path don't exist in the schema, at ${this.validationPath} found original ${path} replaces: ${replaced}`);
|
|
126
135
|
}
|
|
127
136
|
}
|
|
@@ -129,7 +138,7 @@ export class VariableValidator extends TestObjectValidator {
|
|
|
129
138
|
};
|
|
130
139
|
this.externalVariables = externalVariables;
|
|
131
140
|
this.possibleJsonPaths = posibleJsonPaths;
|
|
132
|
-
this.
|
|
141
|
+
this.minimal = minimal;
|
|
133
142
|
}
|
|
134
143
|
validateKey(key) {
|
|
135
144
|
if (nodeReservedKeywords.has(key)) {
|
|
@@ -8,12 +8,12 @@ export class CompleteTestObjectValidator extends TestObjectValidator {
|
|
|
8
8
|
await new RequiredFieldsValidator(this.targetObject, this.validationPath).validate();
|
|
9
9
|
await new NameValidator(this.targetObject, this.validationPath).validate();
|
|
10
10
|
if (this.targetObject[TestObjectSyntax.Scope]) {
|
|
11
|
-
await new ScopeValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths).validate();
|
|
11
|
+
await new ScopeValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.minimal).validate();
|
|
12
12
|
}
|
|
13
13
|
if (this.targetObject[TestObjectSyntax.ErrorCode]) {
|
|
14
|
-
await new ErrorCodeValidator(this.targetObject, this.validationPath, this.dependencies.errorDefinitions).validate();
|
|
14
|
+
await new ErrorCodeValidator(this.targetObject, this.validationPath, this.dependencies.errorDefinitions, this.dependencies.minimal).validate();
|
|
15
15
|
}
|
|
16
|
-
await new VariableValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.externalVariables, this.dependencies.
|
|
16
|
+
await new VariableValidator(this.targetObject, this.validationPath, this.dependencies.stringJsonPaths, this.dependencies.externalVariables, this.dependencies.minimal).validate();
|
|
17
17
|
if (this.targetObject[TestObjectSyntax.Continue]) {
|
|
18
18
|
await new ContinueValidator(this.targetObject, this.validationPath).validate();
|
|
19
19
|
}
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ export { ConfigCompiler };
|
|
|
16
16
|
// const buildYaml = readFileSync(buildPath, "utf-8");
|
|
17
17
|
// const valConfig = JSON.parse(readFileSync(valConfigPath, "utf-8"));
|
|
18
18
|
// await compiler.initialize(buildYaml);
|
|
19
|
-
//
|
|
19
|
+
// await compiler.generateCode(valConfig, "L1-validations", true);
|
|
20
20
|
// };
|
|
21
21
|
// (async () => {
|
|
22
22
|
// await main();
|