Skip to content

Commit 78e19da

Browse files
committed
Format
1 parent 86d0966 commit 78e19da

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

Sources/OpenAPIRuntime/Deprecated/Deprecated.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,33 +65,31 @@ extension AsyncSequence where Element == ArraySlice<UInt8>, Self: Sendable {
6565
///
6666
/// Use this method if the event's `data` field is not JSON, or if you don't want to parse it using `asDecodedServerSentEventsWithJSONData`.
6767
/// - Returns: A sequence that provides the events.
68-
@available(*, deprecated, renamed: "asDecodedServerSentEvents(while:)")
69-
@_disfavoredOverload public func asDecodedServerSentEvents() -> ServerSentEventsDeserializationSequence<
68+
@available(*, deprecated, renamed: "asDecodedServerSentEvents(while:)") @_disfavoredOverload
69+
public func asDecodedServerSentEvents() -> ServerSentEventsDeserializationSequence<
7070
ServerSentEventsLineDeserializationSequence<Self>
7171
> { asDecodedServerSentEvents(while: { _ in true }) }
72-
7372
/// Returns another sequence that decodes each event's data as the provided type using the provided decoder.
7473
///
7574
/// Use this method if the event's `data` field is JSON.
7675
/// - Parameters:
7776
/// - dataType: The type to decode the JSON data into.
7877
/// - decoder: The JSON decoder to use.
7978
/// - Returns: A sequence that provides the events with the decoded JSON data.
80-
@available(*, deprecated, renamed: "asDecodedServerSentEventsWithJSONData(of:decoder:while:)")
81-
@_disfavoredOverload public func asDecodedServerSentEventsWithJSONData<JSONDataType: Decodable>(
79+
@available(*, deprecated, renamed: "asDecodedServerSentEventsWithJSONData(of:decoder:while:)") @_disfavoredOverload
80+
public func asDecodedServerSentEventsWithJSONData<JSONDataType: Decodable>(
8281
of dataType: JSONDataType.Type = JSONDataType.self,
8382
decoder: JSONDecoder = .init()
8483
) -> AsyncThrowingMapSequence<
8584
ServerSentEventsDeserializationSequence<ServerSentEventsLineDeserializationSequence<Self>>,
8685
ServerSentEventWithJSONData<JSONDataType>
87-
> {
88-
asDecodedServerSentEventsWithJSONData(of: dataType, decoder: decoder, while: { _ in true })
89-
}
86+
> { asDecodedServerSentEventsWithJSONData(of: dataType, decoder: decoder, while: { _ in true }) }
9087
}
9188

9289
extension ServerSentEventsDeserializationSequence {
9390
/// Creates a new sequence.
9491
/// - Parameter upstream: The upstream sequence of arbitrary byte chunks.
95-
@available(*, deprecated, renamed: "init(upstream:while:)")
96-
@_disfavoredOverload public init(upstream: Upstream) { self.init(upstream: upstream, while: { _ in true }) }
92+
@available(*, deprecated, renamed: "init(upstream:while:)") @_disfavoredOverload public init(upstream: Upstream) {
93+
self.init(upstream: upstream, while: { _ in true })
94+
}
9795
}

Sources/OpenAPIRuntime/EventStreams/ServerSentEventsDecoding.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,11 @@ extension AsyncSequence where Element == ArraySlice<UInt8>, Self: Sendable {
100100
/// Use this method if the event's `data` field is not JSON, or if you don't want to parse it using `asDecodedServerSentEventsWithJSONData`.
101101
/// - Parameter: A closure that determines whether the given byte chunk should be forwarded to the consumer.
102102
/// - Returns: A sequence that provides the events.
103-
public func asDecodedServerSentEvents(while predicate: @escaping @Sendable (ArraySlice<UInt8>) -> Bool = { _ in true }) -> ServerSentEventsDeserializationSequence<
104-
ServerSentEventsLineDeserializationSequence<Self>
105-
> { .init(upstream: ServerSentEventsLineDeserializationSequence(upstream: self), while: predicate) }
106-
103+
public func asDecodedServerSentEvents(
104+
while predicate: @escaping @Sendable (ArraySlice<UInt8>) -> Bool = { _ in true }
105+
) -> ServerSentEventsDeserializationSequence<ServerSentEventsLineDeserializationSequence<Self>> {
106+
.init(upstream: ServerSentEventsLineDeserializationSequence(upstream: self), while: predicate)
107+
}
107108
/// Returns another sequence that decodes each event's data as the provided type using the provided decoder.
108109
///
109110
/// Use this method if the event's `data` field is JSON.
@@ -188,7 +189,6 @@ extension ServerSentEventsDeserializationSequence.Iterator {
188189
// Dispatch the accumulated event.
189190
// If the last character of data is a newline, strip it.
190191
if event.data?.hasSuffix("\n") ?? false { event.data?.removeLast() }
191-
192192
if let data = event.data, !predicate(ArraySlice(data.utf8)) {
193193
state = .finished
194194
return .returnNil

Tests/OpenAPIRuntimeTests/EventStreams/Test_ServerSentEventsDecoding.swift

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ import XCTest
1616
import Foundation
1717

1818
final class Test_ServerSentEventsDecoding: Test_Runtime {
19-
func _test(input: String, output: [ServerSentEvent], file: StaticString = #filePath, line: UInt = #line, while predicate: @escaping @Sendable (ArraySlice<UInt8>) -> Bool = { _ in true })
20-
async throws
21-
{
19+
func _test(
20+
input: String,
21+
output: [ServerSentEvent],
22+
file: StaticString = #filePath,
23+
line: UInt = #line,
24+
while predicate: @escaping @Sendable (ArraySlice<UInt8>) -> Bool = { _ in true }
25+
) async throws {
2226
let sequence = asOneBytePerElementSequence(ArraySlice(input.utf8)).asDecodedServerSentEvents(while: predicate)
2327
let events = try await [ServerSentEvent](collecting: sequence)
2428
XCTAssertEqual(events.count, output.count, file: file, line: line)
@@ -97,12 +101,8 @@ final class Test_ServerSentEventsDecoding: Test_Runtime {
97101
98102
99103
"""#,
100-
output: [
101-
.init(data: "hello\nworld")
102-
],
103-
while: { incomingData in
104-
incomingData != ArraySlice<UInt8>(Data("[DONE]".utf8))
105-
}
104+
output: [.init(data: "hello\nworld")],
105+
while: { incomingData in incomingData != ArraySlice<UInt8>(Data("[DONE]".utf8)) }
106106
)
107107
}
108108
func _testJSONData<JSONType: Decodable & Hashable & Sendable>(
@@ -162,16 +162,14 @@ final class Test_ServerSentEventsDecoding: Test_Runtime {
162162
event: event3
163163
id: 1
164164
data: {"index":3}
165-
166-
165+
166+
167167
"""#,
168168
output: [
169169
.init(event: "event1", data: TestEvent(index: 1), id: "1"),
170170
.init(event: "event2", data: TestEvent(index: 2), id: "2"),
171171
],
172-
while: { incomingData in
173-
incomingData != ArraySlice<UInt8>(Data("[DONE]".utf8))
174-
}
172+
while: { incomingData in incomingData != ArraySlice<UInt8>(Data("[DONE]".utf8)) }
175173
)
176174
}
177175
}

0 commit comments

Comments
 (0)