fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #361 from hey-api/chore/cleanup-typescript-file

chore: instanciate typescript file with path

authored by

Lubos and committed by
GitHub
a4b0c22f 935270b8

+15 -18
+10 -13
packages/openapi-ts/src/compiler/index.ts
··· 15 15 private _headers: Array<string> = []; 16 16 private _imports: Array<ts.Node> = []; 17 17 private _items: Array<ts.Node | string> = []; 18 - private _path: string = ''; 18 + private _path: string; 19 + 20 + public constructor(path: string, header: boolean = true) { 21 + this._path = path; 22 + if (header) { 23 + const text = 'This file is auto-generated by @hey-api/openapi-ts'; 24 + const comment = addLeadingComment(undefined, [text], true, false); 25 + this._headers = [...this._headers, comment]; 26 + } 27 + } 19 28 20 29 public add(...nodes: Array<ts.Node | string>): void { 21 30 this._items = [...this._items, ...nodes]; 22 31 } 23 32 24 - public addHeader() { 25 - const text = 'This file is auto-generated by @hey-api/openapi-ts'; 26 - const comment = addLeadingComment(undefined, [text], true, false); 27 - this._headers = [...this._headers, comment]; 28 - return this; 29 - } 30 - 31 33 public addNamedImport(...params: Parameters<typeof module.createNamedImportDeclarations>): void { 32 34 this._imports = [...this._imports, compiler.import.named(...params)]; 33 - } 34 - 35 - public setPath(path: string) { 36 - this._path = path; 37 - return this; 38 35 } 39 36 40 37 public toString(seperator: string = '\n') {
+1 -1
packages/openapi-ts/src/utils/write/index.ts
··· 13 13 export const writeClientIndex = async (client: Client, outputPath: string): Promise<void> => { 14 14 const config = getConfig(); 15 15 16 - const fileIndex = new TypeScriptFile().setPath(path.resolve(outputPath, 'index.ts')).addHeader(); 16 + const fileIndex = new TypeScriptFile(path.resolve(outputPath, 'index.ts')); 17 17 18 18 if (config.name) { 19 19 fileIndex.add(compiler.export.named([config.name], `./${config.name}`));
+2 -2
packages/openapi-ts/src/utils/write/models.ts
··· 225 225 export const writeTypesAndEnums = async (openApi: OpenApi, outputPath: string, client: Client): Promise<void> => { 226 226 const config = getConfig(); 227 227 228 - const fileEnums = new TypeScriptFile().setPath(path.resolve(outputPath, 'enums.gen.ts')).addHeader(); 229 - const fileModels = new TypeScriptFile().setPath(path.resolve(outputPath, 'models.ts')).addHeader(); 228 + const fileEnums = new TypeScriptFile(path.resolve(outputPath, 'enums.gen.ts')); 229 + const fileModels = new TypeScriptFile(path.resolve(outputPath, 'models.ts')); 230 230 231 231 for (const model of client.models) { 232 232 processModel(client, model, (node, type) => {
+1 -1
packages/openapi-ts/src/utils/write/schemas.ts
··· 13 13 export const writeSchemas = async (openApi: OpenApi, outputPath: string): Promise<void> => { 14 14 const config = getConfig(); 15 15 16 - const fileSchemas = new TypeScriptFile().setPath(path.resolve(outputPath, 'schemas.ts')).addHeader(); 16 + const fileSchemas = new TypeScriptFile(path.resolve(outputPath, 'schemas.ts')); 17 17 18 18 const addSchema = (name: string, obj: any) => { 19 19 const validName = `$${ensureValidTypeScriptJavaScriptIdentifier(name)}`;
+1 -1
packages/openapi-ts/src/utils/write/services.ts
··· 22 22 ): Promise<void> => { 23 23 const config = getConfig(); 24 24 25 - const fileServices = new TypeScriptFile().setPath(path.resolve(outputPath, 'services.ts')).addHeader(); 25 + const fileServices = new TypeScriptFile(path.resolve(outputPath, 'services.ts')); 26 26 27 27 let imports: string[] = []; 28 28 let results: string[] = [];