Skip to content

Commit

Permalink
1.7.16
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Apr 13, 2024
1 parent 78871a0 commit 59b12f2
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
8 changes: 4 additions & 4 deletions Sources/SwiftAPIClient/Utils/Coders/FormURLEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public extension ContentEncoder where Self == FormURLEncoder {
/// - Parameters:
/// - dateEncodingStrategy: Strategy for encoding date values. Default is `SecondsSince1970CodingStrategy`.
/// - keyEncodingStrategy: Strategy for encoding key names. Default is `UseDeafultKeyCodingStrategy`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.brackets(indexed: false)`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.commaSeparator`.
/// - nestedEncodingStrategy: Strategy for encoding nested objects. Default is `.brackets`.
/// - boolEncodingStrategy: Strategy for encoding boolean values. Default is `.literal`.
/// - Returns: An instance of `Self` configured with the specified strategies.
static func formURL(
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: URLQueryEncoder.NestedEncodingStrategy = .brackets,
boolEncodingStrategy: URLQueryEncoder.BoolEncodingStrategy = .literal
) -> Self {
Expand All @@ -39,13 +39,13 @@ public struct FormURLEncoder: ContentEncoder {
/// - Parameters:
/// - dateEncodingStrategy: Strategy for encoding date values. Default is `SecondsSince1970CodingStrategy`.
/// - keyEncodingStrategy: Strategy for encoding key names. Default is `UseDeafultKeyCodingStrategy`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.brackets(indexed: true)`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.commaSeparator`.
/// - nestedEncodingStrategy: Strategy for encoding nested objects. Default is `.brackets`.
/// - boolEncodingStrategy: Strategy for encoding boolean values. Default is `.literal`.
public init(
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: URLQueryEncoder.NestedEncodingStrategy = .brackets,
boolEncodingStrategy: URLQueryEncoder.BoolEncodingStrategy = .literal
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public extension ContentEncoder where Self == MultipartFormDataEncoder {
boundary: String? = nil,
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: URLQueryEncoder.NestedEncodingStrategy = .brackets,
boolEncodingStrategy: URLQueryEncoder.BoolEncodingStrategy = .literal
) -> Self {
Expand Down Expand Up @@ -44,7 +44,7 @@ public struct MultipartFormDataEncoder: ContentEncoder {
boundary: String? = nil,
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: URLQueryEncoder.NestedEncodingStrategy = .brackets,
boolEncodingStrategy: URLQueryEncoder.BoolEncodingStrategy = .literal
) {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftAPIClient/Utils/Coders/QueryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public extension QueryEncoder where Self == URLQueryEncoder {
/// - Parameters:
/// - dateEncodingStrategy: Strategy for encoding date values. Default is `SecondsSince1970CodingStrategy`.
/// - keyEncodingStrategy: Strategy for encoding key names. Default is `UseDeafultKeyCodingStrategy`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.brackets(indexed: false)`.
/// - arrayEncodingStrategy: Strategy for encoding arrays. Default is `.commaSeparator`.
/// - nestedEncodingStrategy: Strategy for encoding nested objects. Default is `.brackets`.
/// - boolEncodingStrategy: Strategy for encoding boolean values. Default is `.literal`.
/// - Returns: An instance of `URLQueryEncoder` configured with the specified strategies.
static func urlQuery(
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: URLQueryEncoder.ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: URLQueryEncoder.NestedEncodingStrategy = .brackets,
boolEncodingStrategy: URLQueryEncoder.BoolEncodingStrategy = .literal
) -> Self {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct URLQueryEncoder: QueryEncoder {
public init(
dateEncodingStrategy: JSONEncoder.DateEncodingStrategy = .deferredToDate,
keyEncodingStrategy: JSONEncoder.KeyEncodingStrategy = .useDefaultKeys,
arrayEncodingStrategy: ArrayEncodingStrategy = .brackets(indexed: false),
arrayEncodingStrategy: ArrayEncodingStrategy = .commaSeparator,
nestedEncodingStrategy: NestedEncodingStrategy = .brackets,
boolEncodingStrategy: BoolEncodingStrategy = .literal
) {
Expand Down
9 changes: 4 additions & 5 deletions Tests/SwiftAPIClientTests/URLQueryEncoderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,13 @@ final class FormURLEncoderTests: XCTestCase {
let result = try? String(data: encoder.encode(parameters), encoding: .utf8)

// Then
let expected = "one=one&two=2&three=true&four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&five%5Ba%5D=a&six%5Ba%5D%5Bb%5D=b&seven%5Ba%5D=a"
let expected = "one=one&two=2&three=true&four=1%2C2%2C3&five%5Ba%5D=a&six%5Ba%5D%5Bb%5D=b&seven%5Ba%5D=a"
XCTAssertEqual(result, expected)
}

func testThatManuallyEncodableStructCanBeEncoded() {
// Given
let encoder = FormURLEncoder()
let encoder = FormURLEncoder(arrayEncodingStrategy: .brackets(indexed: false))
let parameters = ManuallyEncodableStruct()

// When
Expand Down Expand Up @@ -300,21 +300,20 @@ final class FormURLEncoderTests: XCTestCase {
let result = try? String(data: encoder.encode(parameters), encoding: .utf8)

// Then
let expected = "one=one&two=2&three=true&four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&five%5Ba%5D=a&five%5Bb%5D=b"
let expected = "one=one&two=2&three=true&four=1%2C2%2C3&five%5Ba%5D=a&five%5Bb%5D=b"
XCTAssertEqual(result, expected)
}

func testThatManuallyEncodableSubclassCanBeEncoded() {
// Given
let encoder = FormURLEncoder()
let encoder = FormURLEncoder(arrayEncodingStrategy: .brackets(indexed: false))
let parameters = ManuallyEncodableSubclass()

// When
let result = try? String(data: encoder.encode(parameters), encoding: .utf8)

// Then
let expected = "four%5B%5D=1&four%5B%5D=2&four%5B%5D=3&five%5Ba%5D=a&five%5Bb%5D=b&four=one&four%5Bfive%5D=2&four%5B%5D%5Bfour%5D=one"
// four[]=1&four[]=2&four[]=3&five[a]=a&five[b]=b&four=one&four[five]=2&four[][four]=one
XCTAssertEqual(result, expected)
}

Expand Down

0 comments on commit 59b12f2

Please sign in to comment.