@@ -29,7 +29,7 @@ export class GeneratorService {
2929 ) {
3030 }
3131
32- public async generate ( ...keys : string [ ] ) {
32+ public async generate ( customGenerator ?: string , ...keys : string [ ] ) {
3333
3434 const cwd = this . configService . cwd
3535 const generators = Object . entries ( this . configService . get < { [ name : string ] : GeneratorConfig } > ( this . configPath , { } ) )
@@ -54,7 +54,7 @@ export class GeneratorService {
5454 if ( ! globPattern ) {
5555 return [ {
5656 name : `[${ name } ] ${ params . inputSpec } ` ,
57- command : this . buildCommand ( cwd , params )
57+ command : this . buildCommand ( cwd , params , customGenerator )
5858 } ]
5959 }
6060
@@ -66,7 +66,7 @@ export class GeneratorService {
6666
6767 return glob . sync ( globPattern , { cwd} ) . map ( spec => ( {
6868 name : `[${ name } ] ${ spec } ` ,
69- command : this . buildCommand ( cwd , params , spec )
69+ command : this . buildCommand ( cwd , params , customGenerator , spec )
7070 } ) )
7171 } ) )
7272
@@ -95,7 +95,7 @@ export class GeneratorService {
9595 } ) . join ( '\n' ) )
9696 }
9797
98- private buildCommand ( cwd : string , params : Record < string , unknown > , specFile ?: string ) {
98+ private buildCommand ( cwd : string , params : Record < string , unknown > , customGenerator ?: string , specFile ?: string ) {
9999 const absoluteSpecPath = specFile ? path . resolve ( cwd , specFile ) : String ( params . inputSpec )
100100
101101 const command = Object . entries ( {
@@ -139,19 +139,26 @@ export class GeneratorService {
139139 ext : ext . split ( '.' ) . slice ( - 1 ) . pop ( )
140140 }
141141
142- return this . cmd ( Object . entries ( placeholders )
142+ return this . cmd ( customGenerator , Object . entries ( placeholders )
143143 . filter ( ( [ , replacement ] ) => ! ! replacement )
144144 . reduce ( ( cmd , [ search , replacement ] ) => {
145145 return cmd . split ( `#{${ search } }` ) . join ( replacement )
146146 } , command ) )
147147 }
148148
149- private cmd = ( appendix : string ) => [
150- 'java' ,
151- process . env [ 'JAVA_OPTS' ] ,
152- `-jar "${ this . versionManager . filePath ( ) } "` ,
153- 'generate' ,
154- appendix ,
155- ] . filter ( isString ) . join ( ' ' ) ;
149+ private cmd = ( customGenerator : string | undefined , appendix : string ) => {
150+ const cliPath = this . versionManager . filePath ( ) ;
151+ const subCmd = customGenerator
152+ ? `-cp "${ [ cliPath , customGenerator ] . join ( this . isWin ( ) ? ';' : ':' ) } " org.openapitools.codegen.OpenAPIGenerator`
153+ : `-jar "${ cliPath } "` ;
154+ return [
155+ 'java' ,
156+ process . env [ 'JAVA_OPTS' ] ,
157+ subCmd ,
158+ 'generate' ,
159+ appendix ,
160+ ] . filter ( isString ) . join ( ' ' ) ;
161+ }
156162
163+ private isWin = ( ) => process . platform === "win32"
157164}
0 commit comments