Skip to content

Commit c3d9ec3

Browse files
committed
Doc fixes
1 parent 49eef87 commit c3d9ec3

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

Sources/OpenAPIRuntime/URICoder/Common/URIParsedTypes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ struct URIParsedKey: Hashable {
2626

2727
/// The individual string components.
2828
let components: [URIParsedKeyComponent]
29-
3029
/// Creates a new parsed key.
3130
/// - Parameter components: The key components.
3231
init(_ components: [URIParsedKeyComponent]) { self.components = components }

Sources/OpenAPIRuntime/URICoder/Decoding/URIDecoder.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,7 @@ extension URIDecoder {
7474
/// - data: The URI-encoded string.
7575
/// - Returns: The decoded value.
7676
/// - Throws: An error if decoding fails, for example, due to incompatible data or key.
77-
func decode<T: Decodable>(
78-
_ type: T.Type = T.self,
79-
forKey key: String = "",
80-
from data: Substring
81-
) throws -> T {
77+
func decode<T: Decodable>(_ type: T.Type = T.self, forKey key: String = "", from data: Substring) throws -> T {
8278
let decoder = URIValueFromNodeDecoder(data: data, rootKey: key[...], configuration: configuration)
8379
return try decoder.decodeRoot(type)
8480
}

Sources/OpenAPIRuntime/URICoder/Decoding/URIValueFromNodeDecoder.swift

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ final class URIValueFromNodeDecoder {
5656
/// - data: The data to parse.
5757
/// - rootKey: The key of the root object.
5858
/// - configuration: The configuration of the decoder.
59-
init(
60-
data: Substring,
61-
rootKey: URIParsedKeyComponent,
62-
configuration: URICoderConfiguration
63-
) {
59+
init(data: Substring, rootKey: URIParsedKeyComponent, configuration: URICoderConfiguration) {
6460
self.rootKey = rootKey
6561
self.dateTranscoder = configuration.dateTranscoder
6662
self.configuration = configuration
@@ -144,6 +140,7 @@ extension URIValueFromNodeDecoder {
144140
/// Use the root as a primitive value.
145141
/// - Parameter work: The closure in which to use the value.
146142
/// - Returns: Any value returned from the closure.
143+
/// - Throws: When parsing the root fails.
147144
private func withParsedRootAsPrimitive<R>(_ work: (URIDecodedPrimitive?) throws -> R) throws -> R {
148145
let value: URIDecodedPrimitive?
149146
if let cached = cache.primitive {
@@ -165,6 +162,7 @@ extension URIValueFromNodeDecoder {
165162
/// Use the root as an array.
166163
/// - Parameter work: The closure in which to use the value.
167164
/// - Returns: Any value returned from the closure.
165+
/// - Throws: When parsing the root fails.
168166
private func withParsedRootAsArray<R>(_ work: (URIDecodedArray) throws -> R) throws -> R {
169167
let value: URIDecodedArray
170168
if let cached = cache.array {
@@ -186,6 +184,7 @@ extension URIValueFromNodeDecoder {
186184
/// Use the root as a dictionary.
187185
/// - Parameter work: The closure in which to use the value.
188186
/// - Returns: Any value returned from the closure.
187+
/// - Throws: When parsing the root fails.
189188
private func withParsedRootAsDictionary<R>(_ work: (URIDecodedDictionary) throws -> R) throws -> R {
190189
let value: URIDecodedDictionary
191190
if let cached = cache.dictionary {
@@ -234,6 +233,7 @@ extension URIValueFromNodeDecoder {
234233
/// - key: The key for which to return the value.
235234
/// - dictionary: The dictionary in which to find the value.
236235
/// - Returns: The value in the dictionary, or nil if not found.
236+
/// - Throws: When multiple values are found for the key.
237237
func primitiveValue(forKey key: String, in dictionary: URIDecodedDictionary) throws -> URIParsedValue? {
238238
let values = dictionary[key[...], default: []]
239239
if values.isEmpty { return nil }
@@ -246,6 +246,7 @@ extension URIValueFromNodeDecoder {
246246
/// Use the current top of the stack as a primitive value.
247247
/// - Parameter work: The closure in which to use the value.
248248
/// - Returns: Any value returned from the closure.
249+
/// - Throws: When parsing the root fails.
249250
private func withCurrentPrimitiveElement<R>(_ work: (URIDecodedPrimitive?) throws -> R) throws -> R {
250251
if !codingStack.isEmpty {
251252
// Nesting is involved.
@@ -285,6 +286,7 @@ extension URIValueFromNodeDecoder {
285286
/// Use the current top of the stack as an array.
286287
/// - Parameter work: The closure in which to use the value.
287288
/// - Returns: Any value returned from the closure.
289+
/// - Throws: When parsing the root fails.
288290
private func withCurrentArrayElements<R>(_ work: (URIDecodedArray) throws -> R) throws -> R {
289291
if let nestedArrayParentKey = codingStack.first {
290292
// Top level is dictionary, first level nesting is array.
@@ -301,6 +303,7 @@ extension URIValueFromNodeDecoder {
301303
/// Use the current top of the stack as a dictionary.
302304
/// - Parameter work: The closure in which to use the value.
303305
/// - Returns: Any value returned from the closure.
306+
/// - Throws: When parsing the root fails or if there is unsupported extra nesting of containers.
304307
private func withCurrentDictionaryElements<R>(_ work: (URIDecodedDictionary) throws -> R) throws -> R {
305308
if !codingStack.isEmpty {
306309
try throwMismatch("Nesting a dictionary inside another container is not supported.")
@@ -314,22 +317,26 @@ extension URIValueFromNodeDecoder {
314317

315318
/// Returns the current top-of-stack as a primitive value.
316319
/// - Returns: The primitive value, or nil if not found.
320+
/// - Throws: When parsing the root fails.
317321
func currentElementAsSingleValue() throws -> URIParsedValue? { try withCurrentPrimitiveElement { $0 } }
318322

319323
/// Returns the count of elements in the current top-of-stack array.
320324
/// - Returns: The number of elements.
325+
/// - Throws: When parsing the root fails.
321326
func countOfCurrentArray() throws -> Int { try withCurrentArrayElements { $0.count } }
322327

323328
/// Returns an element from the current top-of-stack array.
324329
/// - Parameter index: The position in the array to return.
325330
/// - Returns: The primitive value from the array.
331+
/// - Throws: When parsing the root fails.
326332
func nestedElementInCurrentArray(atIndex index: Int) throws -> URIParsedValue {
327333
try withCurrentArrayElements { $0[index] }
328334
}
329335

330336
/// Returns an element from the current top-of-stack dictionary.
331337
/// - Parameter key: The key to find a value for.
332338
/// - Returns: The value for the key, or nil if not found.
339+
/// - Throws: When parsing the root fails.
333340
func nestedElementInCurrentDictionary(forKey key: String) throws -> URIParsedValue? {
334341
try withCurrentDictionaryElements { dictionary in try primitiveValue(forKey: key, in: dictionary) }
335342
}
@@ -338,12 +345,14 @@ extension URIValueFromNodeDecoder {
338345
/// contains a value for the provided key.
339346
/// - Parameter key: The key for which to look for a value.
340347
/// - Returns: `true` if a value was found, `false` otherwise.
348+
/// - Throws: When parsing the root fails.
341349
func containsElementInCurrentDictionary(forKey key: String) throws -> Bool {
342350
try withCurrentDictionaryElements { dictionary in dictionary[key[...]] != nil }
343351
}
344352

345353
/// Returns a list of keys found in the current top-of-stack dictionary.
346354
/// - Returns: A list of keys from the dictionary.
355+
/// - Throws: When parsing the root fails.
347356
func elementKeysInCurrentDictionary() throws -> [String] {
348357
try withCurrentDictionaryElements { dictionary in dictionary.keys.map(String.init) }
349358
}

Sources/OpenAPIRuntime/URICoder/Parsing/URIParser.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ enum ParsingError: Swift.Error, Hashable {
4949
// MARK: - Parser implementations
5050

5151
extension URIParser {
52-
5352
/// Parses the string as a primitive value.
5453
/// - Parameter rootKey: The key of the root object, used to filter out unrelated values.
5554
/// - Returns: The parsed primitive value, or nil if not found.
55+
/// - Throws: When parsing the root fails.
5656
func parseRootAsPrimitive(rootKey: URIParsedKeyComponent) throws -> URIParsedPair? {
5757
var data = data
5858
switch (configuration.style, configuration.explode) {
@@ -90,6 +90,7 @@ extension URIParser {
9090
/// Parses the string as an array.
9191
/// - Parameter rootKey: The key of the root object, used to filter out unrelated values.
9292
/// - Returns: The parsed array.
93+
/// - Throws: When parsing the root fails.
9394
func parseRootAsArray(rootKey: URIParsedKeyComponent) throws -> URIParsedPairArray {
9495
var data = data
9596
switch (configuration.style, configuration.explode) {
@@ -169,6 +170,7 @@ extension URIParser {
169170
/// Parses the string as a dictionary.
170171
/// - Parameter rootKey: The key of the root object, used to filter out unrelated values.
171172
/// - Returns: The parsed key/value pairs as an array.
173+
/// - Throws: When parsing the root fails.
172174
func parseRootAsDictionary(rootKey: URIParsedKeyComponent) throws -> URIParsedPairArray {
173175
var data = data
174176
switch (configuration.style, configuration.explode) {

0 commit comments

Comments
 (0)