@@ -401,10 +401,7 @@ extension DocumentTests {
401
401
" title " : " API " ,
402
402
" version " : " 1.0 "
403
403
},
404
- " openapi " : " 3.1.0 " ,
405
- " paths " : {
406
-
407
- }
404
+ " openapi " : " 3.1.0 "
408
405
}
409
406
"""
410
407
)
@@ -455,10 +452,7 @@ extension DocumentTests {
455
452
" title " : " API " ,
456
453
" version " : " 1.0 "
457
454
},
458
- " openapi " : " 3.1.0 " ,
459
- " paths " : {
460
-
461
- }
455
+ " openapi " : " 3.1.0 "
462
456
}
463
457
"""
464
458
)
@@ -510,9 +504,6 @@ extension DocumentTests {
510
504
" version " : " 1.0 "
511
505
},
512
506
" openapi " : " 3.1.0 " ,
513
- " paths " : {
514
-
515
- },
516
507
" servers " : [
517
508
{
518
509
" url " : " http: \\ / \\ /google.com "
@@ -642,9 +633,6 @@ extension DocumentTests {
642
633
" version " : " 1.0 "
643
634
},
644
635
" openapi " : " 3.1.0 " ,
645
- " paths " : {
646
-
647
- },
648
636
" security " : [
649
637
{
650
638
" security " : [
@@ -722,9 +710,6 @@ extension DocumentTests {
722
710
" version " : " 1.0 "
723
711
},
724
712
" openapi " : " 3.1.0 " ,
725
- " paths " : {
726
-
727
- },
728
713
" tags " : [
729
714
{
730
715
" name " : " hi "
@@ -789,10 +774,7 @@ extension DocumentTests {
789
774
" title " : " API " ,
790
775
" version " : " 1.0 "
791
776
},
792
- " openapi " : " 3.1.0 " ,
793
- " paths " : {
794
-
795
- }
777
+ " openapi " : " 3.1.0 "
796
778
}
797
779
"""
798
780
)
@@ -852,9 +834,6 @@ extension DocumentTests {
852
834
" version " : " 1.0 "
853
835
},
854
836
" openapi " : " 3.1.0 " ,
855
- " paths " : {
856
-
857
- },
858
837
" x-specialFeature " : [
859
838
" hello " ,
860
839
" world "
@@ -932,9 +911,6 @@ extension DocumentTests {
932
911
" version " : " 1.0 "
933
912
},
934
913
" openapi " : " 3.1.0 " ,
935
- " paths " : {
936
-
937
- },
938
914
" webhooks " : {
939
915
" webhook-test " : {
940
916
" delete " : {
@@ -1044,4 +1020,118 @@ extension DocumentTests {
1044
1020
)
1045
1021
)
1046
1022
}
1023
+
1024
+ func test_webhooks_noPaths_encode( ) throws {
1025
+ let op = OpenAPI . Operation ( responses: [ : ] )
1026
+ let pathItem : OpenAPI . PathItem = . init( get: op, put: op, post: op, delete: op, options: op, head: op, patch: op, trace: op)
1027
+ let pathItemTest : Either < OpenAPI . Reference < OpenAPI . PathItem > , OpenAPI . PathItem > = . pathItem( pathItem)
1028
+
1029
+ let document = OpenAPI . Document (
1030
+ info: . init( title: " API " , version: " 1.0 " ) ,
1031
+ servers: [ ] ,
1032
+ paths: [ : ] ,
1033
+ webhooks: [
1034
+ " webhook-test " : pathItemTest
1035
+ ] ,
1036
+ components: . noComponents,
1037
+ externalDocs: . init( url: URL ( string: " http://google.com " ) !)
1038
+ )
1039
+ let encodedDocument = try orderUnstableTestStringFromEncoding ( of: document)
1040
+
1041
+ let documentJSON : String ? =
1042
+ """
1043
+ {
1044
+ " externalDocs " : {
1045
+ " url " : " http: \\ / \\ /google.com "
1046
+ },
1047
+ " info " : {
1048
+ " title " : " API " ,
1049
+ " version " : " 1.0 "
1050
+ },
1051
+ " openapi " : " 3.1.0 " ,
1052
+ " webhooks " : {
1053
+ " webhook-test " : {
1054
+ " delete " : {
1055
+
1056
+ },
1057
+ " get " : {
1058
+
1059
+ },
1060
+ " head " : {
1061
+
1062
+ },
1063
+ " options " : {
1064
+
1065
+ },
1066
+ " patch " : {
1067
+
1068
+ },
1069
+ " post " : {
1070
+
1071
+ },
1072
+ " put " : {
1073
+
1074
+ },
1075
+ " trace " : {
1076
+
1077
+ }
1078
+ }
1079
+ }
1080
+ }
1081
+ """
1082
+
1083
+ assertJSONEquivalent ( encodedDocument, documentJSON)
1084
+ }
1085
+
1086
+ func test_webhooks_noPaths_decode( ) throws {
1087
+ let documentData =
1088
+ """
1089
+ {
1090
+ " externalDocs " : {
1091
+ " url " : " http: \\ / \\ /google.com "
1092
+ },
1093
+ " info " : {
1094
+ " title " : " API " ,
1095
+ " version " : " 1.0 "
1096
+ },
1097
+ " openapi " : " 3.1.0 " ,
1098
+ " webhooks " : {
1099
+ " webhook-test " : {
1100
+ " delete " : {
1101
+ },
1102
+ " get " : {
1103
+ },
1104
+ " head " : {
1105
+ },
1106
+ " options " : {
1107
+ },
1108
+ " patch " : {
1109
+ },
1110
+ " post " : {
1111
+ },
1112
+ " put " : {
1113
+ },
1114
+ " trace " : {
1115
+ }
1116
+ }
1117
+ }
1118
+ }
1119
+ """ . data ( using: . utf8) !
1120
+ let document = try orderUnstableDecode ( OpenAPI . Document. self, from: documentData)
1121
+
1122
+ let op = OpenAPI . Operation ( responses: [ : ] )
1123
+ XCTAssertEqual (
1124
+ document,
1125
+ OpenAPI . Document (
1126
+ info: . init( title: " API " , version: " 1.0 " ) ,
1127
+ servers: [ ] ,
1128
+ paths: [ : ] ,
1129
+ webhooks: [
1130
+ " webhook-test " : . pathItem( . init( get: op, put: op, post: op, delete: op, options: op, head: op, patch: op, trace: op) )
1131
+ ] ,
1132
+ components: . noComponents,
1133
+ externalDocs: . init( url: URL ( string: " http://google.com " ) !)
1134
+ )
1135
+ )
1136
+ }
1047
1137
}
0 commit comments