@@ -98,6 +98,10 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
98
98
99
99
// MARK: Decodable
100
100
101
+ /// Initializes an `OpenAPIValueContainer` by decoding it from a decoder.
102
+ ///
103
+ /// - Parameter decoder: The decoder to read data from.
104
+ /// - Throws: An error if the decoding process encounters issues or if the data is corrupted.
101
105
public init ( from decoder: any Decoder ) throws {
102
106
let container = try decoder. singleValueContainer ( )
103
107
if container. decodeNil ( ) {
@@ -124,6 +128,10 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
124
128
125
129
// MARK: Encodable
126
130
131
+ /// Encodes the `OpenAPIValueContainer` and writes it to an encoder.
132
+ ///
133
+ /// - Parameter encoder: The encoder to which the value should be encoded.
134
+ /// - Throws: An error if the encoding process encounters issues or if the value is invalid.
127
135
public func encode( to encoder: any Encoder ) throws {
128
136
var container = encoder. singleValueContainer ( )
129
137
guard let value = value else {
@@ -153,6 +161,12 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
153
161
154
162
// MARK: Equatable
155
163
164
+ /// Compares two `OpenAPIValueContainer` instances for equality.
165
+ ///
166
+ /// - Parameters:
167
+ /// - lhs: The left-hand side `OpenAPIValueContainer` to compare.
168
+ /// - rhs: The right-hand side `OpenAPIValueContainer` to compare.
169
+ /// - Returns: `true` if the two instances are equal, `false` otherwise.
156
170
public static func == ( lhs: OpenAPIValueContainer , rhs: OpenAPIValueContainer ) -> Bool {
157
171
switch ( lhs. value, rhs. value) {
158
172
case ( nil , nil ) , is ( Void , Void ) :
@@ -201,6 +215,9 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
201
215
202
216
// MARK: Hashable
203
217
218
+ /// Hashes the `OpenAPIValueContainer` instance into a hasher.
219
+ ///
220
+ /// - Parameter hasher: The hasher used to compute the hash value.
204
221
public func hash( into hasher: inout Hasher ) {
205
222
switch value {
206
223
case let value as Bool :
@@ -227,30 +244,45 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
227
244
}
228
245
229
246
extension OpenAPIValueContainer : ExpressibleByBooleanLiteral {
247
+ /// Creates an `OpenAPIValueContainer` with the provided boolean value.
248
+ ///
249
+ /// - Parameter value: The boolean value to store in the container.
230
250
public init ( booleanLiteral value: BooleanLiteralType ) {
231
251
self . init ( validatedValue: value)
232
252
}
233
253
}
234
254
235
255
extension OpenAPIValueContainer : ExpressibleByStringLiteral {
256
+ /// Creates an `OpenAPIValueContainer` with the provided string value.
257
+ ///
258
+ /// - Parameter value: The string value to store in the container.
236
259
public init ( stringLiteral value: String ) {
237
260
self . init ( validatedValue: value)
238
261
}
239
262
}
240
263
241
264
extension OpenAPIValueContainer : ExpressibleByNilLiteral {
265
+ /// Creates an `OpenAPIValueContainer` with a `nil` value.
266
+ ///
267
+ /// - Parameter nilLiteral: The `nil` literal.
242
268
public init ( nilLiteral: ( ) ) {
243
269
self . init ( validatedValue: nil )
244
270
}
245
271
}
246
272
247
273
extension OpenAPIValueContainer : ExpressibleByIntegerLiteral {
274
+ /// Creates an `OpenAPIValueContainer` with the provided integer value.
275
+ ///
276
+ /// - Parameter value: The integer value to store in the container.
248
277
public init ( integerLiteral value: Int ) {
249
278
self . init ( validatedValue: value)
250
279
}
251
280
}
252
281
253
282
extension OpenAPIValueContainer : ExpressibleByFloatLiteral {
283
+ /// Creates an `OpenAPIValueContainer` with the provided floating-point value.
284
+ ///
285
+ /// - Parameter value: The floating-point value to store in the container.
254
286
public init ( floatLiteral value: Double ) {
255
287
self . init ( validatedValue: value)
256
288
}
@@ -317,6 +349,10 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
317
349
318
350
// MARK: Decodable
319
351
352
+ /// Creates an `OpenAPIValueContainer` by decoding it from a single-value container in a given decoder.
353
+ ///
354
+ /// - Parameter decoder: The decoder used to decode the container.
355
+ /// - Throws: An error if the decoding process encounters an issue or if the data does not match the expected format.
320
356
public init ( from decoder: any Decoder ) throws {
321
357
let container = try decoder. singleValueContainer ( )
322
358
let item = try container. decode ( [ String : OpenAPIValueContainer ] . self)
@@ -325,13 +361,24 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
325
361
326
362
// MARK: Encodable
327
363
364
+ /// Encodes the `OpenAPIValueContainer` into a format that can be stored or transmitted via the given encoder.
365
+ ///
366
+ /// - Parameter encoder: The encoder used to perform the encoding.
367
+ /// - Throws: An error if the encoding process encounters an issue or if the data does not match the expected format.
328
368
public func encode( to encoder: any Encoder ) throws {
329
369
var container = encoder. singleValueContainer ( )
330
370
try container. encode ( value. mapValues ( OpenAPIValueContainer . init ( validatedValue: ) ) )
331
371
}
332
372
333
373
// MARK: Equatable
334
374
375
+ /// Compares two `OpenAPIObjectContainer` instances for equality by comparing their inner key-value dictionaries.
376
+ ///
377
+ /// - Parameters:
378
+ /// - lhs: The left-hand side `OpenAPIObjectContainer` to compare.
379
+ /// - rhs: The right-hand side `OpenAPIObjectContainer` to compare.
380
+ ///
381
+ /// - Returns: `true` if the `OpenAPIObjectContainer` instances are equal, `false` otherwise.
335
382
public static func == ( lhs: OpenAPIObjectContainer , rhs: OpenAPIObjectContainer ) -> Bool {
336
383
let lv = lhs. value
337
384
let rv = rhs. value
@@ -352,6 +399,9 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
352
399
353
400
// MARK: Hashable
354
401
402
+ /// Hashes the `OpenAPIObjectContainer` instance into the provided `Hasher`.
403
+ ///
404
+ /// - Parameter hasher: The `Hasher` into which the hash value is combined.
355
405
public func hash( into hasher: inout Hasher ) {
356
406
for (key, itemValue) in value {
357
407
hasher. combine ( key)
@@ -414,12 +464,17 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
414
464
/// Returns the specified value cast to an array of supported values.
415
465
/// - Parameter value: An array with untyped values.
416
466
/// - Returns: A cast value if values are supported, nil otherwise.
467
+ /// - Throws: An error if casting to supported values fails for any element.
417
468
static func tryCast( _ value: [ ( any Sendable ) ? ] ) throws -> [ ( any Sendable ) ? ] {
418
469
return try value. map ( OpenAPIValueContainer . tryCast ( _: ) )
419
470
}
420
471
421
472
// MARK: Decodable
422
473
474
+ /// Initializes a new instance by decoding a validated array of values from a decoder.
475
+ ///
476
+ /// - Parameter decoder: The decoder to use for decoding the array of values.
477
+ /// - Throws: An error if the decoding process fails or if the decoded values cannot be validated.
423
478
public init ( from decoder: any Decoder ) throws {
424
479
let container = try decoder. singleValueContainer ( )
425
480
let item = try container. decode ( [ OpenAPIValueContainer ] . self)
@@ -428,13 +483,23 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
428
483
429
484
// MARK: Encodable
430
485
486
+ /// Encodes the array of validated values and stores the result in the given encoder.
487
+ ///
488
+ /// - Parameter encoder: The encoder to use for encoding the array of values.
489
+ /// - Throws: An error if the encoding process fails.
431
490
public func encode( to encoder: any Encoder ) throws {
432
491
var container = encoder. singleValueContainer ( )
433
492
try container. encode ( value. map ( OpenAPIValueContainer . init ( validatedValue: ) ) )
434
493
}
435
494
436
495
// MARK: Equatable
437
496
497
+ /// Compares two `OpenAPIArrayContainer` instances for equality.
498
+ ///
499
+ /// - Parameters:
500
+ /// - lhs: The left-hand side `OpenAPIArrayContainer` to compare.
501
+ /// - rhs: The right-hand side `OpenAPIArrayContainer` to compare.
502
+ /// - Returns: `true` if the two `OpenAPIArrayContainer` instances are equal, `false` otherwise.
438
503
public static func == ( lhs: OpenAPIArrayContainer , rhs: OpenAPIArrayContainer ) -> Bool {
439
504
let lv = lhs. value
440
505
let rv = rhs. value
@@ -449,6 +514,9 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
449
514
450
515
// MARK: Hashable
451
516
517
+ /// Hashes the `OpenAPIArrayContainer` instance into a hasher.
518
+ ///
519
+ /// - Parameter hasher: The hasher used to compute the hash value.
452
520
public func hash( into hasher: inout Hasher ) {
453
521
for item in value {
454
522
hasher. combine ( OpenAPIValueContainer ( validatedValue: item) )
0 commit comments