4
4
using System . ComponentModel ;
5
5
using Microsoft . AspNetCore . Builder ;
6
6
using Microsoft . AspNetCore . Http ;
7
+ using Microsoft . AspNetCore . Mvc ;
7
8
using Microsoft . OpenApi . Any ;
8
9
using Microsoft . OpenApi . Models ;
9
10
@@ -292,8 +293,9 @@ await VerifyOpenApiDocument(builder, document =>
292
293
property =>
293
294
{
294
295
Assert . Equal ( "value" , property . Key ) ;
295
- Assert . Equal ( "object" , property . Value . Type ) ;
296
- Assert . Collection ( property . Value . Properties ,
296
+ var propertyValue = property . Value . GetEffective ( document ) ;
297
+ Assert . Equal ( "object" , propertyValue . Type ) ;
298
+ Assert . Collection ( propertyValue . Properties ,
297
299
property =>
298
300
{
299
301
Assert . Equal ( "id" , property . Key ) ;
@@ -317,8 +319,9 @@ await VerifyOpenApiDocument(builder, document =>
317
319
property =>
318
320
{
319
321
Assert . Equal ( "error" , property . Key ) ;
320
- Assert . Equal ( "object" , property . Value . Type ) ;
321
- Assert . Collection ( property . Value . Properties , property =>
322
+ var propertyValue = property . Value . GetEffective ( document ) ;
323
+ Assert . Equal ( "object" , propertyValue . Type ) ;
324
+ Assert . Collection ( propertyValue . Properties , property =>
322
325
{
323
326
Assert . Equal ( "code" , property . Key ) ;
324
327
Assert . Equal ( "integer" , property . Value . Type ) ;
@@ -404,8 +407,10 @@ await VerifyOpenApiDocument(builder, document =>
404
407
property =>
405
408
{
406
409
Assert . Equal ( "todo" , property . Key ) ;
407
- Assert . Equal ( "object" , property . Value . Type ) ;
408
- Assert . Collection ( property . Value . Properties ,
410
+ Assert . NotNull ( property . Value . Reference ) ;
411
+ var propertyValue = property . Value . GetEffective ( document ) ;
412
+ Assert . Equal ( "object" , propertyValue . Type ) ;
413
+ Assert . Collection ( propertyValue . Properties ,
409
414
property =>
410
415
{
411
416
Assert . Equal ( "id" , property . Key ) ;
@@ -529,8 +534,10 @@ await VerifyOpenApiDocument(builder, document =>
529
534
Assert . Equal ( "items" , property . Key ) ;
530
535
Assert . Equal ( "array" , property . Value . Type ) ;
531
536
Assert . NotNull ( property . Value . Items ) ;
532
- Assert . Equal ( "object" , property . Value . Items . Type ) ;
533
- Assert . Collection ( property . Value . Items . Properties ,
537
+ Assert . NotNull ( property . Value . Items . Reference ) ;
538
+ Assert . Equal ( "object" , property . Value . Items . GetEffective ( document ) . Type ) ;
539
+ var itemsValue = property . Value . Items . GetEffective ( document ) ;
540
+ Assert . Collection ( itemsValue . Properties ,
534
541
property =>
535
542
{
536
543
Assert . Equal ( "id" , property . Key ) ;
@@ -653,6 +660,53 @@ await VerifyOpenApiDocument(builder, document =>
653
660
} ) ;
654
661
}
655
662
663
+ [ Fact ]
664
+ public async Task GetOpenApiResponse_SupportsProducesWithProducesResponseTypeOnController ( )
665
+ {
666
+ var actionDescriptor = CreateActionDescriptor ( nameof ( TestController . Get ) , typeof ( TestController ) ) ;
667
+
668
+ await VerifyOpenApiDocument ( actionDescriptor , document =>
669
+ {
670
+ var operation = document . Paths [ "/" ] . Operations [ OperationType . Get ] ;
671
+ var responses = Assert . Single ( operation . Responses ) ;
672
+ var response = responses . Value ;
673
+ Assert . True ( response . Content . TryGetValue ( "application/json" , out var mediaType ) ) ;
674
+ var schema = mediaType . Schema . GetEffective ( document ) ;
675
+ Assert . Equal ( "object" , schema . Type ) ;
676
+ Assert . Collection ( schema . Properties ,
677
+ property =>
678
+ {
679
+ Assert . Equal ( "id" , property . Key ) ;
680
+ Assert . Equal ( "integer" , property . Value . Type ) ;
681
+ } ,
682
+ property =>
683
+ {
684
+ Assert . Equal ( "title" , property . Key ) ;
685
+ Assert . Equal ( "string" , property . Value . Type ) ;
686
+ } ,
687
+ property =>
688
+ {
689
+ Assert . Equal ( "completed" , property . Key ) ;
690
+ Assert . Equal ( "boolean" , property . Value . Type ) ;
691
+ } ,
692
+ property =>
693
+ {
694
+ Assert . Equal ( "createdAt" , property . Key ) ;
695
+ Assert . Equal ( "string" , property . Value . Type ) ;
696
+ Assert . Equal ( "date-time" , property . Value . Format ) ;
697
+ } ) ;
698
+ } ) ;
699
+ }
700
+
701
+ [ ApiController ]
702
+ [ Produces ( "application/json" ) ]
703
+ public class TestController
704
+ {
705
+ [ Route ( "/" ) ]
706
+ [ ProducesResponseType ( typeof ( Todo ) , StatusCodes . Status200OK ) ]
707
+ internal Todo Get ( ) => new ( 1 , "Write test" , false , DateTime . Now ) ;
708
+ }
709
+
656
710
private class ClassWithObjectProperty
657
711
{
658
712
public object Object { get ; set ; }
0 commit comments