@@ -61,36 +61,46 @@ const validateCompilerOptions = (config?: ts.CompilerOptions): ts.CompilerOption
61
61
} ;
62
62
63
63
export const validateSwaggerConfig = async ( config : SwaggerConfig ) : Promise < SwaggerConfig > => {
64
- if ( ! config . outputDirectory ) { throw new Error ( 'Missing outputDirectory: configuration must contain output directory.' ) ; }
65
- if ( ! config . entryFile ) { throw new Error ( 'Missing entryFile: Configuration must contain an entry point file.' ) ; }
66
- if ( ! await fsExists ( config . entryFile ) ) {
64
+ if ( ! config . outputDirectory ) {
65
+ throw new Error ( 'Missing outputDirectory: configuration must contain output directory.' ) ;
66
+ }
67
+ if ( ! config . entryFile ) {
68
+ throw new Error ( 'Missing entryFile: Configuration must contain an entry point file.' ) ;
69
+ }
70
+ if ( ! ( await fsExists ( config . entryFile ) ) ) {
67
71
throw new Error ( `EntryFile not found: ${ config . entryFile } - Please check your tsoa config.` ) ;
68
72
}
69
- config . version = config . version || await versionDefault ( ) ;
73
+ config . version = config . version || ( await versionDefault ( ) ) ;
70
74
71
75
config . specVersion = config . specVersion || 2 ;
72
- if ( config . specVersion !== 2 && config . specVersion !== 3 ) { throw new Error ( 'Unsupported Spec version.' ) ; }
76
+ if ( config . specVersion !== 2 && config . specVersion !== 3 ) {
77
+ throw new Error ( 'Unsupported Spec version.' ) ;
78
+ }
73
79
74
- config . name = config . name || await nameDefault ( ) ;
75
- config . description = config . description || await descriptionDefault ( ) ;
76
- config . license = config . license || await licenseDefault ( ) ;
80
+ config . name = config . name || ( await nameDefault ( ) ) ;
81
+ config . description = config . description || ( await descriptionDefault ( ) ) ;
82
+ config . license = config . license || ( await licenseDefault ( ) ) ;
77
83
config . basePath = config . basePath || '/' ;
78
84
79
85
return config ;
80
86
} ;
81
87
82
88
const validateRoutesConfig = async ( config : RoutesConfig ) : Promise < RoutesConfig > => {
83
- if ( ! config . entryFile ) { throw new Error ( 'Missing entryFile: Configuration must contain an entry point file.' ) ; }
84
- if ( ! await fsExists ( config . entryFile ) ) {
89
+ if ( ! config . entryFile ) {
90
+ throw new Error ( 'Missing entryFile: Configuration must contain an entry point file.' ) ;
91
+ }
92
+ if ( ! ( await fsExists ( config . entryFile ) ) ) {
85
93
throw new Error ( `EntryFile not found: ${ config . entryFile } - Please check your tsoa config.` ) ;
86
94
}
87
- if ( ! config . routesDir ) { throw new Error ( 'Missing routesDir: Configuration must contain a routes file output directory.' ) ; }
95
+ if ( ! config . routesDir ) {
96
+ throw new Error ( 'Missing routesDir: Configuration must contain a routes file output directory.' ) ;
97
+ }
88
98
89
- if ( config . authenticationModule && ! ( await fsExists ( config . authenticationModule ) || await fsExists ( config . authenticationModule + '.ts' ) ) ) {
99
+ if ( config . authenticationModule && ! ( ( await fsExists ( config . authenticationModule ) ) || ( await fsExists ( config . authenticationModule + '.ts' ) ) ) ) {
90
100
throw new Error ( `No authenticationModule file found at '${ config . authenticationModule } '` ) ;
91
101
}
92
102
93
- if ( config . iocModule && ! ( await fsExists ( config . iocModule ) || await fsExists ( config . iocModule + '.ts' ) ) ) {
103
+ if ( config . iocModule && ! ( ( await fsExists ( config . iocModule ) ) || ( await fsExists ( config . iocModule + '.ts' ) ) ) ) {
94
104
throw new Error ( `No iocModule file found at '${ config . iocModule } '` ) ;
95
105
}
96
106
@@ -134,20 +144,29 @@ const jsonArgs: yargs.Options = {
134
144
yargs
135
145
. usage ( 'Usage: $0 <command> [options]' )
136
146
. demand ( 1 )
137
- . command ( 'swagger' , 'Generate swagger spec' , {
138
- basePath : basePathArgs ,
139
- configuration : configurationArgs ,
140
- host : hostArgs ,
141
- json : jsonArgs ,
142
- yaml : yarmlArgs ,
143
- } , swaggerSpecGenerator )
144
- . command ( 'routes' , 'Generate routes' , {
145
- basePath : basePathArgs ,
146
- configuration : configurationArgs ,
147
- } , routeGenerator )
147
+ . command (
148
+ 'swagger' ,
149
+ 'Generate swagger spec' ,
150
+ {
151
+ basePath : basePathArgs ,
152
+ configuration : configurationArgs ,
153
+ host : hostArgs ,
154
+ json : jsonArgs ,
155
+ yaml : yarmlArgs ,
156
+ } ,
157
+ swaggerSpecGenerator ,
158
+ )
159
+ . command (
160
+ 'routes' ,
161
+ 'Generate routes' ,
162
+ {
163
+ basePath : basePathArgs ,
164
+ configuration : configurationArgs ,
165
+ } ,
166
+ routeGenerator ,
167
+ )
148
168
. help ( 'help' )
149
- . alias ( 'help' , 'h' )
150
- . argv ;
169
+ . alias ( 'help' , 'h' ) . argv ;
151
170
152
171
async function swaggerSpecGenerator ( args ) {
153
172
try {
0 commit comments