@@ -40,13 +40,13 @@ public virtual void Write(AngularWriteConfiguration configuration, List<ITransfe
40
40
string controllerName = controller . Name . TrimEnd ( "Controller" ) ;
41
41
FileTemplate file = files . AddFile ( configuration . Service . RelativePath , configuration . AddHeader , configuration . CheckOnOverwrite ) ;
42
42
ClassTemplate classTemplate = file . AddNamespace ( string . Empty )
43
- . AddClass ( configuration . Service . Name ? . Replace ( "{0}" , controllerName ) ?? controllerName + "Service" )
44
- . FormatName ( configuration )
45
- . WithUsing ( httpClient , httpClientImport )
46
- . WithUsing ( "Injectable" , "@angular/core" )
47
- . WithUsing ( "Observable" , "rxjs" )
48
- . WithUsing ( "Subject" , "rxjs" )
49
- . WithAttribute ( "Injectable" , Code . AnonymousObject ( ) . WithProperty ( "providedIn" , Code . String ( "root" ) ) ) ;
43
+ . AddClass ( configuration . Service . Name ? . Replace ( "{0}" , controllerName ) ?? controllerName + "Service" )
44
+ . FormatName ( configuration )
45
+ . WithUsing ( httpClient , httpClientImport )
46
+ . WithUsing ( "Injectable" , "@angular/core" )
47
+ . WithUsing ( "Observable" , "rxjs" )
48
+ . WithUsing ( "Subject" , "rxjs" )
49
+ . WithAttribute ( "Injectable" , Code . AnonymousObject ( ) . WithProperty ( "providedIn" , Code . String ( "root" ) ) ) ;
50
50
FieldTemplate httpField = classTemplate . AddField ( "http" , Code . Type ( httpClient ) ) . Readonly ( ) . FormatName ( configuration ) ;
51
51
FieldTemplate serviceUrlField = classTemplate . AddField ( "serviceUrl" , Code . Type ( "string" ) ) . Public ( ) . FormatName ( configuration ) . Default ( Code . String ( string . Empty ) ) ;
52
52
classTemplate . AddConstructor ( ) . WithParameter ( Code . Type ( httpClient ) , "http" )
@@ -109,7 +109,7 @@ public virtual void Write(AngularWriteConfiguration configuration, List<ITransfe
109
109
}
110
110
foreach ( HttpServiceActionParameterTransferObject parameter in inlineParameters )
111
111
{
112
- string [ ] chunks = uri . Split ( new [ ] { $ "{{{parameter.Name}}}"} , StringSplitOptions . RemoveEmptyEntries ) ;
112
+ string [ ] chunks = uri . Split ( new [ ] { $ "{{{parameter.Name}}}" } , StringSplitOptions . RemoveEmptyEntries ) ;
113
113
parameterUrl = parameterUrl . Append ( Code . String ( chunks [ 0 ] ) ) . Append ( Code . Local ( parameter . Name ) ) ;
114
114
uri = chunks . Length == 1 ? string . Empty : chunks [ 1 ] ;
115
115
}
@@ -128,25 +128,23 @@ public virtual void Write(AngularWriteConfiguration configuration, List<ITransfe
128
128
}
129
129
foreach ( HttpServiceActionParameterTransferObject parameter in urlParameters )
130
130
{
131
- if ( isFirst )
132
- {
133
- isFirst = false ;
134
- parameterUrl = parameterUrl . Append ( Code . Local ( mapping [ parameter ] ) ) ;
135
- }
136
- else
131
+ string name = mapping [ parameter ] . Name ;
132
+ if ( ! isFirst )
137
133
{
138
- parameterUrl = parameterUrl . Append ( Code . String ( $ "&{ parameter . Name } =") ) . Append ( Code . Local ( mapping [ parameter ] ) ) ;
134
+ parameterUrl = parameterUrl . Append ( Code . String ( $ "&{ parameter . Name } =") ) ;
139
135
}
136
+ isFirst = false ;
137
+ parameterUrl = parameterUrl . Append ( Code . TypeScript ( $ "({ name } === undefined ? \" \" : { name } )") ) ;
140
138
}
141
139
142
140
methodTemplate . WithCode (
143
141
Code . This ( )
144
142
. Field ( httpField )
145
- . Method ( action . Type . ToString ( ) . ToLowerInvariant ( ) ,
146
- parameterUrl ,
143
+ . Method ( action . Type . ToString ( ) . ToLowerInvariant ( ) ,
144
+ parameterUrl ,
147
145
action . RequireBodyParameter ? Code . Local ( action . Parameters . Single ( x => x . FromBody ) . Name ) : null ,
148
146
Code . Local ( "httpOptions" )
149
- )
147
+ )
150
148
. Method ( "subscribe" , Code . Lambda ( hasReturnType ? "result" : null , code ) , errorCode ) . Close ( )
151
149
) ;
152
150
methodTemplate . WithCode ( Code . Return ( Code . Local ( "subject" ) ) ) ;
0 commit comments