|
1 | | -import { DocumentBuilder } from './scan/document-builder'; |
2 | | -import { OpenAPIObject } from './interfaces'; |
3 | | -import * as fs from 'fs'; |
4 | | -import * as path from 'path'; |
5 | | -import Builders from './builders'; |
6 | | -import Spec from './spec'; |
7 | | - |
8 | 1 | export { DocumentBuilder } from './scan/document-builder'; |
9 | | - |
10 | | -export class TypeScriptOpenAPIBuilder { |
11 | | - private static walk(directory: string, callback: (filePath: string) => void): void { |
12 | | - fs.readdirSync(directory).forEach(function (name) { |
13 | | - var filePath = path.join(directory, name); |
14 | | - var stat = fs.statSync(filePath); |
15 | | - if (stat.isFile()) { |
16 | | - callback(filePath); |
17 | | - } else if (stat.isDirectory()) { |
18 | | - this.walkSync(filePath, callback); |
19 | | - } |
20 | | - }); |
21 | | - } |
22 | | - |
23 | | - private static getAllFilesInDir(directory: string, regex: RegExp): string[] { |
24 | | - const files: string[] = []; |
25 | | - this.walk(directory, (filePath) => { |
26 | | - if (filePath.match(regex)) { |
27 | | - files.push(filePath); |
28 | | - } |
29 | | - }); |
30 | | - return files; |
31 | | - } |
32 | | - |
33 | | - public static buildSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): OpenAPIObject { |
34 | | - const filesToScan = this.getAllFilesInDir(directory, fileRegex); |
35 | | - const metas = Builders.buildMetaForFiles(filesToScan); |
36 | | - return Spec.buildSpecFromCollectedMeta(metas, document); |
37 | | - } |
38 | | - |
39 | | - public static buildJsonSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): string { |
40 | | - return JSON.stringify(this.buildSpec(document, directory, fileRegex)); |
41 | | - } |
42 | | -} |
| 2 | +export { TypeScriptOpenAPIBuilder } from './TypeScriptOpenAPIBuilder'; |
| 3 | +export * as decorators from './decorators'; |
| 4 | +export * as interfaces from './interfaces'; |
0 commit comments