File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -409,6 +409,10 @@ private async Task<OpenApiResponse> GetResponseAsync(
409
409
var targetType = parameter . Type == typeof ( string ) && parameter . ModelMetadata . ModelType != parameter . Type
410
410
? parameter . ModelMetadata . ModelType
411
411
: parameter . Type ;
412
+ // If the type is null, then we're dealing with an inert
413
+ // route parameter that does not define a specific parameter type in the
414
+ // route handler or in the response. In this case, we default to a string schema.
415
+ targetType ??= typeof ( string ) ;
412
416
var openApiParameter = new OpenApiParameter
413
417
{
414
418
Name = parameter . Name ,
Original file line number Diff line number Diff line change @@ -592,4 +592,22 @@ internal enum ItemStatus
592
592
Approved = 1 ,
593
593
Rejected = 2 ,
594
594
}
595
+
596
+ [ Fact ]
597
+ public async Task SupportsMvcActionWithAmbientRouteParameter ( )
598
+ {
599
+ // Arrange
600
+ var action = CreateActionDescriptor ( nameof ( AmbientRouteParameter ) ) ;
601
+
602
+ // Assert
603
+ await VerifyOpenApiDocument ( action , document =>
604
+ {
605
+ var operation = document . Paths [ "/api/with-ambient-route-param/{versionId}" ] . Operations [ OperationType . Get ] ;
606
+ var parameter = Assert . Single ( operation . Parameters ) ;
607
+ Assert . Equal ( "string" , parameter . Schema . Type ) ;
608
+ } ) ;
609
+ }
610
+
611
+ [ Route ( "/api/with-ambient-route-param/{versionId}" ) ]
612
+ private void AmbientRouteParameter ( ) { }
595
613
}
You can’t perform that action at this time.
0 commit comments