@@ -426,7 +426,7 @@ public async Task SerializeAsV32JsonWithQueryAndAdditionalOperationsWorks()
426
426
[ new HttpMethod ( "Query" ) ] = new OpenApiOperation
427
427
{
428
428
Summary = "query operation" ,
429
- Description = "query description" ,
429
+ Description = "query description" ,
430
430
OperationId = "queryOperation" ,
431
431
Responses = new OpenApiResponses
432
432
{
@@ -440,7 +440,7 @@ public async Task SerializeAsV32JsonWithQueryAndAdditionalOperationsWorks()
440
440
{
441
441
Summary = "notify operation" ,
442
442
Description = "notify description" ,
443
- OperationId = "notifyOperation" ,
443
+ OperationId = "notifyOperation" ,
444
444
Responses = new OpenApiResponses
445
445
{
446
446
[ "200" ] = new OpenApiResponse
@@ -530,7 +530,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV31Works()
530
530
var pathItem = new OpenApiPathItem
531
531
{
532
532
Summary = "summary" ,
533
- Description = "description" ,
533
+ Description = "description" ,
534
534
Operations = new Dictionary < HttpMethod , OpenApiOperation >
535
535
{
536
536
[ HttpMethod . Get ] = new OpenApiOperation
@@ -569,7 +569,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV31Works()
569
569
}
570
570
}
571
571
} ,
572
-
572
+
573
573
}
574
574
} ;
575
575
@@ -589,7 +589,7 @@ public async Task SerializeV32FeaturesAsExtensionsInV3Works()
589
589
{
590
590
var pathItem = new OpenApiPathItem
591
591
{
592
- Summary = "summary" ,
592
+ Summary = "summary" ,
593
593
Description = "description" ,
594
594
Operations = new Dictionary < HttpMethod , OpenApiOperation >
595
595
{
@@ -749,4 +749,149 @@ public void CopyConstructorCopiesQueryAndAdditionalOperations()
749
749
750
750
Assert . Equal ( originalNotifyOp . Summary , copyNotifyOp . Summary ) ;
751
751
}
752
+
753
+ [ Fact ]
754
+ public async Task SerializeV32PathItemToV31ProducesExtensions ( )
755
+ {
756
+ // Arrange
757
+ var pathItem = new OpenApiPathItem
758
+ {
759
+ Summary = "Test path" ,
760
+ Operations = new Dictionary < HttpMethod , OpenApiOperation >
761
+ {
762
+ [ HttpMethod . Get ] = new OpenApiOperation
763
+ {
764
+ Summary = "Get operation" ,
765
+ OperationId = "getOp" ,
766
+ Responses = new OpenApiResponses
767
+ {
768
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
769
+ }
770
+ } ,
771
+ [ new HttpMethod ( "Query" ) ] = new OpenApiOperation
772
+ {
773
+ Summary = "Query operation" ,
774
+ OperationId = "queryOp" ,
775
+ Responses = new OpenApiResponses
776
+ {
777
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
778
+ }
779
+ } ,
780
+ [ new HttpMethod ( "notify" ) ] = new OpenApiOperation
781
+ {
782
+ Summary = "Notify operation" ,
783
+ OperationId = "notifyOp" ,
784
+ Responses = new OpenApiResponses
785
+ {
786
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
787
+ }
788
+ }
789
+ }
790
+ } ;
791
+
792
+ // Act
793
+ var yaml = await pathItem . SerializeAsYamlAsync ( OpenApiSpecVersion . OpenApi3_1 ) ;
794
+
795
+ // Assert
796
+ Assert . Contains ( "Query:" , yaml ) ;
797
+ Assert . Contains ( "x-oai-additionalOperations:" , yaml ) ;
798
+ Assert . Contains ( "queryOp" , yaml ) ;
799
+ Assert . Contains ( "notifyOp" , yaml ) ;
800
+ }
801
+
802
+ [ Fact ]
803
+ public async Task SerializeV32PathItemToV3ProducesExtensions ( )
804
+ {
805
+ // Arrange
806
+ var pathItem = new OpenApiPathItem
807
+ {
808
+ Summary = "Test path" ,
809
+ Operations = new Dictionary < HttpMethod , OpenApiOperation >
810
+ {
811
+ [ HttpMethod . Get ] = new OpenApiOperation
812
+ {
813
+ Summary = "Get operation" ,
814
+ OperationId = "getOp" ,
815
+ Responses = new OpenApiResponses
816
+ {
817
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
818
+ }
819
+ } ,
820
+ [ new HttpMethod ( "Query" ) ] = new OpenApiOperation
821
+ {
822
+ Summary = "Query operation" ,
823
+ OperationId = "queryOp" ,
824
+ Responses = new OpenApiResponses
825
+ {
826
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
827
+ }
828
+ } ,
829
+ [ new HttpMethod ( "notify" ) ] = new OpenApiOperation
830
+ {
831
+ Summary = "Notify operation" ,
832
+ OperationId = "notifyOp" ,
833
+ Responses = new OpenApiResponses
834
+ {
835
+ [ "200" ] = new OpenApiResponse { Description = "Success" }
836
+ }
837
+ }
838
+ }
839
+ } ;
840
+
841
+ // Act
842
+ var yaml = await pathItem . SerializeAsYamlAsync ( OpenApiSpecVersion . OpenApi3_0 ) ;
843
+
844
+ // Assert
845
+ Assert . Contains ( "Query:" , yaml ) ;
846
+ Assert . Contains ( "x-oai-additionalOperations:" , yaml ) ;
847
+ Assert . Contains ( "queryOp" , yaml ) ;
848
+ Assert . Contains ( "notifyOp" , yaml ) ;
849
+ }
850
+
851
+ [ Fact ]
852
+ public void PathItemShallowCopyIncludesV32Fields ( )
853
+ {
854
+ // Arrange
855
+ var original = new OpenApiPathItem
856
+ {
857
+ Summary = "Original" ,
858
+ Operations = new Dictionary < HttpMethod , OpenApiOperation >
859
+ {
860
+ [ HttpMethod . Get ] = new OpenApiOperation
861
+ {
862
+ Summary = "Get operation" ,
863
+ OperationId = "getOp" ,
864
+ Responses = new OpenApiResponses ( )
865
+ } ,
866
+ [ new HttpMethod ( "Query" ) ] = new OpenApiOperation
867
+ {
868
+ Summary = "Query operation" ,
869
+ OperationId = "queryOp"
870
+ } ,
871
+ [ new HttpMethod ( "notify" ) ] = new OpenApiOperation
872
+ {
873
+ Summary = "Notify operation" ,
874
+ OperationId = "notifyOp"
875
+ }
876
+ }
877
+ } ;
878
+
879
+ // Act
880
+ var copy = original . CreateShallowCopy ( ) ;
881
+
882
+ // Assert
883
+ Assert . NotNull ( original . Operations ) ;
884
+ Assert . NotNull ( copy . Operations ) ;
885
+ Assert . Contains ( HttpMethod . Get , original . Operations ) ;
886
+ Assert . Contains ( HttpMethod . Get , copy . Operations ) ;
887
+
888
+ var copyQueryOp = Assert . Contains ( new HttpMethod ( "Query" ) , copy . Operations ) ;
889
+ Assert . Contains ( new HttpMethod ( "Query" ) , original . Operations ) ;
890
+ Assert . Equal ( "Query operation" , copyQueryOp . Summary ) ;
891
+ Assert . Equal ( "queryOp" , copyQueryOp . OperationId ) ;
892
+ Assert . Contains ( new HttpMethod ( "notify" ) , original . Operations ) ;
893
+ var copyNotifyOp = Assert . Contains ( new HttpMethod ( "notify" ) , copy . Operations ) ;
894
+ Assert . Equal ( "Notify operation" , copyNotifyOp . Summary ) ;
895
+ Assert . Equal ( "notifyOp" , copyNotifyOp . OperationId ) ;
896
+ }
752
897
}
0 commit comments