55 ParameterDeclarationStructure ,
66} from 'ts-morph' ;
77import { GeneratorConfig , PathInfo , SwaggerDefinition } from '../../../core/types.js' ;
8- import { SwaggerParser } from '../../../core/parser.js' ;
98import { camelCase , getTypeScriptType , isDataTypeInterface } from '../../../core/utils.js' ;
109import { HttpContext , HttpHeaders , HttpParams } from '@angular/common/http' ;
10+ import { SwaggerParser } from "@src/core/parser.js" ;
1111
1212/** A strongly-typed representation of Angular's HttpRequest options. */
1313interface HttpRequestOptions {
@@ -119,15 +119,30 @@ export class ServiceMethodGenerator {
119119 urlTemplate = urlTemplate . replace ( `{${ p . name } }` , `\${${ camelCase ( p . name ) } }` ) ;
120120 } ) ;
121121
122- const lines = [ `const url = \`\${this.basePath}${ urlTemplate } \`;` ] ;
122+ const lines : string [ ] = [ ] ;
123+
124+ const cookieParams = operation . parameters ?. filter ( p => p . in === 'cookie' ) ?? [ ] ;
125+ if ( cookieParams . length > 0 ) {
126+ lines . push ( `// TODO: Cookie parameters are not handled by Angular's HttpClient. You may need to handle them manually.
127+ console.warn('The following cookie parameters are not automatically handled:', ${ JSON . stringify ( cookieParams . map ( p => p . name ) ) } );` ) ;
128+ }
129+
130+ const querystringParams = operation . parameters ?. filter ( p => p . in === 'querystring' ) ?? [ ] ;
131+ if ( querystringParams . length > 0 ) {
132+ lines . push ( `// TODO: querystring parameters are not handled by Angular's HttpClient. You may need to handle them manually by constructing the URL.
133+ console.warn('The following querystring parameters are not automatically handled:', ${ JSON . stringify ( querystringParams . map ( p => p . name ) ) } );` ) ;
134+ }
135+ lines . push ( `const url = \`\${this.basePath}${ urlTemplate } \`;` ) ;
136+
123137 const requestOptions : HttpRequestOptions = { } ;
124138
125139 const queryParams = operation . parameters ?. filter ( p => p . in === 'query' ) ?? [ ] ;
126140 if ( queryParams . length > 0 ) {
127141 lines . push ( `let params = new HttpParams({ fromObject: options?.params ?? {} });` ) ;
128142 queryParams . forEach ( p => {
129143 const paramName = camelCase ( p . name ) ;
130- lines . push ( `if (${ paramName } != null) { params = HttpParamsBuilder.addToHttpParams(params, ${ paramName } , '${ p . name } '); }` ) ;
144+ const paramDefJson = JSON . stringify ( p ) ;
145+ lines . push ( `if (${ paramName } != null) { params = HttpParamsBuilder.serializeQueryParam(params, ${ paramDefJson } , ${ paramName } ); }` ) ;
131146 } ) ;
132147 requestOptions . params = 'params' as any ; // Use string placeholder
133148 }
@@ -143,10 +158,10 @@ export class ServiceMethodGenerator {
143158 }
144159
145160 let optionProperties = `
146- observe: options?.observe,
147- reportProgress: options?.reportProgress,
148- responseType: options?.responseType,
149- withCredentials: options?.withCredentials,
161+ observe: options?.observe,
162+ reportProgress: options?.reportProgress,
163+ responseType: options?.responseType,
164+ withCredentials: options?.withCredentials,
150165 context: this.createContextWithClientId(options?.context)` ;
151166
152167 if ( requestOptions . params ) {
0 commit comments