-
Notifications
You must be signed in to change notification settings - Fork 3
/
openApiTypeGenerator.ts
23 lines (22 loc) · 1 KB
/
openApiTypeGenerator.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { compile } from 'json-schema-to-typescript';
import openApi from './src/swagger.js';
import clipboard from "clipboardy";
// example call - yarn swag-type log
(async(object, name) => {
const args = process.argv;
const o = (object) ? object : args[2];
const n = (name) ? name : args[3];
if(!o) {
console.error('MISSING ARGUMENTS --', 'First argument should be the object from your swagger spec within component/schemas', 'Second argument should be what you would like to call this type.')
process.exit(1);
}
if(!n) {
console.error('MISSING ARGUMENTS --', 'Second argument should be what you would like to call this type.')
process.exit(1);
}
const swagger = await openApi.init();
const swaggerObject = swagger.components.schemas[o];
const ts = await compile(swaggerObject, n)
clipboard.writeSync(ts);
console.info('SUCCESS! - the above type definition is in your clipboard. Simply go to the file you wish and paste it in to modify');
})()