@@ -88,12 +88,7 @@ ${controllerPropsCtor}
8888 const haveQueryParams = controllerPath . queryParams . length > 0 ;
8989 url += ! haveQueryParams
9090 ? ''
91- : '?' + controllerPath . queryParams . map ( x => {
92- if ( this . getPropDesc ( x . schema ! ) . includes ( '[]' ) ) {
93- return `{string.Join("&", q${ capitalize ( x . name ) } ?.Select(x => $"${ x . name } ={x}"))}` ;
94- }
95- return `${ x . name } ={q${ capitalize ( x . name ) } }` ;
96- } ) . join ( '&' ) ;
91+ : `?{string.Join("&", query)}` ;
9792 const queryParams = haveQueryParams
9893 ? controllerPath . queryParams
9994 . map (
@@ -102,7 +97,19 @@ ${controllerPropsCtor}
10297 )
10398 . join ( ', ' ) + ', '
10499 : `` ;
105-
100+ let queryContent = `` ;
101+ if ( haveQueryParams ) {
102+ queryContent += `\t\tvar query = new List<string>();\n` ;
103+ for ( const queryParam of controllerPath . queryParams ) {
104+ const csharpParam = `q${ capitalize ( queryParam . name ) } ` ;
105+ const isList = this . getPropDesc ( queryParam . schema ! ) . includes ( '[]' ) ;
106+ if ( isList ) {
107+ queryContent += `\t\tif (${ csharpParam } != null) { query.AddRange(${ csharpParam } .Select(x => $"${ queryParam . name } ={x}")); }\n`
108+ } else {
109+ queryContent += `\t\tquery.Add($"${ queryParam . name } ={${ csharpParam } }");\n`
110+ }
111+ }
112+ }
106113 let methodCommonText = `\t\t\t"${ capitalize ( controllerPath . method . toLowerCase ( ) ) } ",\n` ;
107114 methodCommonText += `\t\t\t\$"${ url } \",\n` ;
108115 methodCommonText += `\t\t\t${ controllerPath . body . haveBody ? 'body' : 'default' } ,\n` ;
@@ -125,31 +132,33 @@ ${controllerPropsCtor}
125132 let methodContent = '' ;
126133 // method one
127134 methodContent += `\tpublic Task<${ responseType } ${ nullableMark } > ${ methodName } Async(${ methodParams } ) \n\t{\n` . replace ( ', )' , ')' ) ;
135+ methodContent += queryContent ;
128136 methodContent += `\t\treturn Method<${ requestType } ,${ responseType } ${ nullableMark } >(\n` ;
129137 methodContent += methodCommonText ;
130138
131139 // method two
132140 methodContent += `\tpublic Task<T${ nullableMark } > ${ methodName } Async<T>(${ methodParams } ) \n\t{\n` . replace ( ', )' , ')' ) ;
141+ methodContent += queryContent ;
133142 methodContent += `\t\treturn Method<${ requestType } ,T${ nullableMark } >(\n` ;
134143 methodContent += methodCommonText ;
135144
136145 // method three
137146 const genericBodyParam = controllerPath . body . haveBody ? `S body, ` : '' ;
138147 const genericBodyMethodParams = `${ genericBodyParam } ${ pathParams } ${ queryParams } ${ headersParams } ` ;
139148 methodContent += `\tpublic Task<T${ nullableMark } > ${ methodName } Async<T, S>(${ genericBodyMethodParams } ) \n\t{\n` . replace ( ', )' , ')' ) ;
149+ methodContent += queryContent ;
140150 methodContent += `\t\treturn Method<S,T${ nullableMark } >(\n` ;
141151 methodContent += methodCommonText ;
142152
143153 // method four
144154 methodContent += `\tpublic Task<string${ nullableMark } > ${ methodName } ContentAsync(${ methodParams } ) \n\t{\n` . replace ( ', )' , ')' ) ;
155+ methodContent += queryContent ;
145156 methodContent += `\t\treturn Method<${ requestType } >(\n` ;
146157 methodContent += methodCommonText ;
147158
148159 // method five
149- methodContent += `\tpublic Task<string${ nullableMark } > ${ methodName } ContentAsync<S>(${ genericBodyMethodParams } ) \n\t{\n` . replace (
150- ', )' ,
151- ')' ,
152- ) ;
160+ methodContent += `\tpublic Task<string${ nullableMark } > ${ methodName } ContentAsync<S>(${ genericBodyMethodParams } ) \n\t{\n` . replace ( ', )' , ')' , ) ;
161+ methodContent += queryContent ;
153162 methodContent += `\t\treturn Method<S>(\n` ;
154163 methodContent += methodCommonText ;
155164
0 commit comments