Skip to content

Commit 8fcdea5

Browse files
Added parameter --save-file
1 parent 45f697d commit 8fcdea5

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.history
3-
node_modules
4-
dist
53
build
4+
dist
5+
node_modules
6+
openapi_temp*
67
output

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
dist
44
examples
55
node_modules
6+
openapi_temp*
67
output

src/models/config.model.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { resolve as pathResolve } from 'path';
33
import { TemplateConfigModel } from './template-config.model';
44

55
export interface ConfigI {
6+
tempFilePath: string;
67
outputPath: string;
78
readonly exportPath: string;
89
readonly outputModelsPath: string;
@@ -12,6 +13,7 @@ export interface ConfigI {
1213
}
1314

1415
class ConfigModel implements ConfigI {
16+
private _tempFilePath: string;
1517
private _outputPath: string;
1618
private _outputBaseFolder: string = '';
1719
private _outputModelsFolder: string = 'models';
@@ -37,6 +39,14 @@ class ConfigModel implements ConfigI {
3739
return pathResolve(this.exportPath, this._outputApisFolder);
3840
}
3941

42+
get tempFilePath(): string {
43+
return this._tempFilePath;
44+
}
45+
46+
set tempFilePath(tempFilePath: string) {
47+
this._tempFilePath = tempFilePath;
48+
}
49+
4050
get template(): string {
4151
if (!this._template) {
4252
throw 'No template defined';
@@ -84,6 +94,7 @@ class ConfigModel implements ConfigI {
8494

8595
parseYargs(yargs): void {
8696
this._outputPath = yargs.outputFolder;
97+
this.tempFilePath = pathResolve(yargs.saveFile);
8798
this.template = yargs.template;
8899
}
89100
}

src/services/arguments.service.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,38 @@ export const argumentsInstance = yargs
88
'$0 -f swagger.js -o api/ -t angular2',
99
'Convert a Swagger JSON file to compatible-angular API',
1010
)
11+
12+
.nargs('save-file', 1)
13+
.alias('s', 'file')
14+
.describe('file', 'Path to save the file IF --file IS AN URL (without extension)')
15+
.default('save-file', './openapi_temp')
16+
1117
.nargs('file', 1)
1218
.alias('f', 'file')
1319
.describe('file', 'Path OR URL to the swagger document to parse')
1420
.demandOption(['file'])
21+
1522
.alias('o', 'output-folder')
1623
.nargs('output-folder', 1)
24+
1725
.nargs('template', 1)
1826
.alias('t', 'template')
1927
.describe('template', 'Template (preset) name or path to a template')
28+
2029
.implies('file', 'output-folder')
2130
.implies('file', 'template')
2231
.describe(
2332
'output-folder',
2433
'Specify the output folder (generated folders will be replaced)',
2534
)
2635
.default('output-folder', 'output')
36+
2737
.boolean('clean')
2838
.describe('clean', 'No clean the output-folder, so old files will remain')
2939
.default('clean', true)
40+
3041
.help('help')
3142
.alias('h', 'help')
43+
3244
.epilog('For more info visit: https://github.com/ProtocolNebula/ts-openapi-generator/')
3345
.argv;

src/services/parsers/file-reader.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class FileReaderService {
6161
}
6262

6363
if (isURL(this.path)) {
64-
this.localFilePath = `${this.configuration.outputPath}temp.${extension}`;
64+
this.localFilePath = `${this.configuration.tempFilePath}.${extension}`;
6565
console.log(`${this.path} will be saved as ${this.localFilePath}...`);
6666
await downloadFile(this.path, this.localFilePath);
6767
console.log(`${this.localFilePath} saved!`);

0 commit comments

Comments
 (0)