Skip to content

Commit 634b7eb

Browse files
authored
Fix empty additionalProperties dictionary encoding (#103)
### Motivation Fixes apple/swift-openapi-generator#525. Turns out that the mere act of creating a decoding container is meaningful and we skipped it as an optimization, causing JSONDecoder to fail for empty dictionaries when used in additional properties. ### Modifications Remove the extra guards that skipped creating a container, even when we already know there are no elements. ### Result No more failures when encoding empty dictionaries in additionalProperties. ### Test Plan Tested manually as this requirement seems to be coming out of JSONDecoder.
1 parent a875c2d commit 634b7eb

File tree

1 file changed

+0
-2
lines changed

1 file changed

+0
-2
lines changed

Sources/OpenAPIRuntime/Conversion/CodableExtensions.swift

-2
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
/// - Parameter additionalProperties: A container of additional properties.
103103
/// - Throws: An error if there are issues with encoding the additional properties.
104104
public func encodeAdditionalProperties(_ additionalProperties: OpenAPIObjectContainer) throws {
105-
guard !additionalProperties.value.isEmpty else { return }
106105
var container = container(keyedBy: StringKey.self)
107106
for (key, value) in additionalProperties.value {
108107
try container.encode(OpenAPIValueContainer(unvalidatedValue: value), forKey: .init(key))
@@ -116,7 +115,6 @@
116115
/// - Parameter additionalProperties: A container of additional properties.
117116
/// - Throws: An error if there are issues with encoding the additional properties.
118117
public func encodeAdditionalProperties<T: Encodable>(_ additionalProperties: [String: T]) throws {
119-
guard !additionalProperties.isEmpty else { return }
120118
var container = container(keyedBy: StringKey.self)
121119
for (key, value) in additionalProperties { try container.encode(value, forKey: .init(key)) }
122120
}

0 commit comments

Comments
 (0)