Skip to content

Commit 9633ee2

Browse files
committed
Code format fixes
1 parent 3aae2c7 commit 9633ee2

File tree

9 files changed

+32
-109
lines changed

9 files changed

+32
-109
lines changed

Sources/OpenAPIRuntime/Conversion/ParameterStyles.swift

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
///
2727
/// Details: https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.2
2828
case simple
29-
3029
/// The deepObject style.
3130
///
3231
/// Details: https://spec.openapis.org/oas/v3.1.0.html#style-values

Sources/OpenAPIRuntime/URICoder/Common/URICoderConfiguration.swift

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ struct URICoderConfiguration {
2525

2626
/// A style for form-based URI expansion.
2727
case form
28-
2928
/// A style for nested variable expansion
3029
case deepObject
3130
}

Sources/OpenAPIRuntime/URICoder/Parsing/URIParser.swift

+2-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ enum ParsingError: Swift.Error, Hashable {
4343

4444
/// A malformed key-value pair was detected.
4545
case malformedKeyValuePair(Raw)
46-
4746
/// An invalid configuration was detected.
4847
case invalidConfiguration(String)
4948
}
@@ -213,7 +212,6 @@ extension URIParser {
213212
}
214213
}
215214
}
216-
217215
/// Parses the root node assuming the raw string uses the deepObject style
218216
/// and the explode parameter is enabled.
219217
/// - Returns: The parsed root node.
@@ -224,35 +222,26 @@ extension URIParser {
224222
let pairSeparator: Character = "&"
225223
let nestedKeyStartingCharacter: Character = "["
226224
let nestedKeyEndingCharacter: Character = "]"
227-
228225
func nestedKey(from deepObjectKey: String.SubSequence) -> Raw {
229226
var unescapedDeepObjectKey = Substring(deepObjectKey.removingPercentEncoding ?? "")
230227
let topLevelKey = unescapedDeepObjectKey.parseUpToCharacterOrEnd(nestedKeyStartingCharacter)
231228
let nestedKey = unescapedDeepObjectKey.parseUpToCharacterOrEnd(nestedKeyEndingCharacter)
232229
return nestedKey.isEmpty ? topLevelKey : nestedKey
233230
}
234-
235231
while !data.isEmpty {
236232
let (firstResult, firstValue) = data.parseUpToEitherCharacterOrEnd(
237233
first: keyValueSeparator,
238234
second: pairSeparator
239235
)
240-
241-
guard case .foundFirst = firstResult else {
242-
throw ParsingError.malformedKeyValuePair(firstValue)
243-
}
236+
guard case .foundFirst = firstResult else { throw ParsingError.malformedKeyValuePair(firstValue) }
244237
// Hit the key/value separator, so a value will follow.
245238
let secondValue = data.parseUpToCharacterOrEnd(pairSeparator)
246239
let key = nestedKey(from: firstValue)
247240
let value = secondValue
248-
249241
appendPair(key, [value])
250242
}
251243
}
252-
253-
try parseNode.forEach { (key, value) in
254-
if value.count > 1 { throw ParsingError.malformedKeyValuePair(key) }
255-
}
244+
for (key, value) in parseNode where value.count > 1 { throw ParsingError.malformedKeyValuePair(key) }
256245
return parseNode
257246
}
258247
}

Sources/OpenAPIRuntime/URICoder/Serialization/URISerializer.swift

