-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmakefile.js
115 lines (101 loc) · 2.46 KB
/
makefile.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import {argv} from "node:process"
import {existsSync} from "node:fs"
import {fileURLToPath} from "node:url"
import {join} from "node:path"
import {mkdir, writeFile} from "node:fs/promises"
import {OpenAPIV3 as OpenApi} from "openapi-types"
import sade from "sade"
const config = {
source: {
owner: "onlyoffice",
repo: "docspace-declarations",
reference: "src",
paths: [
{name: "data", path: "asc.data.backup.swagger.json"},
{name: "files", path: "asc.files.swagger.json"},
{name: "people", path: "asc.people.swagger.json"},
{name: "web", path: "asc.web.api.swagger.json"},
],
},
}
main()
/**
* @returns {void}
*/
function main() {
sade("./makefile.js")
.command("build")
.action(build)
.parse(argv)
}
/**
* @returns {Promise<void>}
*/
async function build(){
const c = config.source
const rd = rootDir()
const dd = distDir(rd)
if (!existsSync(dd)) {
await mkdir(dd)
}
//TODO: console info?
for (const p of c.paths){
const u = `https://raw.githubusercontent.com/${c.owner}/${c.repo}/${c.reference}/${p.path}`
const r = await (await fetch(u)).json()
patch(r)
const dp = join(dd, p.path)
const ds = JSON.stringify(r, null, 2)
await writeFile(dp, ds)
}
}
/**
* @param {OpenApi.Document<{}>} d
* @returns {void}
*/
function patch(d) {
for (const pn in d.paths){
const po = d.paths[pn]
if (!po) {
continue
}
// https://github.com/ONLYOFFICE/DocSpace-server/blob/v2.0.2-server/web/ASC.Web.Api/Api/CapabilitiesController.cs#L33
if (pn.endsWith("{.format}")) {
delete d.paths[pn]
continue
}
for (const mn of Object.values(OpenApi.HttpMethods)) {
const mo = po[mn]
if (!mo) {
continue
}
if (mo.description) {
mo.description = `**Note**: ${mo.description}`
}
if (mo.summary) {
if (!mo.description) {
mo.description = mo.summary
} else {
mo.description = `${mo.summary}\n\n${mo.description}`
}
}
if ("x-shortName" in mo && typeof mo["x-shortName"] === "string") {
mo.summary = mo["x-shortName"]
delete mo["x-shortName"]
}
}
}
}
/**
* @returns {string}
*/
function rootDir() {
const u = new URL(".", import.meta.url)
return fileURLToPath(u)
}
/**
* @param {string} d
* @returns {string}
*/
function distDir(d) {
return join(d, "dist")
}