Skip to content

Commit

Permalink
fix(swift): don't overwrite decimal encoding/decoding methods (genera…
Browse files Browse the repository at this point in the history
…ted)

algolia/api-clients-automation#4428

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Thomas Raffray <[email protected]>
  • Loading branch information
algolia-bot and Fluf22 committed Feb 5, 2025
1 parent 3c61175 commit ae1342c
Showing 1 changed file with 0 additions and 40 deletions.
40 changes: 0 additions & 40 deletions Sources/Core/Helpers/Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -161,18 +161,6 @@ public extension KeyedEncodingContainerProtocol {
try self.encodeMap(pairs)
}
}

mutating func encode(_ value: Decimal, forKey key: Self.Key) throws {
var mutableValue = value
let stringValue = NSDecimalString(&mutableValue, Locale(identifier: "en_US"))
try self.encode(stringValue, forKey: key)
}

mutating func encodeIfPresent(_ value: Decimal?, forKey key: Self.Key) throws {
if let value {
try self.encode(value, forKey: key)
}
}
}

public extension KeyedDecodingContainerProtocol {
Expand Down Expand Up @@ -213,34 +201,6 @@ public extension KeyedDecodingContainerProtocol {

return map
}

func decode(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal {
let stringValue = try decode(String.self, forKey: key)
guard let decimalValue = Decimal(string: stringValue) else {
let context = DecodingError.Context(
codingPath: [key],
debugDescription: "The key \(key) couldn't be converted to a Decimal value"
)
throw DecodingError.typeMismatch(type, context)
}

return decimalValue
}

func decodeIfPresent(_ type: Decimal.Type, forKey key: Self.Key) throws -> Decimal? {
guard let stringValue = try decodeIfPresent(String.self, forKey: key) else {
return nil
}
guard let decimalValue = Decimal(string: stringValue) else {
let context = DecodingError.Context(
codingPath: [key],
debugDescription: "The key \(key) couldn't be converted to a Decimal value"
)
throw DecodingError.typeMismatch(type, context)
}

return decimalValue
}
}

extension HTTPURLResponse {
Expand Down

0 comments on commit ae1342c

Please sign in to comment.