Skip to content

Commit 331046f

Browse files
committed
PR feedback
1 parent 570666b commit 331046f

File tree

9 files changed

+115
-132
lines changed

9 files changed

+115
-132
lines changed

Sources/OpenAPIRuntime/URICoder/Common/URIDecodedTypes.swift

Lines changed: 0 additions & 22 deletions
This file was deleted.

Sources/OpenAPIRuntime/URICoder/Common/URIEncodedNode.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ extension URIEncodedNode {
7373
/// The encoder appended to a node that wasn't an array.
7474
case appendingToNonArrayContainer
7575

76+
/// The encoder is trying to mark a container as array, but it's already
77+
/// marked as a container of another type.
78+
case markingExistingNonArrayContainerAsArray
79+
7680
/// The encoder inserted a value for key into a node that wasn't
7781
/// a dictionary.
7882
case insertingChildValueIntoNonContainer
@@ -136,7 +140,7 @@ extension URIEncodedNode {
136140
// Already an array.
137141
break
138142
case .unset: self = .array([])
139-
default: throw InsertionError.appendingToNonArrayContainer
143+
default: throw InsertionError.markingExistingNonArrayContainerAsArray
140144
}
141145
}
142146

Sources/OpenAPIRuntime/URICoder/Common/URIParsedTypes.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ struct URIParsedKey: Hashable {
3838
/// A primitive value produced by `URIParser`.
3939
typealias URIParsedValue = String.SubSequence
4040

41-
/// An array of primitive values produced by `URIParser`.
42-
typealias URIParsedValueArray = [URIParsedValue]
43-
4441
/// A key-value produced by `URIParser`.
4542
struct URIParsedPair: Equatable {
4643

@@ -55,9 +52,6 @@ struct URIParsedPair: Equatable {
5552
var value: URIParsedValue
5653
}
5754

58-
/// An array of key-value pairs produced by `URIParser`.
59-
typealias URIParsedPairArray = [URIParsedPair]
60-
6155
// MARK: - Extensions
6256

6357
extension URIParsedKey: CustomStringConvertible {

Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder+Keyed.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,9 @@ extension URIKeyedDecodingContainer {
9494

9595
extension URIKeyedDecodingContainer: KeyedDecodingContainerProtocol {
9696

97-
var allKeys: [Key] {
98-
do { return try decoder.elementKeysInCurrentDictionary().compactMap { .init(stringValue: $0) } } catch {
99-
return []
100-
}
101-
}
97+
var allKeys: [Key] { decoder.elementKeysInCurrentDictionary().compactMap { .init(stringValue: $0) } }
10298

103-
func contains(_ key: Key) -> Bool {
104-
do { return try decoder.containsElementInCurrentDictionary(forKey: key.stringValue) } catch { return false }
105-
}
99+
func contains(_ key: Key) -> Bool { decoder.containsElementInCurrentDictionary(forKey: key.stringValue) }
106100

107101
var codingPath: [any CodingKey] { decoder.codingPath }
108102

Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder+Single.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ struct URISingleValueDecodingContainer {
2424
extension URISingleValueDecodingContainer {
2525

2626
/// The underlying value as a single value.
27+
///
28+
/// Can be nil if the underlying URI is valid, just doesn't contain any value.
29+
///
30+
/// For example, an empty string input into an exploded form decoder (expecting pairs in the form `key=value`)
31+
/// would result in a nil returned value.
2732
var value: URIParsedValue? { get throws { try decoder.currentElementAsSingleValue() } }
2833

2934
/// Returns the value found in the underlying node converted to

Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder+Unkeyed.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ struct URIUnkeyedDecodingContainer {
2020
let decoder: URIValueFromNodeDecoder
2121

2222
/// The index of the next item to be decoded.
23-
private var index: URIParsedValueArray.Index = 0
23+
private(set) var currentIndex: Int
2424

2525
/// Creates a new unkeyed container ready to decode the first key.
2626
/// - Parameter decoder: The underlying decoder.
27-
init(decoder: URIValueFromNodeDecoder) { self.decoder = decoder }
27+
init(decoder: URIValueFromNodeDecoder) {
28+
self.decoder = decoder
29+
self.currentIndex = 0
30+
}
2831
}
2932

3033
extension URIUnkeyedDecodingContainer {
@@ -36,7 +39,7 @@ extension URIUnkeyedDecodingContainer {
3639
/// - Throws: An error if the container ran out of items.
3740
private mutating func _decodingNext<R>(in work: () throws -> R) throws -> R {
3841
guard !isAtEnd else { throw URIValueFromNodeDecoder.GeneralError.reachedEndOfUnkeyedContainer }
39-
defer { index += 1 }
42+
defer { currentIndex += 1 }
4043
return try work()
4144
}
4245

@@ -45,7 +48,7 @@ extension URIUnkeyedDecodingContainer {
4548
/// - Returns: The next value found.
4649
/// - Throws: An error if the container ran out of items.
4750
private mutating func _decodeNext() throws -> URIParsedValue {
48-
try _decodingNext { [decoder, index] in try decoder.nestedElementInCurrentArray(atIndex: index) }
51+
try _decodingNext { [decoder, currentIndex] in try decoder.nestedElementInCurrentArray(atIndex: currentIndex) }
4952
}
5053

5154
/// Returns the next value converted to the provided type.
@@ -103,9 +106,7 @@ extension URIUnkeyedDecodingContainer: UnkeyedDecodingContainer {
103106

104107
var count: Int? { try? decoder.countOfCurrentArray() }
105108

106-
var isAtEnd: Bool { index == count }
107-
108-
var currentIndex: Int { index }
109+
var isAtEnd: Bool { currentIndex == count }
109110

110111
var codingPath: [any CodingKey] { decoder.codingPath }
111112

0 commit comments

Comments
 (0)