@avtechno/sfr 2.0.9 → 2.1.0

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/index.mjs CHANGED
@@ -22,6 +22,8 @@ async function write_service_discovery(cfg, documents) {
22
22
  //Setup files in case they do not exist.
23
23
  //Setup output folder
24
24
  await fs.mkdir(path.join(cwd, cfg.out), { recursive: true });
25
+ // Write combined OpenAPI index file containing all protocols
26
+ await write_combined_openapi_index(cfg, documents);
25
27
  // Loop over each protocol
26
28
  for (let [protocol, documentation] of Object.entries(documents)) {
27
29
  //Strictly await for setup to create dirs for each protocol.
@@ -51,6 +53,28 @@ async function write_service_discovery(cfg, documents) {
51
53
  }
52
54
  }
53
55
  }
56
+ // Writes a combined openapi.yml index file containing all generated documentation
57
+ async function write_combined_openapi_index(cfg, documents) {
58
+ const combined = {
59
+ openapi: "3.1.0",
60
+ info: {},
61
+ paths: {}
62
+ };
63
+ for (const [protocol, documentation] of Object.entries(documents)) {
64
+ switch (protocol) {
65
+ case "REST":
66
+ {
67
+ const rest_doc = documentation;
68
+ // Merge REST OpenAPI info and paths into combined doc
69
+ combined.info = rest_doc.info;
70
+ combined.paths = rest_doc.paths;
71
+ }
72
+ break;
73
+ }
74
+ }
75
+ // Write the combined index file
76
+ await fs.writeFile(path.join(cwd, cfg.out, "openapi.yml"), yaml.dump(combined, { lineWidth: -1, indent: 2, noRefs: true }), { flag: "w+" });
77
+ }
54
78
  //Tasked with recursively creating directories and spec files.
55
79
  async function write_to_file(cfg, dir, data) {
56
80
  //Path is a slash(/) delimited string, with the end delimiter indicating the filename to be used.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avtechno/sfr",
3
- "version": "2.0.9",
3
+ "version": "2.1.0",
4
4
  "description": "An opinionated way of writing services using ExpressJS.",
5
5
  "type": "module",
6
6
  "files": [
package/src/index.mts CHANGED
@@ -31,6 +31,9 @@ async function write_service_discovery(cfg: ParserCFG, documents: ServiceDocumen
31
31
  //Setup output folder
32
32
  await fs.mkdir(path.join(cwd, cfg.out), { recursive: true });
33
33
 
34
+ // Write combined OpenAPI index file containing all protocols
35
+ await write_combined_openapi_index(cfg, documents);
36
+
34
37
  // Loop over each protocol
35
38
  for (let [protocol, documentation] of Object.entries(documents)) {
36
39
  //Strictly await for setup to create dirs for each protocol.
@@ -60,6 +63,33 @@ async function write_service_discovery(cfg: ParserCFG, documents: ServiceDocumen
60
63
  }
61
64
  }
62
65
 
66
+ // Writes a combined openapi.yml index file containing all generated documentation
67
+ async function write_combined_openapi_index(cfg: ParserCFG, documents: ServiceDocuments) {
68
+ const combined: any = {
69
+ openapi: "3.1.0",
70
+ info: {},
71
+ paths: {}
72
+ };
73
+
74
+ for (const [protocol, documentation] of Object.entries(documents)) {
75
+ switch (protocol) {
76
+ case "REST": {
77
+ const rest_doc = documentation as OAPI_Document;
78
+ // Merge REST OpenAPI info and paths into combined doc
79
+ combined.info = rest_doc.info;
80
+ combined.paths = rest_doc.paths;
81
+ } break;
82
+ }
83
+ }
84
+
85
+ // Write the combined index file
86
+ await fs.writeFile(
87
+ path.join(cwd, cfg.out, "openapi.yml"),
88
+ yaml.dump(combined, { lineWidth: -1, indent: 2, noRefs: true }),
89
+ { flag: "w+" }
90
+ );
91
+ }
92
+
63
93
  //Tasked with recursively creating directories and spec files.
64
94
  async function write_to_file(cfg: ParserCFG, dir: string, data: object) {
65
95
  //Path is a slash(/) delimited string, with the end delimiter indicating the filename to be used.