11import ts from "typescript" ;
22
33import { Factory } from "../../CodeGenerator" ;
4- import { CodeGeneratorParams } from "../../Converter/v3" ;
4+ import type { CodeGenerator , CodeGeneratorParams } from "../../Converter/v3" ;
55import * as MethodBody from "./MethodBody" ;
66
77export { MethodBody } ;
@@ -32,7 +32,12 @@ const generateParams = (factory: Factory.Type, params: CodeGeneratorParams) => {
3232 } ) ;
3333} ;
3434
35- const generateResponseReturnType = ( factory : Factory . Type , successResponseNameList : string [ ] , successResponseContentTypeList : string [ ] ) => {
35+ const generateResponseReturnType = (
36+ factory : Factory . Type ,
37+ successResponseNameList : string [ ] ,
38+ successResponseContentTypeList : string [ ] ,
39+ option : CodeGenerator . Option ,
40+ ) => {
3641 let objectType : ts . TypeNode = factory . TypeNode . create ( {
3742 type : "void" ,
3843 } ) ;
@@ -48,6 +53,9 @@ const generateResponseReturnType = (factory: Factory.Type, successResponseNameLi
4853
4954 // レスポンスが存在しないので Promise<void>
5055 if ( successResponseNameList . length === 0 ) {
56+ if ( option . sync ) {
57+ return objectType ;
58+ }
5159 return factory . TypeReferenceNode . create ( {
5260 name : "Promise" ,
5361 typeArguments : [ objectType ] ,
@@ -64,6 +72,13 @@ const generateResponseReturnType = (factory: Factory.Type, successResponseNameLi
6472 } ) ;
6573 }
6674
75+ if ( option . sync ) {
76+ return factory . IndexedAccessTypeNode . create ( {
77+ objectType,
78+ indexType,
79+ } ) ;
80+ }
81+
6782 return factory . TypeReferenceNode . create ( {
6883 name : "Promise" ,
6984 typeArguments : [
@@ -106,7 +121,7 @@ const methodTypeParameters = (factory: Factory.Type, params: CodeGeneratorParams
106121 *
107122 * }
108123 */
109- export const create = ( factory : Factory . Type , params : CodeGeneratorParams ) : ts . MethodDeclaration => {
124+ export const create = ( factory : Factory . Type , params : CodeGeneratorParams , option : CodeGenerator . Option ) : ts . MethodDeclaration => {
110125 const typeParameters : ts . TypeParameterDeclaration [ ] = methodTypeParameters ( factory , params ) ;
111126 const methodArguments : ts . ParameterDeclaration [ ] = [ ] ;
112127 const hasParamsArguments =
@@ -116,7 +131,7 @@ export const create = (factory: Factory.Type, params: CodeGeneratorParams): ts.M
116131 methodArguments . push ( generateParams ( factory , params ) ) ;
117132 }
118133
119- const returnType : ts . TypeNode = generateResponseReturnType ( factory , params . responseSuccessNames , params . successResponseContentTypes ) ;
134+ const returnType : ts . TypeNode = generateResponseReturnType ( factory , params . responseSuccessNames , params . successResponseContentTypes , option ) ;
120135
121136 methodArguments . push (
122137 factory . ParameterDeclaration . create ( {
@@ -131,7 +146,7 @@ export const create = (factory: Factory.Type, params: CodeGeneratorParams): ts.M
131146
132147 return factory . MethodDeclaration . create ( {
133148 name : params . functionName ,
134- async : true ,
149+ async : ! option . sync ,
135150 parameters : methodArguments ,
136151 comment : params . comment ,
137152 deprecated : params . deprecated ,
0 commit comments