@@ -509,6 +509,86 @@ await VerifyOpenApiDocument(builder, document =>
509509 } ) ;
510510 }
511511
512+ [ Fact ]
513+ public async Task GetOpenApiParameters_HandlesAsParametersParametersWithDescriptionAttribute ( )
514+ {
515+ // Arrange
516+ var builder = CreateBuilder ( ) ;
517+
518+ // Act
519+ builder . MapGet ( "/api" , ( [ AsParameters ] FromQueryModel model ) => { } ) ;
520+
521+ // Assert
522+ await VerifyOpenApiDocument ( builder , document =>
523+ {
524+ var operation = document . Paths [ "/api" ] . Operations [ HttpMethod . Get ] ;
525+ Assert . Contains ( operation . Parameters , actualMemory => actualMemory . Name == "id" && actualMemory . Description == "The ID of the entity" ) ;
526+ } ) ;
527+ }
528+
529+ [ Fact ]
530+ public async Task GetOpenApiParameters_HandlesFromQueryParametersWithDescriptionAttribute ( )
531+ {
532+ // Arrange
533+ var actionDescriptor = CreateActionDescriptor ( nameof ( TestFromQueryController . GetWithFromQueryDto ) , typeof ( TestFromQueryController ) ) ;
534+
535+ // Assert
536+ await VerifyOpenApiDocument ( actionDescriptor , document =>
537+ {
538+ var operation = document . Paths [ "/" ] . Operations [ HttpMethod . Get ] ;
539+ Assert . Contains ( operation . Parameters , actualMemory => actualMemory . Name == "id" && actualMemory . Description == "The ID of the entity" ) ;
540+ } ) ;
541+ }
542+
543+ [ Fact ]
544+ public async Task GetOpenApiParameters_HandlesAsParametersParametersWithDefaultValueAttribute ( )
545+ {
546+ // Arrange
547+ var builder = CreateBuilder ( ) ;
548+
549+ // Act
550+ builder . MapGet ( "/api" , ( [ AsParameters ] FromQueryModel model ) => { } ) ;
551+
552+ // Assert
553+ await VerifyOpenApiDocument ( builder , document =>
554+ {
555+ var operation = document . Paths [ "/api" ] . Operations [ HttpMethod . Get ] ;
556+ Assert . Contains (
557+ operation . Parameters ,
558+ actualMemory =>
559+ {
560+ return actualMemory . Name == "limit" &&
561+ actualMemory . Schema != null &&
562+ actualMemory . Schema . Default != null &&
563+ actualMemory . Schema . Default . GetValueKind ( ) == JsonValueKind . Number &&
564+ actualMemory . Schema . Default . GetValue < int > ( ) == 20 ;
565+ } ) ;
566+ } ) ;
567+ }
568+
569+ [ Fact ]
570+ public async Task GetOpenApiParameters_HandlesFromQueryParametersWithDefaultValueAttribute ( )
571+ {
572+ // Arrange
573+ var actionDescriptor = CreateActionDescriptor ( nameof ( TestFromQueryController . GetWithFromQueryDto ) , typeof ( TestFromQueryController ) ) ;
574+
575+ // Assert
576+ await VerifyOpenApiDocument ( actionDescriptor , document =>
577+ {
578+ var operation = document . Paths [ "/" ] . Operations [ HttpMethod . Get ] ;
579+ Assert . Contains (
580+ operation . Parameters ,
581+ actualMemory =>
582+ {
583+ return actualMemory . Name == "limit" &&
584+ actualMemory . Schema != null &&
585+ actualMemory . Schema . Default != null &&
586+ actualMemory . Schema . Default . GetValueKind ( ) == JsonValueKind . Number &&
587+ actualMemory . Schema . Default . GetValue < int > ( ) == 20 ;
588+ } ) ;
589+ } ) ;
590+ }
591+
512592 [ Route ( "/api/{id}/{date}" ) ]
513593 private void AcceptsParametersInModel ( RouteParamsContainer model ) { }
514594
@@ -809,4 +889,28 @@ public override void Write(Utf8JsonWriter writer, EnumArrayType value, JsonSeria
809889 writer . WriteEndObject ( ) ;
810890 }
811891 }
892+
893+ [ ApiController ]
894+ [ Route ( "[controller]/[action]" ) ]
895+ private class TestFromQueryController : ControllerBase
896+ {
897+ [ HttpGet ]
898+ public Task < IActionResult > GetWithFromQueryDto ( [ FromQuery ] FromQueryModel query )
899+ {
900+ return Task . FromResult < IActionResult > ( Ok ( ) ) ;
901+ }
902+ }
903+
904+ [ Description ( "A query model." ) ]
905+ private record FromQueryModel
906+ {
907+ [ Description ( "The ID of the entity" ) ]
908+ [ FromQuery ( Name = "id" ) ]
909+ public int Id { get ; set ; }
910+
911+ [ Description ( "The maximum number of results" ) ]
912+ [ FromQuery ( Name = "limit" ) ]
913+ [ DefaultValue ( 20 ) ]
914+ public int Limit { get ; set ; }
915+ }
812916}
0 commit comments