@voxgig/apidef 0.3.0 → 1.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/bin/{run-apidef.js → voxgig-apidef} +24 -24
- package/dist/apidef.d.ts +5 -4
- package/dist/apidef.js +31 -49
- package/dist/apidef.js.map +1 -1
- package/dist/transform.js +1 -1
- package/dist/transform.js.map +1 -1
- package/package.json +8 -7
- package/src/apidef.ts +45 -59
- package/src/transform.ts +1 -1
- package/bin/run-apidef.js~ +0 -330
|
@@ -15,33 +15,35 @@ const { ApiDef } = require('../dist/apidef.js')
|
|
|
15
15
|
|
|
16
16
|
let CONSOLE = console
|
|
17
17
|
|
|
18
|
+
run()
|
|
18
19
|
|
|
19
|
-
try {
|
|
20
|
-
let options = resolveOptions()
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
async function run() {
|
|
22
|
+
try {
|
|
23
|
+
let options = resolveOptions()
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if(options.version) {
|
|
26
|
+
version()
|
|
27
|
+
}
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if(options.help) {
|
|
30
|
+
help()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if(options.version || options.help) {
|
|
34
|
+
exit()
|
|
35
|
+
}
|
|
33
36
|
|
|
34
|
-
|
|
37
|
+
options = validateOptions(options)
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
await generate(options)
|
|
40
|
+
}
|
|
41
|
+
catch(err) {
|
|
42
|
+
handleError(err)
|
|
43
|
+
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
|
|
44
|
-
|
|
45
47
|
function exit(err) {
|
|
46
48
|
let code = 0
|
|
47
49
|
if(err) {
|
|
@@ -51,7 +53,7 @@ function exit(err) {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
|
|
54
|
-
function generate(options) {
|
|
56
|
+
async function generate(options) {
|
|
55
57
|
const apidef = new ApiDef({
|
|
56
58
|
debug: options.debug
|
|
57
59
|
})
|
|
@@ -64,12 +66,11 @@ function generate(options) {
|
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
if(options.watch) {
|
|
67
|
-
apidef.watch(spec)
|
|
69
|
+
await apidef.watch(spec)
|
|
68
70
|
}
|
|
69
71
|
else {
|
|
70
|
-
apidef.generate(spec)
|
|
72
|
+
await apidef.generate(spec)
|
|
71
73
|
}
|
|
72
|
-
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
|
|
@@ -159,10 +160,9 @@ function validateOptions(rawOptions) {
|
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
|
|
162
|
-
function handleError(err) {
|
|
163
|
+
async function handleError(err) {
|
|
163
164
|
CONSOLE.log('Voxgig API Definition Error:')
|
|
164
165
|
CONSOLE.log(err)
|
|
165
|
-
|
|
166
166
|
exit(err)
|
|
167
167
|
}
|
|
168
168
|
|
package/dist/apidef.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import Pino from '
|
|
1
|
+
import { Pino } from '@voxgig/util';
|
|
2
2
|
type ApiDefOptions = {
|
|
3
3
|
fs?: any;
|
|
4
4
|
pino?: ReturnType<typeof Pino>;
|
|
@@ -9,9 +9,10 @@ type ApiDefSpec = {
|
|
|
9
9
|
model: string;
|
|
10
10
|
kind: string;
|
|
11
11
|
meta: Record<string, any>;
|
|
12
|
+
guide: any;
|
|
12
13
|
};
|
|
13
14
|
declare function ApiDef(opts?: ApiDefOptions): {
|
|
14
|
-
watch: (spec:
|
|
15
|
+
watch: (spec: ApiDefSpec) => Promise<void>;
|
|
15
16
|
generate: (spec: ApiDefSpec) => Promise<{
|
|
16
17
|
ok: boolean;
|
|
17
18
|
model: {
|
|
@@ -22,7 +23,7 @@ declare function ApiDef(opts?: ApiDefOptions): {
|
|
|
22
23
|
def: {};
|
|
23
24
|
};
|
|
24
25
|
};
|
|
25
|
-
}>;
|
|
26
|
+
} | undefined>;
|
|
26
27
|
};
|
|
27
|
-
export type { ApiDefOptions, };
|
|
28
|
+
export type { ApiDefOptions, ApiDefSpec, };
|
|
28
29
|
export { ApiDef, };
|
package/dist/apidef.js
CHANGED
|
@@ -33,23 +33,11 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
33
33
|
const openapi_core_1 = require("@redocly/openapi-core");
|
|
34
34
|
const chokidar_1 = require("chokidar");
|
|
35
35
|
const aontu_1 = require("aontu");
|
|
36
|
-
const
|
|
37
|
-
const pino_pretty_1 = __importDefault(require("pino-pretty"));
|
|
36
|
+
const util_1 = require("@voxgig/util");
|
|
38
37
|
const transform_1 = require("./transform");
|
|
39
38
|
function ApiDef(opts = {}) {
|
|
40
39
|
const fs = opts.fs || Fs;
|
|
41
|
-
|
|
42
|
-
if (null == pino) {
|
|
43
|
-
let pretty = (0, pino_pretty_1.default)({ sync: true });
|
|
44
|
-
const level = null == opts.debug ? 'info' :
|
|
45
|
-
true === opts.debug ? 'debug' :
|
|
46
|
-
'string' == typeof opts.debug ? opts.debug :
|
|
47
|
-
'info';
|
|
48
|
-
pino = (0, pino_1.default)({
|
|
49
|
-
name: 'apidef',
|
|
50
|
-
level,
|
|
51
|
-
}, pretty);
|
|
52
|
-
}
|
|
40
|
+
const pino = (0, util_1.prettyPino)('apidef', opts);
|
|
53
41
|
const log = pino.child({ cmp: 'apidef' });
|
|
54
42
|
async function watch(spec) {
|
|
55
43
|
log.info({ point: 'watch-start' });
|
|
@@ -62,12 +50,14 @@ function ApiDef(opts = {}) {
|
|
|
62
50
|
});
|
|
63
51
|
log.trace({ watch: 'add', what: 'def', file: spec.def });
|
|
64
52
|
fsw.add(spec.def);
|
|
65
|
-
log.trace({ watch: 'add', what: 'guide', file: spec.
|
|
53
|
+
log.trace({ watch: 'add', what: 'guide', file: spec.guide });
|
|
66
54
|
fsw.add(spec.guide);
|
|
67
55
|
}
|
|
68
56
|
async function generate(spec) {
|
|
69
57
|
const start = Date.now();
|
|
70
|
-
|
|
58
|
+
// TODO: validate spec
|
|
59
|
+
const defpath = node_path_1.default.normalize(spec.def);
|
|
60
|
+
log.info({ point: 'generate-start', note: 'defpath', defpath, start });
|
|
71
61
|
log.debug({ point: 'generate-spec', spec });
|
|
72
62
|
// TODO: Validate spec
|
|
73
63
|
const ctx = {
|
|
@@ -76,9 +66,12 @@ function ApiDef(opts = {}) {
|
|
|
76
66
|
guide: {},
|
|
77
67
|
opts,
|
|
78
68
|
util: { fixName: transform_1.fixName },
|
|
79
|
-
defpath: node_path_1.default.dirname(
|
|
69
|
+
defpath: node_path_1.default.dirname(defpath)
|
|
80
70
|
};
|
|
81
71
|
const guide = await resolveGuide(spec, opts);
|
|
72
|
+
if (null == guide) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
82
75
|
log.debug({ point: 'guide', guide });
|
|
83
76
|
ctx.guide = guide;
|
|
84
77
|
const transformSpec = await (0, transform_1.resolveTransforms)(ctx);
|
|
@@ -88,7 +81,7 @@ function ApiDef(opts = {}) {
|
|
|
88
81
|
source = fs.readFileSync(spec.def, 'utf8');
|
|
89
82
|
}
|
|
90
83
|
catch (err) {
|
|
91
|
-
log.error({ read: 'fail', what: 'def', file:
|
|
84
|
+
log.error({ read: 'fail', what: 'def', file: defpath, err });
|
|
92
85
|
throw err;
|
|
93
86
|
}
|
|
94
87
|
const config = await (0, openapi_core_1.createConfig)({});
|
|
@@ -101,7 +94,7 @@ function ApiDef(opts = {}) {
|
|
|
101
94
|
});
|
|
102
95
|
}
|
|
103
96
|
catch (err) {
|
|
104
|
-
log.error({ parse: 'fail', what: 'openapi', file:
|
|
97
|
+
log.error({ parse: 'fail', what: 'openapi', file: defpath, err });
|
|
105
98
|
throw err;
|
|
106
99
|
}
|
|
107
100
|
const model = {
|
|
@@ -137,23 +130,7 @@ function ApiDef(opts = {}) {
|
|
|
137
130
|
let modelDefSrc = JSON.stringify(modelDef, null, 2);
|
|
138
131
|
modelDefSrc = modelDefSrc.substring(1, modelDefSrc.length - 1);
|
|
139
132
|
writeChanged('def-model', defFilePath, modelDefSrc);
|
|
140
|
-
|
|
141
|
-
let existingSrc: string = ''
|
|
142
|
-
if (fs.existsSync(defFilePath)) {
|
|
143
|
-
existingSrc = fs.readFileSync(defFilePath, 'utf8')
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let writeModelDef = existingSrc !== modelDefSrc
|
|
147
|
-
// console.log('APIDEF', writeModelDef)
|
|
148
|
-
|
|
149
|
-
// Only write the model def if it has changed
|
|
150
|
-
if (writeModelDef) {
|
|
151
|
-
fs.writeFileSync(
|
|
152
|
-
defFilePath,
|
|
153
|
-
modelDefSrc
|
|
154
|
-
)
|
|
155
|
-
}
|
|
156
|
-
*/
|
|
133
|
+
log.info({ point: 'generate-end', note: 'success', break: true });
|
|
157
134
|
return {
|
|
158
135
|
ok: true,
|
|
159
136
|
model,
|
|
@@ -165,6 +142,7 @@ function ApiDef(opts = {}) {
|
|
|
165
142
|
let action = '';
|
|
166
143
|
try {
|
|
167
144
|
let existingContent = '';
|
|
145
|
+
path = node_path_1.default.normalize(path);
|
|
168
146
|
exists = fs.existsSync(path);
|
|
169
147
|
if (exists) {
|
|
170
148
|
action = 'read';
|
|
@@ -172,6 +150,8 @@ function ApiDef(opts = {}) {
|
|
|
172
150
|
}
|
|
173
151
|
changed = existingContent !== content;
|
|
174
152
|
log.info({
|
|
153
|
+
point: 'write-' + what,
|
|
154
|
+
note: 'changed,file',
|
|
175
155
|
write: 'file', what, skip: !changed, exists, changed,
|
|
176
156
|
contentLength: content.length, file: path
|
|
177
157
|
});
|
|
@@ -235,11 +215,21 @@ guide: control: transform: openapi: order: \`
|
|
|
235
215
|
const root = (0, aontu_1.Aontu)(src, aopts);
|
|
236
216
|
const hasErr = root.err && 0 < root.err.length;
|
|
237
217
|
if (hasErr) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
218
|
+
for (let serr of root.err) {
|
|
219
|
+
let err = new Error('Guide model: ' + serr.msg);
|
|
220
|
+
err.cause$ = [serr];
|
|
221
|
+
if ('syntax' === serr.why) {
|
|
222
|
+
err.uxmsg$ = true;
|
|
223
|
+
}
|
|
224
|
+
log.error({ fail: 'parse', point: 'guide-parse', file: path, err });
|
|
225
|
+
if (err.uxmsg$) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
err.rooterrs$ = root.err;
|
|
230
|
+
throw err;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
243
233
|
}
|
|
244
234
|
let genctx = new aontu_1.Context({ root });
|
|
245
235
|
const guide = spec.guideModel = root.gen(genctx);
|
|
@@ -255,14 +245,6 @@ guide: control: transform: openapi: order: \`
|
|
|
255
245
|
spec.guideModelPath = node_path_1.default.join(pathParts.dir, pathParts.name + '.json');
|
|
256
246
|
const updatedSrc = JSON.stringify(guide, null, 2);
|
|
257
247
|
writeChanged('guide-model', spec.guideModelPath, updatedSrc);
|
|
258
|
-
// console.log('APIDEF resolveGuide write', spec.guideModelPath, src !== updatedSrc)
|
|
259
|
-
// let existingSrc = ''
|
|
260
|
-
// if (fs.existsSync(spec.guideModelPath)) {
|
|
261
|
-
// existingSrc = fs.readFileSync(spec.guideModelPath, 'utf8')
|
|
262
|
-
// }
|
|
263
|
-
// if (existingSrc !== updatedSrc) {
|
|
264
|
-
// fs.writeFileSync(spec.guideModelPath, updatedSrc)
|
|
265
|
-
// }
|
|
266
248
|
return guide;
|
|
267
249
|
}
|
|
268
250
|
return {
|
package/dist/apidef.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apidef.js","sourceRoot":"","sources":["../src/apidef.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"apidef.js","s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MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;YACxC,MAAM,GAAG,GAAQ,IAAI,KAAK,CAAC,sBAAsB;gBAC/C,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAO,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;YACnD,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;YAC5D,GAAG,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,CAAA;YAC3B,MAAM,GAAG,CAAA;QACX,CAAC;QAED,MAAM,SAAS,GAAG,mBAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,mBAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,CAAC,IAAI,GAAG,OAAO,CAAC,CAAA;QAExE,MAAM,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;QAEjD,YAAY,CAAC,aAAa,EAAE,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC,CAAA;QAE5D,OAAO,KAAK,CAAA;IACd,CAAC;IAGD,OAAO;QACL,KAAK;QACL,QAAQ;KACT,CAAA;AACH,CAAC"}
|
package/dist/transform.js
CHANGED
|
@@ -32,7 +32,7 @@ async function resolveTransforms(ctx) {
|
|
|
32
32
|
.split(/\s*,\s*/)
|
|
33
33
|
.map((t) => t.trim())
|
|
34
34
|
.filter((t) => '' != t);
|
|
35
|
-
log.info({
|
|
35
|
+
log.info({ point: 'transform', note: 'order', order: transformNames });
|
|
36
36
|
for (const tn of transformNames) {
|
|
37
37
|
log.debug({ what: 'transform', transform: tn });
|
|
38
38
|
const transform = await resolveTransform(tn, ctx);
|
package/dist/transform.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;;AA6L1C,0BAAO;AACP,8CAAiB;AACjB,8CAAiB;AA5LnB,0DAA4B;AAE5B,uCAA+C;AAG/C,yCAA8C;AAC9C,+CAAoD;AACpD,qDAA0D;AAC1D,6CAAkD;AAClD,+CAAoD;AAoCpD,MAAM,SAAS,GAA8B;IAC3C,GAAG,EAAE,kBAAY;IACjB,MAAM,EAAE,wBAAe;IACvB,SAAS,EAAE,8BAAkB;IAC7B,KAAK,EAAE,sBAAc;IACrB,MAAM,EAAE,wBAAe;CACxB,CAAA;AAKD,KAAK,UAAU,iBAAiB,CAAC,GAAiB;IAChD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,GAAG,CAAA;IAErC,MAAM,KAAK,GAAkB;QAC3B,SAAS,EAAE,EAAE;KACd,CAAA;IAED,qBAAqB;IACrB,MAAM,OAAO,GAAG,SAAS,CAAA;IACzB,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK;SAC1D,KAAK,CAAC,SAAS,CAAC;SAChB,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5B,MAAM,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAA;IAEjC,GAAG,CAAC,IAAI,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"transform.js","sourceRoot":"","sources":["../src/transform.ts"],"names":[],"mappings":";AAAA,4CAA4C;;;;;AA6L1C,0BAAO;AACP,8CAAiB;AACjB,8CAAiB;AA5LnB,0DAA4B;AAE5B,uCAA+C;AAG/C,yCAA8C;A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;;;;;;EAOE;AAGF,SAAS,OAAO,CAAC,IAAS,EAAE,IAAY,EAAE,IAAI,GAAG,MAAM;IACrD,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;IAC7C,IAAI,CAAC,IAAA,mBAAQ,EAAC,IAAI,CAAC,CAAC,GAAG,IAAA,mBAAQ,EAAC,IAAI,CAAC,CAAA;IACrC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAA;AAC/C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/apidef",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"main": "dist/apidef.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/apidef.d.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"url": "git://github.com/voxgig/apidef.git"
|
|
17
17
|
},
|
|
18
18
|
"bin": {
|
|
19
|
-
"apidef": "bin/
|
|
19
|
+
"voxgig-apidef": "bin/voxgig-apidef"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "node --enable-source-maps --test dist-test",
|
|
@@ -41,20 +41,21 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@hapi/code": "^9.0.3",
|
|
43
43
|
"@types/js-yaml": "^4.0.9",
|
|
44
|
-
"@types/node": "22.
|
|
45
|
-
"aontu": "^0.
|
|
44
|
+
"@types/node": "22.9.0",
|
|
45
|
+
"aontu": "^0.25.1",
|
|
46
46
|
"esbuild": "^0.24.0",
|
|
47
47
|
"json-schema-to-ts": "^3.1.1",
|
|
48
48
|
"memfs": "^4.14.0",
|
|
49
49
|
"typescript": "^5.6.3"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@redocly/openapi-core": "^1.25.
|
|
52
|
+
"@redocly/openapi-core": "^1.25.11",
|
|
53
|
+
"@voxgig/util": "^0.0.5",
|
|
53
54
|
"chokidar": "^4.0.1",
|
|
54
55
|
"gubu": "^8.3.0",
|
|
55
|
-
"jostraca": "^0.
|
|
56
|
+
"jostraca": "^0.8.0",
|
|
56
57
|
"pino": "^9.5.0",
|
|
57
|
-
"pino-pretty": "^
|
|
58
|
+
"pino-pretty": "^13.0.0",
|
|
58
59
|
"sonic-boom": "^4.2.0"
|
|
59
60
|
}
|
|
60
61
|
}
|
package/src/apidef.ts
CHANGED
|
@@ -7,10 +7,8 @@ import Path from 'node:path'
|
|
|
7
7
|
import { bundleFromString, createConfig } from '@redocly/openapi-core'
|
|
8
8
|
import { FSWatcher } from 'chokidar'
|
|
9
9
|
import { Aontu, Context } from 'aontu'
|
|
10
|
-
import Pino from 'pino'
|
|
11
|
-
import PinoPretty from 'pino-pretty'
|
|
12
|
-
|
|
13
10
|
|
|
11
|
+
import { prettyPino, Pino } from '@voxgig/util'
|
|
14
12
|
|
|
15
13
|
|
|
16
14
|
import {
|
|
@@ -32,33 +30,18 @@ type ApiDefSpec = {
|
|
|
32
30
|
model: string,
|
|
33
31
|
kind: string,
|
|
34
32
|
meta: Record<string, any>,
|
|
33
|
+
guide: any
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
|
|
38
37
|
function ApiDef(opts: ApiDefOptions = {}) {
|
|
39
38
|
const fs = opts.fs || Fs
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (null == pino) {
|
|
43
|
-
let pretty = PinoPretty({ sync: true })
|
|
44
|
-
const level = null == opts.debug ? 'info' :
|
|
45
|
-
true === opts.debug ? 'debug' :
|
|
46
|
-
'string' == typeof opts.debug ? opts.debug :
|
|
47
|
-
'info'
|
|
48
|
-
|
|
49
|
-
pino = Pino({
|
|
50
|
-
name: 'apidef',
|
|
51
|
-
level,
|
|
52
|
-
},
|
|
53
|
-
pretty
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
39
|
+
const pino = prettyPino('apidef', opts)
|
|
57
40
|
|
|
58
41
|
const log = pino.child({ cmp: 'apidef' })
|
|
59
42
|
|
|
60
43
|
|
|
61
|
-
async function watch(spec:
|
|
44
|
+
async function watch(spec: ApiDefSpec) {
|
|
62
45
|
log.info({ point: 'watch-start' })
|
|
63
46
|
log.debug({ point: 'watch-spec', spec })
|
|
64
47
|
|
|
@@ -74,7 +57,7 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
74
57
|
log.trace({ watch: 'add', what: 'def', file: spec.def })
|
|
75
58
|
fsw.add(spec.def)
|
|
76
59
|
|
|
77
|
-
log.trace({ watch: 'add', what: 'guide', file: spec.
|
|
60
|
+
log.trace({ watch: 'add', what: 'guide', file: spec.guide })
|
|
78
61
|
fsw.add(spec.guide)
|
|
79
62
|
}
|
|
80
63
|
|
|
@@ -82,7 +65,11 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
82
65
|
async function generate(spec: ApiDefSpec) {
|
|
83
66
|
const start = Date.now()
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
// TODO: validate spec
|
|
69
|
+
|
|
70
|
+
const defpath = Path.normalize(spec.def)
|
|
71
|
+
|
|
72
|
+
log.info({ point: 'generate-start', note: 'defpath', defpath, start })
|
|
86
73
|
log.debug({ point: 'generate-spec', spec })
|
|
87
74
|
|
|
88
75
|
// TODO: Validate spec
|
|
@@ -92,10 +79,18 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
92
79
|
guide: {},
|
|
93
80
|
opts,
|
|
94
81
|
util: { fixName },
|
|
95
|
-
defpath: Path.dirname(
|
|
82
|
+
defpath: Path.dirname(defpath)
|
|
96
83
|
}
|
|
97
84
|
|
|
85
|
+
|
|
86
|
+
|
|
98
87
|
const guide = await resolveGuide(spec, opts)
|
|
88
|
+
|
|
89
|
+
if (null == guide) {
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
99
94
|
log.debug({ point: 'guide', guide })
|
|
100
95
|
|
|
101
96
|
ctx.guide = guide
|
|
@@ -108,7 +103,7 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
108
103
|
source = fs.readFileSync(spec.def, 'utf8')
|
|
109
104
|
}
|
|
110
105
|
catch (err: any) {
|
|
111
|
-
log.error({ read: 'fail', what: 'def', file:
|
|
106
|
+
log.error({ read: 'fail', what: 'def', file: defpath, err })
|
|
112
107
|
throw err
|
|
113
108
|
}
|
|
114
109
|
|
|
@@ -124,7 +119,7 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
124
119
|
})
|
|
125
120
|
}
|
|
126
121
|
catch (err: any) {
|
|
127
|
-
log.error({ parse: 'fail', what: 'openapi', file:
|
|
122
|
+
log.error({ parse: 'fail', what: 'openapi', file: defpath, err })
|
|
128
123
|
throw err
|
|
129
124
|
}
|
|
130
125
|
|
|
@@ -171,23 +166,7 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
171
166
|
|
|
172
167
|
writeChanged('def-model', defFilePath, modelDefSrc)
|
|
173
168
|
|
|
174
|
-
|
|
175
|
-
let existingSrc: string = ''
|
|
176
|
-
if (fs.existsSync(defFilePath)) {
|
|
177
|
-
existingSrc = fs.readFileSync(defFilePath, 'utf8')
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
let writeModelDef = existingSrc !== modelDefSrc
|
|
181
|
-
// console.log('APIDEF', writeModelDef)
|
|
182
|
-
|
|
183
|
-
// Only write the model def if it has changed
|
|
184
|
-
if (writeModelDef) {
|
|
185
|
-
fs.writeFileSync(
|
|
186
|
-
defFilePath,
|
|
187
|
-
modelDefSrc
|
|
188
|
-
)
|
|
189
|
-
}
|
|
190
|
-
*/
|
|
169
|
+
log.info({ point: 'generate-end', note: 'success', break: true })
|
|
191
170
|
|
|
192
171
|
return {
|
|
193
172
|
ok: true,
|
|
@@ -203,6 +182,8 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
203
182
|
let action = ''
|
|
204
183
|
try {
|
|
205
184
|
let existingContent: string = ''
|
|
185
|
+
path = Path.normalize(path)
|
|
186
|
+
|
|
206
187
|
exists = fs.existsSync(path)
|
|
207
188
|
|
|
208
189
|
if (exists) {
|
|
@@ -213,6 +194,8 @@ function ApiDef(opts: ApiDefOptions = {}) {
|
|
|
213
194
|
changed = existingContent !== content
|
|
214
195
|
|
|
215
196
|
log.info({
|
|
197
|
+
point: 'write-' + what,
|
|
198
|
+
note: 'changed,file',
|
|
216
199
|
write: 'file', what, skip: !changed, exists, changed,
|
|
217
200
|
contentLength: content.length, file: path
|
|
218
201
|
})
|
|
@@ -282,17 +265,29 @@ guide: control: transform: openapi: order: \`
|
|
|
282
265
|
throw err
|
|
283
266
|
}
|
|
284
267
|
|
|
285
|
-
|
|
286
268
|
const aopts = { path }
|
|
287
269
|
const root = Aontu(src, aopts)
|
|
288
270
|
const hasErr = root.err && 0 < root.err.length
|
|
289
271
|
|
|
290
272
|
if (hasErr) {
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
273
|
+
for (let serr of root.err) {
|
|
274
|
+
let err: any = new Error('Guide model: ' + serr.msg)
|
|
275
|
+
err.cause$ = [serr]
|
|
276
|
+
|
|
277
|
+
if ('syntax' === serr.why) {
|
|
278
|
+
err.uxmsg$ = true
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
log.error({ fail: 'parse', point: 'guide-parse', file: path, err })
|
|
282
|
+
|
|
283
|
+
if (err.uxmsg$) {
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
err.rooterrs$ = root.err
|
|
288
|
+
throw err
|
|
289
|
+
}
|
|
290
|
+
}
|
|
296
291
|
}
|
|
297
292
|
|
|
298
293
|
let genctx = new Context({ root })
|
|
@@ -314,16 +309,6 @@ guide: control: transform: openapi: order: \`
|
|
|
314
309
|
|
|
315
310
|
writeChanged('guide-model', spec.guideModelPath, updatedSrc)
|
|
316
311
|
|
|
317
|
-
// console.log('APIDEF resolveGuide write', spec.guideModelPath, src !== updatedSrc)
|
|
318
|
-
// let existingSrc = ''
|
|
319
|
-
// if (fs.existsSync(spec.guideModelPath)) {
|
|
320
|
-
// existingSrc = fs.readFileSync(spec.guideModelPath, 'utf8')
|
|
321
|
-
// }
|
|
322
|
-
|
|
323
|
-
// if (existingSrc !== updatedSrc) {
|
|
324
|
-
// fs.writeFileSync(spec.guideModelPath, updatedSrc)
|
|
325
|
-
// }
|
|
326
|
-
|
|
327
312
|
return guide
|
|
328
313
|
}
|
|
329
314
|
|
|
@@ -339,6 +324,7 @@ guide: control: transform: openapi: order: \`
|
|
|
339
324
|
|
|
340
325
|
export type {
|
|
341
326
|
ApiDefOptions,
|
|
327
|
+
ApiDefSpec,
|
|
342
328
|
}
|
|
343
329
|
|
|
344
330
|
|
package/src/transform.ts
CHANGED
|
@@ -71,7 +71,7 @@ async function resolveTransforms(ctx: TransformCtx): Promise<TransformSpec> {
|
|
|
71
71
|
.map((t: string) => t.trim())
|
|
72
72
|
.filter((t: string) => '' != t)
|
|
73
73
|
|
|
74
|
-
log.info({
|
|
74
|
+
log.info({ point: 'transform', note: 'order', order: transformNames })
|
|
75
75
|
|
|
76
76
|
for (const tn of transformNames) {
|
|
77
77
|
log.debug({ what: 'transform', transform: tn })
|
package/bin/run-apidef.js~
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const Path = require('node:path')
|
|
4
|
-
const { statSync } = require('node:fs')
|
|
5
|
-
const { parseArgs } = require('node:util')
|
|
6
|
-
|
|
7
|
-
const { Gubu, Fault } = require('gubu')
|
|
8
|
-
const { Aontu, Context } = require('aontu')
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const Pkg = require('../package.json')
|
|
12
|
-
|
|
13
|
-
const { CreateSdkGen } = require('../dist/create-sdkgen.js')
|
|
14
|
-
|
|
15
|
-
// const { Root } = require('../dist/standard/Root')
|
|
16
|
-
const rootpath = require.resolve('../dist/standard/Root')
|
|
17
|
-
|
|
18
|
-
let DEBUG = false
|
|
19
|
-
let CONSOLE = console
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
let options = resolveOptions()
|
|
24
|
-
|
|
25
|
-
if(options.debug) {
|
|
26
|
-
DEBUG = true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if(options.version) {
|
|
30
|
-
version()
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if(options.help) {
|
|
34
|
-
help()
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if(options.version || options.help) {
|
|
38
|
-
exit()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
options = validateOptions(options)
|
|
42
|
-
|
|
43
|
-
generate(options)
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
catch(err) {
|
|
47
|
-
handleError(err)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
function exit(err) {
|
|
53
|
-
let code = 0
|
|
54
|
-
if(err) {
|
|
55
|
-
code = 1
|
|
56
|
-
}
|
|
57
|
-
process.exit(code)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
function generate(options) {
|
|
62
|
-
const createSdkGen = CreateSdkGen({
|
|
63
|
-
folder: options.folder,
|
|
64
|
-
rootpath
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const model = resolveModel(options)
|
|
69
|
-
|
|
70
|
-
const spec = {
|
|
71
|
-
// TODO: move to CreateSdkGen options
|
|
72
|
-
spec: options.spec,
|
|
73
|
-
model,
|
|
74
|
-
// root: Root,
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if(options.watch) {
|
|
78
|
-
spec.watch = [
|
|
79
|
-
'../tm',
|
|
80
|
-
'../feature',
|
|
81
|
-
'../def',
|
|
82
|
-
'../dist',
|
|
83
|
-
]
|
|
84
|
-
createSdkGen.watch(spec)
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
createSdkGen.generate(spec)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
function resolveModel(options) {
|
|
94
|
-
|
|
95
|
-
const typespec = `
|
|
96
|
-
name: string
|
|
97
|
-
year: number
|
|
98
|
-
def: filepath: string
|
|
99
|
-
feature: &: {
|
|
100
|
-
active: *false | boolean
|
|
101
|
-
}
|
|
102
|
-
`
|
|
103
|
-
|
|
104
|
-
const features = options.feature.map(name=>`feature:${name}:active:true`)
|
|
105
|
-
|
|
106
|
-
const src = [
|
|
107
|
-
typespec,
|
|
108
|
-
`name: ${options.name}`,
|
|
109
|
-
`year: ${new Date().getFullYear()}`,
|
|
110
|
-
`def: filepath: "${options.def || 'def.yml'}"`,
|
|
111
|
-
'' === options.model ? '' : `@"${options.model}"`,
|
|
112
|
-
...(options.set||[]),
|
|
113
|
-
...(features||[]),
|
|
114
|
-
].join('\n')
|
|
115
|
-
const aopts = {}
|
|
116
|
-
const root = Aontu(src, aopts)
|
|
117
|
-
const hasErr = root.err && 0 < root.err.length
|
|
118
|
-
|
|
119
|
-
// TODO: collect all errors
|
|
120
|
-
if (hasErr) {
|
|
121
|
-
// console.log('ERROR ROOT', root.err)
|
|
122
|
-
throw root.err[0].msg
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
let genctx = new Context({ root })
|
|
126
|
-
const model = root.gen(genctx)
|
|
127
|
-
|
|
128
|
-
// TODO: collect all errors
|
|
129
|
-
if (genctx.err && 0 < genctx.err.length) {
|
|
130
|
-
// console.log(genctx.err)
|
|
131
|
-
// console.log('ERROR GEN', genctx.err)
|
|
132
|
-
throw new Error(JSON.stringify(genctx.err[0]))
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
model.def.filename = Path.basename(model.def.filepath)
|
|
136
|
-
|
|
137
|
-
// console.log('MODEL')
|
|
138
|
-
// console.dir(model,{depth:null})
|
|
139
|
-
|
|
140
|
-
return model
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
function resolveOptions() {
|
|
145
|
-
|
|
146
|
-
const args = parseArgs({
|
|
147
|
-
allowPositionals: true,
|
|
148
|
-
options: {
|
|
149
|
-
folder: {
|
|
150
|
-
type: 'string',
|
|
151
|
-
short: 'f',
|
|
152
|
-
default: '',
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
def: {
|
|
156
|
-
type: 'string',
|
|
157
|
-
short: 'd',
|
|
158
|
-
default: '',
|
|
159
|
-
},
|
|
160
|
-
|
|
161
|
-
set: {
|
|
162
|
-
type: 'string',
|
|
163
|
-
short: 's',
|
|
164
|
-
multiple: true,
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
model: {
|
|
168
|
-
type: 'string',
|
|
169
|
-
short: 'm',
|
|
170
|
-
default: '',
|
|
171
|
-
},
|
|
172
|
-
|
|
173
|
-
feature: {
|
|
174
|
-
type: 'string',
|
|
175
|
-
short: 't',
|
|
176
|
-
multiple: true,
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
watch: {
|
|
180
|
-
type: 'boolean',
|
|
181
|
-
short: 'w',
|
|
182
|
-
},
|
|
183
|
-
|
|
184
|
-
debug: {
|
|
185
|
-
type: 'boolean',
|
|
186
|
-
short: 'g',
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
help: {
|
|
190
|
-
type: 'boolean',
|
|
191
|
-
short: 'h',
|
|
192
|
-
},
|
|
193
|
-
|
|
194
|
-
version: {
|
|
195
|
-
type: 'boolean',
|
|
196
|
-
short: 'v',
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
const options = {
|
|
203
|
-
name: args.positionals[0],
|
|
204
|
-
folder: '' === args.values.folder ? args.positionals[0] : args.values.folder,
|
|
205
|
-
def: args.values.def,
|
|
206
|
-
model: args.values.model,
|
|
207
|
-
feature: args.values.feature,
|
|
208
|
-
set: args.values.set,
|
|
209
|
-
watch: !!args.values.watch,
|
|
210
|
-
debug: !!args.values.debug,
|
|
211
|
-
help: !!args.values.help,
|
|
212
|
-
version: !!args.values.version,
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
return options
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
function validateOptions(rawOptions) {
|
|
220
|
-
const optShape = Gubu({
|
|
221
|
-
name: Fault('The first argument should be the project name.', String),
|
|
222
|
-
folder: String,
|
|
223
|
-
def: '',
|
|
224
|
-
model: '',
|
|
225
|
-
feature: [String],
|
|
226
|
-
set: [String],
|
|
227
|
-
watch: Boolean,
|
|
228
|
-
debug: Boolean,
|
|
229
|
-
help: Boolean,
|
|
230
|
-
version: Boolean,
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
const err = []
|
|
234
|
-
const options = optShape(rawOptions,{err})
|
|
235
|
-
|
|
236
|
-
if(err[0]) {
|
|
237
|
-
throw new Error(err[0].text)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
if('' !== options.def) {
|
|
241
|
-
options.def = Path.resolve(options.def)
|
|
242
|
-
const stat = statSync(options.def, {throwIfNoEntry:false})
|
|
243
|
-
if(null == stat) {
|
|
244
|
-
throw new Error('Definition file not found: '+options.def)
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if('' !== options.model) {
|
|
249
|
-
options.model = Path.resolve(options.model)
|
|
250
|
-
const stat = statSync(options.model, {throwIfNoEntry:false})
|
|
251
|
-
if(null == stat) {
|
|
252
|
-
throw new Error('Model file not found: '+options.model)
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
return options
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
function handleError(err) {
|
|
261
|
-
CONSOLE.log('Voxgig SDK Generator Error:')
|
|
262
|
-
|
|
263
|
-
if(DEBUG) {
|
|
264
|
-
CONSOLE.log(err)
|
|
265
|
-
}
|
|
266
|
-
else {
|
|
267
|
-
CONSOLE.log(err.message)
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
exit(err)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
function version() {
|
|
275
|
-
CONSOLE.log(Pkg.version)
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
function help() {
|
|
280
|
-
let s = `
|
|
281
|
-
Create a Voxgig SDK Generator project.
|
|
282
|
-
|
|
283
|
-
Usage: npm create @voxgig/sdkgen@latest <name> <args>
|
|
284
|
-
|
|
285
|
-
where <name> is the name of the SDK project. This is also used to
|
|
286
|
-
create a project folder if one is not explictly defined using the -f
|
|
287
|
-
argument. If run against an existing folder generated files will be
|
|
288
|
-
overwritten.
|
|
289
|
-
|
|
290
|
-
<args> are the command arguments:
|
|
291
|
-
|
|
292
|
-
--folder <folder> Specific the folder for the SDK project. Optional.
|
|
293
|
-
-f <folder> Default: <name> in current folder.
|
|
294
|
-
|
|
295
|
-
--def <file> Specify the API definition file (OpenAPI, Swagger, etc)
|
|
296
|
-
-d that defines the SDK. Optional.
|
|
297
|
-
|
|
298
|
-
--model <file> Specify the SDK model file to customize the SDK. Optional.
|
|
299
|
-
-m
|
|
300
|
-
|
|
301
|
-
--watch Run in watch mode. The SDK project will be updated if any of the
|
|
302
|
-
-w project inputs (such as the spec file) change.
|
|
303
|
-
|
|
304
|
-
--debug Print verbose logging.
|
|
305
|
-
-d
|
|
306
|
-
|
|
307
|
-
--help Print this help message.
|
|
308
|
-
-h
|
|
309
|
-
|
|
310
|
-
--version Print version number.
|
|
311
|
-
-v
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
Examples:
|
|
315
|
-
|
|
316
|
-
# Basic usage
|
|
317
|
-
> npm create @voxgig/sdkgen@latest foo
|
|
318
|
-
# Creates the SDK Project in the folder ./foo
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
# Custom project folder
|
|
322
|
-
> npm create @voxgig/sdkgen@latest foo -f ~/Projects/Foo
|
|
323
|
-
# Creates the SDK Project in the folder ~/Projects/Foo
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
See also: https://voxgig.com/sdkgen
|
|
327
|
-
`
|
|
328
|
-
|
|
329
|
-
CONSOLE.log(s)
|
|
330
|
-
}
|