1
1
import * as fs from "fs" ;
2
2
import { posix as path } from "path" ;
3
3
4
- import { CodeGenerator , GeneratorTemplate } from "../lib" ;
4
+ import { CodeGenerator , CustomCodeGenerator } from "../lib" ;
5
5
import * as Templates from "../lib/templates" ;
6
6
7
7
const writeText = ( filename : string , text : string ) : void => {
@@ -34,7 +34,7 @@ const generateTemplateCodeOnly = (
34
34
} ) ;
35
35
}
36
36
37
- const apiClientGeneratorTemplate : GeneratorTemplate < Templates . ApiClient . Option > = {
37
+ const apiClientGeneratorTemplate : CustomCodeGenerator < Templates . ApiClient . Option > = {
38
38
generator : Templates . ApiClient . generator ,
39
39
option : option ,
40
40
} ;
@@ -58,11 +58,7 @@ const generateTypedefWithTemplateCode = (
58
58
}
59
59
60
60
const code = codeGenerator . generateTypeDefinition ( [
61
- {
62
- generator : ( ) => {
63
- return codeGenerator . getAdditionalTypeStatements ( ) ;
64
- } ,
65
- } ,
61
+ codeGenerator . getAdditionalTypeDefinitionCustomCodeGenerator ( ) ,
66
62
{
67
63
generator : Templates . ApiClient . generator ,
68
64
option : option ,
@@ -75,9 +71,9 @@ const generateTypedefWithTemplateCode = (
75
71
const generateSplitCode = ( inputFilename : string , outputDir : string ) => {
76
72
const codeGenerator = new CodeGenerator ( inputFilename ) ;
77
73
78
- const apiClientGeneratorTemplate : GeneratorTemplate < Templates . ApiClient . Option > = {
74
+ const apiClientGeneratorTemplate : CustomCodeGenerator < Templates . ApiClient . Option > = {
79
75
generator : Templates . ApiClient . generator ,
80
- option : { sync : false } ,
76
+ option : { sync : false , additionalMethodComment : true } ,
81
77
} ;
82
78
83
79
const typeDefCode = codeGenerator . generateTypeDefinition ( ) ;
@@ -87,18 +83,19 @@ const generateSplitCode = (inputFilename: string, outputDir: string) => {
87
83
return [ `import { Schemas } from "./types";` ] ;
88
84
} ,
89
85
} ,
90
- {
91
- generator : ( ) => {
92
- return codeGenerator . getAdditionalTypeStatements ( ) ;
93
- } ,
94
- } ,
86
+ codeGenerator . getAdditionalTypeDefinitionCustomCodeGenerator ( ) ,
95
87
apiClientGeneratorTemplate ,
96
88
] ) ;
97
89
98
90
writeText ( path . join ( outputDir , "types.ts" ) , typeDefCode ) ;
99
91
writeText ( path . join ( outputDir , "apiClient.ts" ) , apiClientCode ) ;
100
92
} ;
101
93
94
+ const generateParameter = ( inputFilename : string , outputFilename : string ) => {
95
+ const codeGenerator = new CodeGenerator ( inputFilename ) ;
96
+ writeText ( outputFilename , JSON . stringify ( codeGenerator . getCodeGeneratorParamsArray ( ) , null , 2 ) ) ;
97
+ } ;
98
+
102
99
const main = ( ) => {
103
100
generateTypedefCodeOnly ( "test/api.test.domain/index.yml" , "test/code/typedef-only/api.test.domain.ts" , true ) ;
104
101
generateTypedefCodeOnly ( "test/infer.domain/index.yml" , "test/code/typedef-only/infer.domain.ts" , false ) ;
@@ -116,6 +113,9 @@ const main = () => {
116
113
generateTypedefWithTemplateCode ( "test/infer.domain/index.yml" , "test/code/typedef-with-template/infer.domain.ts" , false , { sync : false } ) ;
117
114
118
115
generateSplitCode ( "test/api.test.domain/index.yml" , "test/code/split" ) ;
116
+
117
+ generateParameter ( "test/api.test.domain/index.yml" , "test/code/parameter/api.test.domain.json" ) ;
118
+ generateParameter ( "test/infer.domain/index.yml" , "test/code/parameter/infer.domain.json" ) ;
119
119
} ;
120
120
121
121
main ( ) ;
0 commit comments