@@ -59,6 +59,7 @@ public sealed class MinimalApiGenerator : IIncrementalGenerator
5959 private const string SummaryAttributeNamedParameter = "Summary" ;
6060 private const string DescriptionAttributeNamedParameter = "Description" ;
6161 private const string ResponseTypeAttributeNamedParameter = "ResponseType" ;
62+ private const string RequestTypeAttributeNamedParameter = "RequestType" ;
6263
6364 private const string RequireAuthorizationAttributeName = "RequireAuthorizationAttribute" ;
6465 private const string RequireAuthorizationAttributeFullyQualifiedName = $ "{ AttributesNamespace } .{ RequireAuthorizationAttributeName } ";
@@ -281,7 +282,7 @@ internal sealed class {{AcceptsAttributeName}} : global::System.Attribute
281282 /// <summary>
282283 /// Gets the request type accepted by the endpoint.
283284 /// </summary>
284- public global::System.Type RequestType { get; }
285+ public global::System.Type RequestType { get; init; } = default!;
285286
286287 /// <summary>
287288 /// Gets the primary content type accepted by the endpoint.
@@ -296,12 +297,10 @@ internal sealed class {{AcceptsAttributeName}} : global::System.Attribute
296297 /// <summary>
297298 /// Initializes a new instance of the <see cref="{{ AcceptsAttributeName }} "/> class.
298299 /// </summary>
299- /// <param name="requestType">The CLR type of the request body.</param>
300300 /// <param name="contentType">The primary content type accepted by the endpoint.</param>
301301 /// <param name="additionalContentTypes">Additional content types accepted by the endpoint.</param>
302- public {{ AcceptsAttributeName }} (global::System.Type requestType, string contentType = "application/json", params string[] additionalContentTypes)
302+ public {{ AcceptsAttributeName }} (string contentType = "application/json", params string[] additionalContentTypes)
303303 {
304- RequestType = requestType ?? throw new global::System.ArgumentNullException(nameof(requestType));
305304 ContentType = string.IsNullOrWhiteSpace(contentType) ? "application/json" : contentType;
306305 AdditionalContentTypes = additionalContentTypes ?? [];
307306 }
@@ -927,15 +926,14 @@ private static void TryAddAcceptsMetadata(
927926 ? GetStringArrayValues ( attribute . ConstructorArguments [ 1 ] )
928927 : null ;
929928 }
930- else if ( attribute . ConstructorArguments . Length >= 1 &&
931- attribute . ConstructorArguments [ 0 ] . Value is ITypeSymbol requestTypeSymbol )
929+ else if ( GetNamedTypeSymbol ( attribute , RequestTypeAttributeNamedParameter ) is { } requestTypeSymbol )
932930 {
933931 requestType = requestTypeSymbol . ToDisplayString ( SymbolDisplayFormat . FullyQualifiedFormat ) ;
934- contentType = attribute . ConstructorArguments . Length > 1
935- ? NormalizeRequiredContentType ( attribute . ConstructorArguments [ 1 ] . Value as string , "application/json" )
932+ contentType = attribute . ConstructorArguments . Length > 0
933+ ? NormalizeRequiredContentType ( attribute . ConstructorArguments [ 0 ] . Value as string , "application/json" )
936934 : "application/json" ;
937- additionalContentTypes = attribute . ConstructorArguments . Length > 2
938- ? GetStringArrayValues ( attribute . ConstructorArguments [ 2 ] )
935+ additionalContentTypes = attribute . ConstructorArguments . Length > 1
936+ ? GetStringArrayValues ( attribute . ConstructorArguments [ 1 ] )
939937 : null ;
940938 }
941939 else
0 commit comments