@@ -20,6 +20,7 @@ public async Task SupportsXmlCommentsOnOperationsFromMinimalApis()
20
20
using Microsoft.Extensions.DependencyInjection;
21
21
using Microsoft.AspNetCore.Http.HttpResults;
22
22
using Microsoft.AspNetCore.Http;
23
+ using Microsoft.AspNetCore.Mvc;
23
24
24
25
var builder = WebApplication.CreateBuilder();
25
26
@@ -44,6 +45,9 @@ public async Task SupportsXmlCommentsOnOperationsFromMinimalApis()
44
45
app.MapGet("/15", RouteHandlerExtensionMethods.Get15);
45
46
app.MapPost("/16", RouteHandlerExtensionMethods.Post16);
46
47
app.MapGet("/17", RouteHandlerExtensionMethods.Get17);
48
+ app.MapPost("/18", RouteHandlerExtensionMethods.Post18);
49
+ app.MapPost("/19", RouteHandlerExtensionMethods.Post19);
50
+ app.MapGet("/20", RouteHandlerExtensionMethods.Get20);
47
51
48
52
app.Run();
49
53
@@ -207,8 +211,70 @@ public static void Post16(Example example)
207
211
public static int[][] Get17(int[] args)
208
212
{
209
213
return [[1, 2, 3], [4, 5, 6], [7, 8, 9], args];
214
+ }
210
215
216
+ /// <summary>
217
+ /// A summary of Post18.
218
+ /// </summary>
219
+ public static int Post18([AsParameters] FirstParameters queryParameters, [AsParameters] SecondParameters bodyParameters)
220
+ {
221
+ return 0;
211
222
}
223
+
224
+ /// <summary>
225
+ /// Tests mixed regular and AsParameters with examples.
226
+ /// </summary>
227
+ /// <param name="regularParam">A regular parameter with documentation.</param>
228
+ /// <param name="mixedParams">Mixed parameter class with various types.</param>
229
+ public static IResult Post19(string regularParam, [AsParameters] MixedParametersClass mixedParams)
230
+ {
231
+ return TypedResults.Ok($"Regular: {regularParam}, Email: {mixedParams.Email}");
232
+ }
233
+
234
+ /// <summary>
235
+ /// Tests AsParameters with different binding sources.
236
+ /// </summary>
237
+ /// <param name="bindingParams">Parameters from different sources.</param>
238
+ public static IResult Get20([AsParameters] BindingSourceParametersClass bindingParams)
239
+ {
240
+ return TypedResults.Ok($"Query: {bindingParams.QueryParam}, Header: {bindingParams.HeaderParam}");
241
+ }
242
+ }
243
+
244
+ public class FirstParameters
245
+ {
246
+ /// <summary>
247
+ /// The name of the person.
248
+ /// </summary>
249
+ public string? Name { get; set; }
250
+ /// <summary>
251
+ /// The age of the person.
252
+ /// </summary>
253
+ /// <example>30</example>
254
+ public int? Age { get; set; }
255
+ /// <summary>
256
+ /// The user information.
257
+ /// </summary>
258
+ /// <example>
259
+ /// {
260
+ /// "username": "johndoe",
261
+
262
+ /// }
263
+ /// </example>
264
+ public User? User { get; set; }
265
+ }
266
+
267
+ public class SecondParameters
268
+ {
269
+ /// <summary>
270
+ /// The description of the project.
271
+ /// </summary>
272
+ public string? Description { get; set; }
273
+ /// <summary>
274
+ /// The service used for testing.
275
+ /// </summary>
276
+ [FromServices]
277
+ public Example Service { get; set; }
212
278
}
213
279
214
280
public class User
@@ -232,6 +298,42 @@ public Example(Func<object?, int> function, object? state) : base(function, stat
232
298
{
233
299
}
234
300
}
301
+
302
+ public class MixedParametersClass
303
+ {
304
+ /// <summary>
305
+ /// The user's email address.
306
+ /// </summary>
307
+ /// <example>"[email protected] "</example>
308
+ public string? Email { get; set; }
309
+
310
+ /// <summary>
311
+ /// The user's age in years.
312
+ /// </summary>
313
+ /// <example>25</example>
314
+ public int Age { get; set; }
315
+
316
+ /// <summary>
317
+ /// Whether the user is active.
318
+ /// </summary>
319
+ /// <example>true</example>
320
+ public bool IsActive { get; set; }
321
+ }
322
+
323
+ public class BindingSourceParametersClass
324
+ {
325
+ /// <summary>
326
+ /// Query parameter from URL.
327
+ /// </summary>
328
+ [FromQuery]
329
+ public string? QueryParam { get; set; }
330
+
331
+ /// <summary>
332
+ /// Header value from request.
333
+ /// </summary>
334
+ [FromHeader]
335
+ public string? HeaderParam { get; set; }
336
+ }
235
337
""" ;
236
338
var generator = new XmlCommentGenerator ( ) ;
237
339
await SnapshotTestHelper . Verify ( source , generator , out var compilation ) ;
@@ -304,6 +406,33 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document =>
304
406
305
407
var path17 = document . Paths [ "/17" ] . Operations [ HttpMethod . Get ] ;
306
408
Assert . Equal ( "A summary of Get17." , path17 . Summary ) ;
409
+
410
+ var path18 = document . Paths [ "/18" ] . Operations [ HttpMethod . Post ] ;
411
+ Assert . Equal ( "A summary of Post18." , path18 . Summary ) ;
412
+ Assert . Equal ( "The name of the person." , path18 . Parameters [ 0 ] . Description ) ;
413
+ Assert . Equal ( "The age of the person." , path18 . Parameters [ 1 ] . Description ) ;
414
+ Assert . Equal ( 30 , path18 . Parameters [ 1 ] . Example . GetValue < int > ( ) ) ;
415
+ Assert . Equal ( "The description of the project." , path18 . Parameters [ 2 ] . Description ) ;
416
+ Assert . Equal ( "The user information." , path18 . RequestBody . Description ) ;
417
+ var path18RequestBody = path18 . RequestBody . Content [ "application/json" ] ;
418
+ var path18Example = Assert . IsAssignableFrom < JsonNode > ( path18RequestBody . Example ) ;
419
+ Assert . Equal ( "johndoe" , path18Example [ "username" ] . GetValue < string > ( ) ) ;
420
+ Assert . Equal ( "[email protected] " , path18Example [ "email" ] . GetValue < string > ( ) ) ;
421
+
422
+ var path19 = document . Paths [ "/19" ] . Operations [ HttpMethod . Post ] ;
423
+ Assert . Equal ( "Tests mixed regular and AsParameters with examples." , path19 . Summary ) ;
424
+ Assert . Equal ( "A regular parameter with documentation." , path19 . Parameters [ 0 ] . Description ) ;
425
+ Assert . Equal ( "The user's email address." , path19 . Parameters [ 1 ] . Description ) ;
426
+ Assert . Equal ( "[email protected] " , path19 . Parameters [ 1 ] . Example . GetValue < string > ( ) ) ;
427
+ Assert . Equal ( "The user's age in years." , path19 . Parameters [ 2 ] . Description ) ;
428
+ Assert . Equal ( 25 , path19 . Parameters [ 2 ] . Example . GetValue < int > ( ) ) ;
429
+ Assert . Equal ( "Whether the user is active." , path19 . Parameters [ 3 ] . Description ) ;
430
+ Assert . True ( path19 . Parameters [ 3 ] . Example . GetValue < bool > ( ) ) ;
431
+
432
+ var path20 = document . Paths [ "/20" ] . Operations [ HttpMethod . Get ] ;
433
+ Assert . Equal ( "Tests AsParameters with different binding sources." , path20 . Summary ) ;
434
+ Assert . Equal ( "Query parameter from URL." , path20 . Parameters [ 0 ] . Description ) ;
435
+ Assert . Equal ( "Header value from request." , path20 . Parameters [ 1 ] . Description ) ;
307
436
} ) ;
308
437
}
309
438
}
0 commit comments