ondc-code-generator 0.1.1 → 0.1.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.
|
@@ -19,5 +19,6 @@ export declare class ConfigCompiler {
|
|
|
19
19
|
performValidations: (valConfig: ValidationConfig) => Promise<void>;
|
|
20
20
|
generateCode: (valConfig: ValidationConfig, codeName?: string) => Promise<void>;
|
|
21
21
|
generateL0Schema: () => Promise<void>;
|
|
22
|
+
generateValidPaths: () => Promise<void>;
|
|
22
23
|
}
|
|
23
24
|
export {};
|
|
@@ -5,8 +5,12 @@ import { SupportedLanguages } from "../types/compiler-types.js";
|
|
|
5
5
|
import { TypescriptGenerator } from "./generators/typescript/ts-generator.js";
|
|
6
6
|
import { ConfigValidator } from "./validators/config-validator.js";
|
|
7
7
|
import { writeAndFormatCode } from "../utils/fs-utils.js";
|
|
8
|
-
import { readFileSync } from "fs";
|
|
8
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
9
9
|
import Mustache from "mustache";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
import path from "path";
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
10
14
|
const defaultConfig = {
|
|
11
15
|
removeRequiredfromSchema: true,
|
|
12
16
|
removeEnumsfromSchema: true,
|
|
@@ -65,11 +69,16 @@ export class ConfigCompiler {
|
|
|
65
69
|
action: schema,
|
|
66
70
|
};
|
|
67
71
|
});
|
|
68
|
-
const template = readFileSync("
|
|
72
|
+
const template = readFileSync(path.resolve(__dirname, "../generator/generators/typescript/templates/schema-template.mustache"), "utf-8");
|
|
69
73
|
console.log(actions);
|
|
70
74
|
const l0 = Mustache.render(template, { actions });
|
|
71
75
|
await writeAndFormatCode(`./generated/L0-schemas`, `index.ts`, l0, "typescript");
|
|
72
76
|
};
|
|
77
|
+
this.generateValidPaths = async () => {
|
|
78
|
+
if (!this.possibleJsonPaths)
|
|
79
|
+
throw new Error("Possible paths not initialized");
|
|
80
|
+
writeFileSync("./validPaths.json", JSON.stringify(this.possibleJsonPaths, null, 2));
|
|
81
|
+
};
|
|
73
82
|
this.language = language;
|
|
74
83
|
this.SchemaExtactionService = new SchemaExtactionService();
|
|
75
84
|
}
|
|
@@ -11,8 +11,10 @@ export class SchemaExtactionService {
|
|
|
11
11
|
for (const targetApi of apis) {
|
|
12
12
|
const existingSchema = paths[`/${targetApi}`].post.requestBody.content["application/json"]
|
|
13
13
|
.schema;
|
|
14
|
-
output["response"] =
|
|
15
|
-
|
|
14
|
+
// output["response"] =
|
|
15
|
+
// paths[`/${targetApi}`].post.responses.default.content[
|
|
16
|
+
// "application/json"
|
|
17
|
+
// ].schema;
|
|
16
18
|
const filtteredSchema = removeRequiredAndEnum(existingSchema, removeEnums, removeRequired);
|
|
17
19
|
output[targetApi] = filtteredSchema;
|
|
18
20
|
}
|