This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: split TypeScriptOpenAPIBuilder into a file
- Loading branch information
1 parent
e0459ab
commit bd80547
Showing
2 changed files
with
43 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { DocumentBuilder } from './scan/document-builder'; | ||
import { OpenAPIObject } from './interfaces'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import Builders from './builders'; | ||
import Spec from './spec'; | ||
|
||
export class TypeScriptOpenAPIBuilder { | ||
private static walk(directory: string, callback: (filePath: string) => void): void { | ||
fs.readdirSync(directory).forEach(function (name) { | ||
var filePath = path.join(directory, name); | ||
var stat = fs.statSync(filePath); | ||
if (stat.isFile()) { | ||
callback(filePath); | ||
} else if (stat.isDirectory()) { | ||
this.walkSync(filePath, callback); | ||
} | ||
}); | ||
} | ||
|
||
private static getAllFilesInDir(directory: string, regex: RegExp): string[] { | ||
const files: string[] = []; | ||
this.walk(directory, (filePath) => { | ||
if (filePath.match(regex)) { | ||
files.push(filePath); | ||
} | ||
}); | ||
return files; | ||
} | ||
|
||
public static buildSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): OpenAPIObject { | ||
const filesToScan = this.getAllFilesInDir(directory, fileRegex); | ||
const metas = Builders.buildMetaForFiles(filesToScan); | ||
return Spec.buildSpecFromCollectedMeta(metas, document); | ||
} | ||
|
||
public static buildJsonSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): string { | ||
return JSON.stringify(this.buildSpec(document, directory, fileRegex)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,4 @@ | ||
import { DocumentBuilder } from './scan/document-builder'; | ||
import { OpenAPIObject } from './interfaces'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import Builders from './builders'; | ||
import Spec from './spec'; | ||
|
||
export { DocumentBuilder } from './scan/document-builder'; | ||
|
||
export class TypeScriptOpenAPIBuilder { | ||
private static walk(directory: string, callback: (filePath: string) => void): void { | ||
fs.readdirSync(directory).forEach(function (name) { | ||
var filePath = path.join(directory, name); | ||
var stat = fs.statSync(filePath); | ||
if (stat.isFile()) { | ||
callback(filePath); | ||
} else if (stat.isDirectory()) { | ||
this.walkSync(filePath, callback); | ||
} | ||
}); | ||
} | ||
|
||
private static getAllFilesInDir(directory: string, regex: RegExp): string[] { | ||
const files: string[] = []; | ||
this.walk(directory, (filePath) => { | ||
if (filePath.match(regex)) { | ||
files.push(filePath); | ||
} | ||
}); | ||
return files; | ||
} | ||
|
||
public static buildSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): OpenAPIObject { | ||
const filesToScan = this.getAllFilesInDir(directory, fileRegex); | ||
const metas = Builders.buildMetaForFiles(filesToScan); | ||
return Spec.buildSpecFromCollectedMeta(metas, document); | ||
} | ||
|
||
public static buildJsonSpec(document: DocumentBuilder, directory: string, fileRegex: RegExp): string { | ||
return JSON.stringify(this.buildSpec(document, directory, fileRegex)); | ||
} | ||
} | ||
export { TypeScriptOpenAPIBuilder } from './TypeScriptOpenAPIBuilder'; | ||
export * as decorators from './decorators'; | ||
export * as interfaces from './interfaces'; |