11import ts from "typescript" ;
22
33import * as TypeScriptCodeGenerator from "../CodeGenerator" ;
4+ import { CodeGenerator as CodeGenerator2 } from "../types" ;
45import * as CodeGenerator from "./CodeGenerator" ;
56import * as Comment from "./Comment" ;
67import * as Headers from "./components/Headers" ;
@@ -21,22 +22,18 @@ export { OpenApi, CodeGenerator, CodeGeneratorParams, PickedParameter, Name };
2122export interface Type {
2223 generateLeadingComment : ( ) => string ;
2324 createFunction : TypeScriptCodeGenerator . CreateFunction ;
24- codeGeneratorOption : CodeGenerator . Option ;
25+ codeGeneratorOption : CodeGenerator2 . Option ;
2526}
2627
2728export interface Option {
28- /**
29- * It is possible to rewrite the implementation after the type declaration.
30- */
31- rewriteCodeAfterTypeDeclaration : CodeGenerator . RewriteCodeAfterTypeDeclaration ;
32- /**
33- *
34- */
35- codeGeneratorOption : CodeGenerator . Option ;
3629 /**
3730 * List of operationId to be used
3831 */
3932 allowOperationIds ?: string [ ] ;
33+
34+ generateCodeAfterGeneratedTypeDefinition ?: CodeGenerator2 . GenerateFunction ;
35+
36+ codeGeneratorOption : CodeGenerator2 . Option ;
4037}
4138
4239export const create = ( entryPoint : string , rootSchema : OpenApi . Document , noReferenceOpenApiSchema : OpenApi . Document , option : Option ) : Type => {
@@ -47,6 +44,7 @@ export const create = (entryPoint: string, rootSchema: OpenApi.Document, noRefer
4744 const factory = TypeScriptCodeGenerator . Factory . create ( context ) ;
4845 const store = Store . create ( factory , noReferenceOpenApiSchema ) ;
4946 const toTypeNodeContext = TypeNodeContext . create ( entryPoint , store , factory , converterContext ) ;
47+ let extraStatements : ts . Statement [ ] = [ ] ;
5048
5149 if ( rootSchema . components ) {
5250 if ( rootSchema . components . schemas ) {
@@ -106,16 +104,12 @@ export const create = (entryPoint: string, rootSchema: OpenApi.Document, noRefer
106104 }
107105 if ( rootSchema . paths ) {
108106 Paths . generateStatements ( entryPoint , currentPoint , store , factory , rootSchema . paths , toTypeNodeContext , converterContext ) ;
109- CodeGenerator . generateApiClientCode (
110- store ,
111- context ,
112- converterContext ,
113- option . rewriteCodeAfterTypeDeclaration ,
114- option . allowOperationIds ,
115- option . codeGeneratorOption ,
116- ) ;
107+
108+ const codeGeneratorParamsList = CodeGenerator . generateCodeGeneratorParamsList ( store , converterContext , option . allowOperationIds ) ;
109+ const extraStatements2 = option . generateCodeAfterGeneratedTypeDefinition ?.( context , codeGeneratorParamsList , option . codeGeneratorOption ) || [ ] ;
110+ extraStatements = extraStatements . concat ( TypeScriptCodeGenerator . Utils . convertIntermediateCodes ( extraStatements2 ) ) ;
117111 }
118- return store . getRootStatements ( ) ;
112+ return store . getRootStatements ( ) . concat ( extraStatements ) ;
119113 } ;
120114
121115 return {
0 commit comments