@@ -22,7 +22,7 @@ export class Generator extends Emitter<GeneratorEmits> {
2222 static defaults : StrictGeneratorOptions = {
2323 cwd : process . cwd ( ) ,
2424 dest : '/src/apis' ,
25- modules : { } ,
25+ documents : { } ,
2626 } ;
2727
2828 options : StrictGeneratorOptions ;
@@ -32,7 +32,7 @@ export class Generator extends Emitter<GeneratorEmits> {
3232 }
3333
3434 async generate ( ) {
35- const entries = Object . entries ( this . options . modules ) ;
35+ const entries = Object . entries ( this . options . documents ) ;
3636 const count = entries . length ;
3737 const payload : GeneratorPayload = { count } ;
3838 this . emit ( 'start' , payload ) ;
@@ -41,7 +41,7 @@ export class Generator extends Emitter<GeneratorEmits> {
4141 let index = 0 ;
4242 for ( const [ name , module ] of entries ) {
4343 const openAPI : OpenAPIOptions = isString ( module ) ? { document : module } : module ;
44- await this . #generateOpenAPI( index , count , name , openAPI ) ;
44+ await this . #generateOpenAPI( { index, count, name } , openAPI ) ;
4545 index ++ ;
4646 }
4747 }
@@ -54,12 +54,12 @@ export class Generator extends Emitter<GeneratorEmits> {
5454 this . emit ( 'end' , payload ) ;
5555 }
5656
57- async #generateOpenAPI( index : number , count : number , module : string , openAPIOptions : OpenAPIOptions ) {
57+ async #generateOpenAPI( { index, count , name } : { index : number ; count : number ; name : string } , openAPIOptions : OpenAPIOptions ) {
5858 const { cwd, dest, ...globalPrinter } = this . options ;
59- const { document, fileName = `${ module } .ts` , ...scopePrinter } = openAPIOptions ;
59+ const { document, fileName = `${ name } .ts` , ...scopePrinter } = openAPIOptions ;
6060 const mainFile = path . join ( cwd , dest , fileName ) ;
61- const typeFile = path . join ( cwd , dest , fileName . replace ( / \. t s $ / , '.type.ts' ) ) ;
62- const schemaFile = path . join ( cwd , dest , fileName . replace ( / \. t s $ / , '.schema.ts' ) ) ;
61+ const typeFile = mainFile . replace ( / \. t s $ / , '.type.ts' ) ;
62+ const schemaFile = mainFile . replace ( / \. t s $ / , '.schema.ts' ) ;
6363
6464 // 1. 参数合并
6565 const printerOptions = Object . assign ( { } , globalPrinter , scopePrinter ) ;
@@ -69,11 +69,11 @@ export class Generator extends Emitter<GeneratorEmits> {
6969 dest,
7070 ...printerOptions ,
7171 } ;
72- const makePayload = ( step : GeneratingStage ) : GeneratingPayload => ( {
72+ const makePayload = ( stage : GeneratingStage ) : GeneratingPayload => ( {
7373 index,
7474 count,
75- module ,
76- stage : step ,
75+ name ,
76+ stage,
7777 options,
7878 file : mainFile ,
7979 } ) ;
@@ -87,7 +87,7 @@ export class Generator extends Emitter<GeneratorEmits> {
8787 // 3. 输出
8888 this . emit ( 'process' , makePayload ( 'printing' ) ) ;
8989 const printer = new Printer ( openAPIV3Document , printerOptions ) ;
90- const { type, main, schema } = printer . print ( { module , cwd, mainFile, typeFile, schemaFile } ) ;
90+ const { type, main, schema } = printer . print ( { document : name , cwd, mainFile, typeFile, schemaFile } ) ;
9191
9292 // 4. 写入
9393 this . emit ( 'process' , makePayload ( 'writing' ) ) ;
0 commit comments