@@ -104,7 +104,10 @@ Dictionary<string, int> methodNameCounts
104104 StringComparison . Ordinal
105105 ) ;
106106 var parameters = GetParameters ( operation , schemas ) ;
107- var hasBody = GetRequestBodyType ( operation ) != null ;
107+ // Match ExtensionMethodGenerator behavior: POST/PUT/PATCH always have body
108+ var hasBody = operationType == HttpMethod . Post
109+ || operationType == HttpMethod . Put
110+ || operationType == HttpMethod . Patch ;
108111 var bodyType = GetRequestBodyType ( operation ) ?? "object" ;
109112 var responseType = GetResponseType ( operation ) ;
110113 var errorType = GetErrorType ( operation ) ;
@@ -146,8 +149,9 @@ string errorType
146149 var extensionCallArgs = new List < string > ( ) ;
147150
148151 // Separate required and optional parameters
149- var requiredParams = parameters . Where ( p => p . Required || ( ! p . Type . Contains ( '?' , StringComparison . Ordinal ) && p . DefaultValue == null ) ) . ToList ( ) ;
150- var optionalParams = parameters . Where ( p => ! p . Required && ( p . Type . Contains ( '?' , StringComparison . Ordinal ) || p . DefaultValue != null ) ) . ToList ( ) ;
152+ // A parameter is optional if it has a default value OR is nullable, regardless of Required flag
153+ var optionalParams = parameters . Where ( p => p . DefaultValue != null || p . Type . Contains ( '?' , StringComparison . Ordinal ) ) . ToList ( ) ;
154+ var requiredParams = parameters . Except ( optionalParams ) . ToList ( ) ;
151155
152156 // Add required parameters first
153157 foreach ( var param in requiredParams )
@@ -169,7 +173,7 @@ string errorType
169173 methodParams . Add ( FormatParameter ( param ) ) ;
170174
171175 // For optional strings with default "", use null coalescing
172- if ( param . Type == "string?" && param . DefaultValue == "" )
176+ if ( param . Type == "string?" && string . IsNullOrEmpty ( param . DefaultValue ) )
173177 {
174178 extensionCallArgs . Add ( $ "{ param . Name } ?? \" \" ") ;
175179 }
@@ -193,10 +197,11 @@ string errorType
193197
194198 var methodParamsStr =
195199 methodParams . Count > 0 ? string . Join ( ", " , methodParams ) : string . Empty ;
196- var extensionCallArgsStr =
197- extensionCallArgs . Count > 0
198- ? string . Join ( ", " , extensionCallArgs ) + ", "
199- : string . Empty ;
200+
201+ // Always add CancellationToken.None as last parameter
202+ extensionCallArgs . Add ( "CancellationToken.None" ) ;
203+
204+ var extensionCallArgsStr = string . Join ( ", " , extensionCallArgs ) ;
200205
201206 var okAlias = $ "Ok{ responseType } ";
202207 var errorAlias = $ "Error{ responseType } ";
@@ -346,11 +351,31 @@ private static string GetResponseType(OpenApiOperation operation)
346351 }
347352
348353 var content = successResponse . Value . Value . Content . FirstOrDefault ( ) ;
349- return content . Value ? . Schema is OpenApiSchemaReference schemaRef
350- ? schemaRef . Reference . Id != null
354+
355+ // Check if it's a schema reference (named type)
356+ if ( content . Value ? . Schema is OpenApiSchemaReference schemaRef )
357+ {
358+ return schemaRef . Reference . Id != null
351359 ? CodeGenerationHelpers . ToPascalCase ( schemaRef . Reference . Id )
352- : "object"
353- : "object" ;
360+ : "object" ;
361+ }
362+
363+ // Check for primitive types
364+ if ( content . Value ? . Schema != null )
365+ {
366+ var schema = content . Value . Schema ;
367+ return schema . Type switch
368+ {
369+ JsonSchemaType . String => "string" ,
370+ JsonSchemaType . Integer => schema . Format == "int64" ? "long" : "int" ,
371+ JsonSchemaType . Number => schema . Format == "float" ? "float" : "double" ,
372+ JsonSchemaType . Boolean => "bool" ,
373+ JsonSchemaType . Array => "object" , // Arrays are complex
374+ _ => "object"
375+ } ;
376+ }
377+
378+ return "object" ;
354379 }
355380
356381 private static string GetErrorType ( OpenApiOperation operation )
0 commit comments