File tree 3 files changed +58
-4
lines changed
OpenAPIKitCompatibilitySuite
3 files changed +58
-4
lines changed Original file line number Diff line number Diff line change @@ -150,7 +150,9 @@ extension OpenAPI.Server.Variable: Encodable {
150
150
public func encode( to encoder: Encoder ) throws {
151
151
var container = encoder. container ( keyedBy: CodingKeys . self)
152
152
153
- try container. encode ( `enum`, forKey: . enum)
153
+ if !`enum`. isEmpty {
154
+ try container. encode ( `enum`, forKey: . enum)
155
+ }
154
156
155
157
try container. encode ( `default`, forKey: . default)
156
158
@@ -164,7 +166,7 @@ extension OpenAPI.Server.Variable: Decodable {
164
166
public init ( from decoder: Decoder ) throws {
165
167
let container = try decoder. container ( keyedBy: CodingKeys . self)
166
168
167
- `enum` = try container. decode ( [ String ] . self, forKey: . enum)
169
+ `enum` = try container. decodeIfPresent ( [ String ] . self, forKey: . enum) ?? [ ]
168
170
169
171
`default` = try container. decode ( String . self, forKey: . default)
170
172
Original file line number Diff line number Diff line change @@ -118,8 +118,7 @@ final class GoogleBooksAPICampatibilityTests: XCTestCase {
118
118
119
119
XCTAssertNotNil ( addBooksParameters)
120
120
XCTAssertEqual ( addBooksParameters? . count, 11 )
121
- XCTAssertEqual ( addBooksParameters? . first? . description, " JSONP " )
122
- XCTAssertEqual ( addBooksParameters? . first? . context, . query)
121
+ XCTAssert ( addBooksParameters? . contains { $0. description == " JSONP " && $0. context == . query } ?? false )
123
122
}
124
123
125
124
func test_dereferencedComponents( ) throws {
Original file line number Diff line number Diff line change @@ -75,6 +75,59 @@ extension ServerTests {
75
75
)
76
76
}
77
77
78
+ func test_minimalServerVariable_decode( ) {
79
+ let serverData =
80
+ """
81
+ {
82
+ " url " : " https://hello.com " ,
83
+ " variables " : {
84
+ " world " : {
85
+ " default " : " cool "
86
+ }
87
+ }
88
+ }
89
+ """ . data ( using: . utf8) !
90
+
91
+ let serverDecoded = try ! orderUnstableDecode ( Server . self, from: serverData)
92
+
93
+ XCTAssertEqual (
94
+ serverDecoded,
95
+ Server (
96
+ url: URL ( string: " https://hello.com " ) !,
97
+ variables: [
98
+ " world " : . init(
99
+ default: " cool "
100
+ )
101
+ ]
102
+ )
103
+ )
104
+ }
105
+
106
+ func test_minimalServerVariable_encode( ) {
107
+ let server = Server (
108
+ url: URL ( string: " https://hello.com " ) !,
109
+ variables: [
110
+ " world " : . init(
111
+ default: " cool "
112
+ )
113
+ ]
114
+ )
115
+ let encodedServer = try ! orderUnstableTestStringFromEncoding ( of: server)
116
+
117
+ assertJSONEquivalent ( encodedServer,
118
+ """
119
+ {
120
+ " url " : " https: \\ / \\ /hello.com " ,
121
+ " variables " : {
122
+ " world " : {
123
+ " default " : " cool "
124
+ }
125
+ }
126
+ }
127
+ """
128
+ )
129
+ }
130
+
78
131
func test_maximalServer_decode( ) {
79
132
let serverData =
80
133
"""
You can’t perform that action at this time.
0 commit comments