forked from oasis-tcs/odata-openapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtransform.js
More file actions
38 lines (31 loc) · 1.15 KB
/
Copy pathtransform.js
File metadata and controls
38 lines (31 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env node
"use strict";
const csdl = require("odata-csdl");
const lib = require("./csdl2openapi");
const fs = require("fs");
const exampleFolder = "./examples/";
const basePath = {
example: "/V4/OData/(S(nsga2k1tyctb0cn0ofcgcn4o))/OData.svc",
Northwind: "/V4/Northwind/Northwind.svc",
TripPin: "/V4/(S(cnbm44wtbc1v5bgrlek5lpcc))/TripPinServiceRW",
"odata-rw-v3": "/V3/(S(1urrjxgkuh4r30yqim0hqrtj))/OData/OData.svc",
"Northwind-V3": "/V3/Northwind/Northwind.svc",
};
fs.readdirSync(exampleFolder)
.filter((fn) => fn.endsWith(".xml"))
.forEach((xmlfile) => {
const example = xmlfile.substring(0, xmlfile.lastIndexOf("."));
console.log(xmlfile);
const xml = fs.readFileSync(exampleFolder + xmlfile, "utf8");
const json = csdl.xml2json(xml, false);
const openapi = lib.csdl2openapi(json, {
scheme: "https",
host: basePath[example] ? "services.odata.org" : "localhost",
basePath: basePath[example] || "/service-root",
diagram: true,
});
fs.writeFileSync(
exampleFolder + example + ".openapi3.json",
JSON.stringify(openapi, null, 4)
);
});