1
1
import ts from "typescript" ;
2
2
3
3
import * as TypeScriptCodeGenerator from "../CodeGenerator" ;
4
+ import { CodeGenerator as CodeGenerator2 } from "../types" ;
4
5
import * as CodeGenerator from "./CodeGenerator" ;
5
6
import * as Comment from "./Comment" ;
6
7
import * as Headers from "./components/Headers" ;
@@ -21,22 +22,18 @@ export { OpenApi, CodeGenerator, CodeGeneratorParams, PickedParameter, Name };
21
22
export interface Type {
22
23
generateLeadingComment : ( ) => string ;
23
24
createFunction : TypeScriptCodeGenerator . CreateFunction ;
24
- codeGeneratorOption : CodeGenerator . Option ;
25
+ codeGeneratorOption : CodeGenerator2 . Option ;
25
26
}
26
27
27
28
export 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 ;
36
29
/**
37
30
* List of operationId to be used
38
31
*/
39
32
allowOperationIds ?: string [ ] ;
33
+
34
+ generateCodeAfterGeneratedTypeDefinition ?: CodeGenerator2 . GenerateFunction ;
35
+
36
+ codeGeneratorOption : CodeGenerator2 . Option ;
40
37
}
41
38
42
39
export 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
47
44
const factory = TypeScriptCodeGenerator . Factory . create ( context ) ;
48
45
const store = Store . create ( factory , noReferenceOpenApiSchema ) ;
49
46
const toTypeNodeContext = TypeNodeContext . create ( entryPoint , store , factory , converterContext ) ;
47
+ let extraStatements : ts . Statement [ ] = [ ] ;
50
48
51
49
if ( rootSchema . components ) {
52
50
if ( rootSchema . components . schemas ) {
@@ -106,16 +104,12 @@ export const create = (entryPoint: string, rootSchema: OpenApi.Document, noRefer
106
104
}
107
105
if ( rootSchema . paths ) {
108
106
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 ) ) ;
117
111
}
118
- return store . getRootStatements ( ) ;
112
+ return store . getRootStatements ( ) . concat ( extraStatements ) ;
119
113
} ;
120
114
121
115
return {
0 commit comments