-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen-openapi.ts
32 lines (29 loc) · 959 Bytes
/
gen-openapi.ts
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
import * as OAPI from "./openapi/openapi-utils.ts";
import { fs, path } from "./deps.ts";
import { parseAdl } from "./utils/adl.ts";
import * as adlast from "./adl-gen/runtime/sys/adlast.ts";
export interface Params {
adlFiles: string[];
searchPath: string[];
apiModule: string;
apiName: string;
outputFile: string;
verbose?: boolean;
}
export async function genOpenApi(params: Params): Promise<void> {
const loadedAdl = await parseAdl(params.adlFiles, params.searchPath, {
verbose: params.verbose,
});
const schema = OAPI.schemaFromApi({
moduleName: params.apiModule,
name: params.apiName,
}, loadedAdl);
const text = params.outputFile.endsWith(".json")
? JSON.stringify(schema, null, 2)
: OAPI.yamlFromJsonSchema(schema);
await fs.ensureDir(path.dirname(params.outputFile));
if (params.verbose) {
console.log(`writing ${params.outputFile}...`);
}
await Deno.writeTextFile(params.outputFile, text);
}