-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrateOpenApi.js
More file actions
47 lines (39 loc) · 1.26 KB
/
Copy pathmigrateOpenApi.js
File metadata and controls
47 lines (39 loc) · 1.26 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
39
40
41
42
43
44
45
46
47
const marked = require('marked');
const yaml = require('js-yaml');
const fs = require('fs');
function extractUrls(inputString) {
const urlRegex = /(https?:\/\/[^\s]+)/g; // regular expression to match URLs
const matches = inputString.match(urlRegex);
if (!matches) return [];
const openapiJson = {
openapi: "3.0.0",
info: {
version: "1.0.0",
title: "URLs found in string",
description: "List of URLs extracted from input string",
},
paths: {},
};
// create a path for each URL found
matches.forEach((url, index) => {
const path = `${url.split("https://api.cakework.com/v1")[1]}`;
openapiJson.paths[path] = {
get: {
tags: ["URLs"],
summary: `${url.split("https://api.cakework.com/v1")[1]}`,
description: `How to get started with the ${url} call`,
responses: {
200: {
description: "Success",
},
},
},
};
});
return openapiJson;
}
const file = fs.readFileSync("./docs/reference/rest.md", { encoding: 'utf8', flag: 'r' })
console.log(file)
const openapiJson = extractUrls(file);
console.log(openapiJson);
fs.writeFileSync("./openapi.json", JSON.stringify(openapiJson))