File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Sources/OpenAPIKitCore/AnyCodable
Tests/OpenAPIKitCoreTests/URLTemplate Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -49,10 +49,24 @@ public struct AnyCodable: @unchecked Sendable {
49
49
}
50
50
}
51
51
52
+ protocol _Optional {
53
+ var isNil : Bool { get }
54
+ }
55
+
56
+ extension Optional : _Optional {
57
+ var isNil : Bool { return self == nil }
58
+ }
59
+
52
60
extension AnyCodable : Encodable {
53
61
public func encode( to encoder: Encoder ) throws {
54
62
var container = encoder. singleValueContainer ( )
55
63
64
+ // special nil case
65
+ if let optionalValue = value as? _Optional , optionalValue. isNil {
66
+ try container. encodeNil ( )
67
+ return
68
+ }
69
+
56
70
switch value {
57
71
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
58
72
case let number as NSNumber :
Original file line number Diff line number Diff line change @@ -391,7 +391,7 @@ extension URLTemplateTests {
391
391
}
392
392
393
393
""" . utf8)
394
- let document = try JSONDecoder ( ) . decode (
394
+ let _ = try JSONDecoder ( ) . decode (
395
395
StackFoo . self,
396
396
from: data
397
397
)
You can’t perform that action at this time.
0 commit comments