11import * as fs from "fs" ;
22import { posix as path } from "path" ;
33
4- import { CodeGenerator , GeneratorTemplate } from "../lib" ;
4+ import { CodeGenerator , CustomCodeGenerator } from "../lib" ;
55import * as Templates from "../lib/templates" ;
66
77const writeText = ( filename : string , text : string ) : void => {
@@ -34,7 +34,7 @@ const generateTemplateCodeOnly = (
3434 } ) ;
3535 }
3636
37- const apiClientGeneratorTemplate : GeneratorTemplate < Templates . ApiClient . Option > = {
37+ const apiClientGeneratorTemplate : CustomCodeGenerator < Templates . ApiClient . Option > = {
3838 generator : Templates . ApiClient . generator ,
3939 option : option ,
4040 } ;
@@ -58,11 +58,7 @@ const generateTypedefWithTemplateCode = (
5858 }
5959
6060 const code = codeGenerator . generateTypeDefinition ( [
61- {
62- generator : ( ) => {
63- return codeGenerator . getAdditionalTypeStatements ( ) ;
64- } ,
65- } ,
61+ codeGenerator . getAdditionalTypeDefinitionCustomCodeGenerator ( ) ,
6662 {
6763 generator : Templates . ApiClient . generator ,
6864 option : option ,
@@ -75,9 +71,9 @@ const generateTypedefWithTemplateCode = (
7571const generateSplitCode = ( inputFilename : string , outputDir : string ) => {
7672 const codeGenerator = new CodeGenerator ( inputFilename ) ;
7773
78- const apiClientGeneratorTemplate : GeneratorTemplate < Templates . ApiClient . Option > = {
74+ const apiClientGeneratorTemplate : CustomCodeGenerator < Templates . ApiClient . Option > = {
7975 generator : Templates . ApiClient . generator ,
80- option : { sync : false } ,
76+ option : { sync : false , additionalMethodComment : true } ,
8177 } ;
8278
8379 const typeDefCode = codeGenerator . generateTypeDefinition ( ) ;
@@ -87,18 +83,19 @@ const generateSplitCode = (inputFilename: string, outputDir: string) => {
8783 return [ `import { Schemas } from "./types";` ] ;
8884 } ,
8985 } ,
90- {
91- generator : ( ) => {
92- return codeGenerator . getAdditionalTypeStatements ( ) ;
93- } ,
94- } ,
86+ codeGenerator . getAdditionalTypeDefinitionCustomCodeGenerator ( ) ,
9587 apiClientGeneratorTemplate ,
9688 ] ) ;
9789
9890 writeText ( path . join ( outputDir , "types.ts" ) , typeDefCode ) ;
9991 writeText ( path . join ( outputDir , "apiClient.ts" ) , apiClientCode ) ;
10092} ;
10193
94+ const generateParameter = ( inputFilename : string , outputFilename : string ) => {
95+ const codeGenerator = new CodeGenerator ( inputFilename ) ;
96+ writeText ( outputFilename , JSON . stringify ( codeGenerator . getCodeGeneratorParamsArray ( ) , null , 2 ) ) ;
97+ } ;
98+
10299const main = ( ) => {
103100 generateTypedefCodeOnly ( "test/api.test.domain/index.yml" , "test/code/typedef-only/api.test.domain.ts" , true ) ;
104101 generateTypedefCodeOnly ( "test/infer.domain/index.yml" , "test/code/typedef-only/infer.domain.ts" , false ) ;
@@ -116,6 +113,9 @@ const main = () => {
116113 generateTypedefWithTemplateCode ( "test/infer.domain/index.yml" , "test/code/typedef-with-template/infer.domain.ts" , false , { sync : false } ) ;
117114
118115 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" ) ;
119119} ;
120120
121121main ( ) ;
0 commit comments