Skip to content

Commit

Permalink
1.25.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dankinsoid committed Jun 17, 2024
1 parent 84f755d commit 8f0fc37
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Sources/SwiftAPIClient/Utils/Coders/URLQuery/URLQueryEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,13 @@ public struct URLQueryEncoder: QueryEncoder {

public enum NestedEncodingStrategy {

case brackets, dots, json(JSONEncoder?)
case brackets, dots, json(JSONEncoder? = nil, encode: ValueType = .objects)

public static var json: NestedEncodingStrategy { .json(nil) }

public enum ValueType {
case objects, arraysAndObjects
}
}

private func getQueryItems(from output: QueryValue, percentEncoded: Bool) throws -> [URLQueryItem] {
Expand Down Expand Up @@ -262,7 +266,11 @@ final class _URLQueryEncoder: Encoder {
try? value.encode(to: isArrayEncoder)
let isArray = isArrayEncoder.isArray ?? false
let isSingle = isArrayEncoder.isSingle ?? false
if !isSingle, case let .json(jsonEncoder) = context.nestedEncodingStrategy, !codingPath.isEmpty, !(codingPath.count < 2 && isArray) {
if
!isSingle,
case let .json(jsonEncoder, encodeType) = context.nestedEncodingStrategy,
!codingPath.isEmpty,
!(codingPath.count < 2 && isArray && encodeType == .objects) {
let jsonEncoder = jsonEncoder ?? {
let encoder = JSONEncoder()
encoder.dateEncodingStrategy = context.dateEncodingStrategy
Expand Down

0 comments on commit 8f0fc37

Please sign in to comment.