+1-6
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,10 @@ extension URISerializer {
6969

7070
/// Nested containers are not supported.
7171
case nestedContainersNotSupported
72-
7372
/// Deep object arrays are not supported.
7473
case deepObjectsArrayNotSupported
75-
7674
/// Deep object with primitive values are not supported.
7775
case deepObjectsWithPrimitiveValuesNotSupported
78-
7976
/// An invalid configuration was detected.
8077
case invalidConfiguration(String)
8178
}
@@ -190,8 +187,7 @@ extension URISerializer {
190187
case (.simple, _):
191188
keyAndValueSeparator = nil
192189
pairSeparator = ","
193-
case (.deepObject, _):
194-
throw SerializationError.deepObjectsArrayNotSupported
190+
case (.deepObject, _): throw SerializationError.deepObjectsArrayNotSupported
195191
}
196192
func serializeNext(_ element: URIEncodedNode.Primitive) throws {
197193
if let keyAndValueSeparator {
@@ -263,7 +259,6 @@ extension URISerializer {
263259
try serializeNext(element, forKey: serializeNestedKey(elementKey, forKey: key))
264260
data.append(pairSeparator)
265261
}
266-
267262
if let (elementKey, element) = sortedDictionary.last {
268263
try serializeNext(element, forKey: serializeNestedKey(elementKey, forKey: key))
269264
}

Tests/OpenAPIRuntimeTests/URICoder/Encoding/Test_URIEncoder.swift

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ final class Test_URIEncoder: Test_Runtime {
2323
let encodedString = try encoder.encode(Foo(bar: "hello world"), forKey: "root")
2424
XCTAssertEqual(encodedString, "bar=hello+world")
2525
}
26-
2726
func testNestedEncoding() throws {
2827
struct Foo: Encodable { var bar: String }
2928
let serializer = URISerializer(configuration: .deepObjectExplode)

Tests/OpenAPIRuntimeTests/URICoder/Parsing/Test_URIParser.swift

+5-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import XCTest
1717
final class Test_URIParser: Test_Runtime {
1818

1919
let testedVariants: [URICoderConfiguration] = [
20-
.formExplode, .formUnexplode, .simpleExplode, .simpleUnexplode, .formDataExplode, .formDataUnexplode, .deepObjectExplode
20+
.formExplode, .formUnexplode, .simpleExplode, .simpleUnexplode, .formDataExplode, .formDataUnexplode,
21+
.deepObjectExplode,
2122
]
2223

2324
func testParsing() throws {
@@ -101,7 +102,7 @@ final class Test_URIParser: Test_Runtime {
101102
formDataUnexplode: .custom(
102103
"keys=comma,%2C,dot,.,semi,%3B",
103104
value: ["keys": ["comma", ",", "dot", ".", "semi", ";"]]
104-
),
105+
),
105106
deepObjectExplode: "keys%5Bcomma%5D=%2C&keys%5Bdot%5D=.&keys%5Bsemi%5D=%3B"
106107
),
107108
value: ["semi": [";"], "dot": ["."], "comma": [","]]
@@ -120,14 +121,8 @@ final class Test_URIParser: Test_Runtime {
120121
line: testCase.line
121122
)
122123
} catch {
123-
guard let expectedError = input.expectedError,
124-
let parsingError = error as? ParsingError else {
125-
XCTAssert(
126-
false,
127-
"Unexpected error thrown: \(error)",
128-
file: testCase.file,
129-
line: testCase.line
130-
)
124+
guard let expectedError = input.expectedError, let parsingError = error as? ParsingError else {
125+
XCTAssert(false, "Unexpected error thrown: \(error)", file: testCase.file, line: testCase.line)
131126
return
132127
}
133128
XCTAssertEqual(
@@ -181,7 +176,6 @@ extension Test_URIParser {
181176
static func custom(_ string: String, value: URIParsedNode) -> Self {
182177
.init(string: string, valueOverride: value, expectedError: nil)
183178
}
184-
185179
static func custom(_ string: String, expectedError: ParsingError) -> Self {
186180
.init(string: string, valueOverride: nil, expectedError: expectedError)
187181
}

Tests/OpenAPIRuntimeTests/URICoder/Serialization/Test_URISerializer.swift

+8-29
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ final class Test_URISerializer: Test_Runtime {
3232
simpleUnexplode: "",
3333
formDataExplode: "empty=",
3434
formDataUnexplode: "empty=",
35-
deepObjectExplode: .custom(
36-
"empty=",
37-
expectedError: .deepObjectsWithPrimitiveValuesNotSupported
38-
)
35+
deepObjectExplode: .custom("empty=", expectedError: .deepObjectsWithPrimitiveValuesNotSupported)
3936
)
4037
),
4138
makeCase(
@@ -48,10 +45,7 @@ final class Test_URISerializer: Test_Runtime {
4845
simpleUnexplode: "fred",
4946
formDataExplode: "who=fred",
5047
formDataUnexplode: "who=fred",
51-
deepObjectExplode: .custom(
52-
"who=fred",
53-
expectedError: .deepObjectsWithPrimitiveValuesNotSupported
54-
)
48+
deepObjectExplode: .custom("who=fred", expectedError: .deepObjectsWithPrimitiveValuesNotSupported)
5549
)
5650
),
5751
makeCase(
@@ -64,10 +58,7 @@ final class Test_URISerializer: Test_Runtime {
6458
simpleUnexplode: "1234",
6559
formDataExplode: "x=1234",
6660
formDataUnexplode: "x=1234",
67-
deepObjectExplode: .custom(
68-
"x=1234",
69-
expectedError: .deepObjectsWithPrimitiveValuesNotSupported
70-
)
61+
deepObjectExplode: .custom("x=1234", expectedError: .deepObjectsWithPrimitiveValuesNotSupported)
7162
)
7263
),
7364
makeCase(
@@ -80,10 +71,7 @@ final class Test_URISerializer: Test_Runtime {
8071
simpleUnexplode: "12.34",
8172
formDataExplode: "x=12.34",
8273
formDataUnexplode: "x=12.34",
83-
deepObjectExplode: .custom(
84-
"x=12.34",
85-
expectedError: .deepObjectsWithPrimitiveValuesNotSupported
86-
)
74+
deepObjectExplode: .custom("x=12.34", expectedError: .deepObjectsWithPrimitiveValuesNotSupported)
8775
)
8876
),
8977
makeCase(
@@ -129,7 +117,7 @@ final class Test_URISerializer: Test_Runtime {
129117
formDataExplode: "list=red&list=green&list=blue",
130118
formDataUnexplode: "list=red,green,blue",
131119
deepObjectExplode: .custom(
132-
"list=red&list=green&list=blue",
120+
"list=red&list=green&list=blue",
133121
expectedError: .deepObjectsArrayNotSupported
134122
)
135123
)
@@ -165,13 +153,9 @@ final class Test_URISerializer: Test_Runtime {
165153
)
166154
} catch {
167155
guard let expectedError = input.expectedError,
168-
let serializationError = error as? URISerializer.SerializationError else {
169-
XCTAssert(
170-
false,
171-
"Unexpected error thrown: \(error)",
172-
file: testCase.file,
173-
line: testCase.line
174-
)
156+
let serializationError = error as? URISerializer.SerializationError
157+
else {
158+
XCTAssert(false, "Unexpected error thrown: \(error)", file: testCase.file, line: testCase.line)
175159
return
176160
}
177161
XCTAssertEqual(
@@ -209,26 +193,21 @@ extension Test_URISerializer {
209193
static let deepObjectExplode: Self = .init(name: "deepObjectExplode", config: .deepObjectExplode)
210194
}
211195
struct Variants {
212-
213196
struct Input: ExpressibleByStringLiteral {
214197
var string: String
215198
var expectedError: URISerializer.SerializationError?
216-
217199
init(string: String, expectedError: URISerializer.SerializationError? = nil) {
218200
self.string = string
219201
self.expectedError = expectedError
220202
}
221-
222203
static func custom(_ string: String, expectedError: URISerializer.SerializationError) -> Self {
223204
.init(string: string, expectedError: expectedError)
224205
}
225-
226206
init(stringLiteral value: String) {
227207
self.string = value
228208
self.expectedError = nil
229209
}
230210
}
231-
232211
var formExplode: Input
233212
var formUnexplode: Input
234213
var simpleExplode: Input

0 commit comments

Comments
 (0)