Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_enabled: false
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_2_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
Expand Down Expand Up @@ -44,6 +44,7 @@ jobs:
MATRIX_LINUX_SETUP_COMMAND: apt-get update -y && apt-get install -yq jq && git config --global --add safe.directory /swift-openapi-generator/.git && git config --global --add safe.directory /swift-openapi-generator
MATRIX_LINUX_COMMAND: SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${workspace} ./scripts/run-integration-test.sh
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_LINUX_5_10_ENABLED: false

integration-test:
name: Integration test
Expand All @@ -69,6 +70,7 @@ jobs:
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-openapi-generator
MATRIX_LINUX_COMMAND: ./scripts/test-examples.sh
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_LINUX_5_10_ENABLED: false

example-packages:
name: Example packages
Expand All @@ -93,6 +95,7 @@ jobs:
name: Release builds
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
with:
linux_5_10_enabled: false
windows_6_0_enabled: true
windows_6_1_enabled: true
windows_6_2_enabled: true
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: Unit tests
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
with:
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
linux_5_10_enabled: false
linux_6_0_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_1_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
linux_6_2_arguments_override: "-Xswiftc -warnings-as-errors --explicit-target-dependency-import-check error"
Expand Down Expand Up @@ -69,6 +69,7 @@ jobs:
MATRIX_LINUX_SETUP_COMMAND: apt-get update -y && apt-get install -yq jq && git config --global --add safe.directory /swift-openapi-generator/.git && git config --global --add safe.directory /swift-openapi-generator
MATRIX_LINUX_COMMAND: SWIFT_OPENAPI_GENERATOR_REPO_URL=file://${workspace} ./scripts/run-integration-test.sh
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_LINUX_5_10_ENABLED: false

integration-test:
name: Integration test
Expand All @@ -94,6 +95,7 @@ jobs:
MATRIX_LINUX_SETUP_COMMAND: git config --global --add safe.directory /swift-openapi-generator
MATRIX_LINUX_COMMAND: ./scripts/test-examples.sh
MATRIX_LINUX_NIGHTLY_MAIN_ENABLED: false
MATRIX_LINUX_5_10_ENABLED: false

example-packages:
name: Example packages
Expand All @@ -103,7 +105,6 @@ jobs:
name: "Example packages"
matrix_string: '${{ needs.construct-example-packages-matrix.outputs.example-packages-matrix }}'


macos-tests:
name: macOS tests
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
Expand All @@ -119,6 +120,7 @@ jobs:
name: Release builds
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
with:
linux_5_10_enabled: false
windows_6_0_enabled: true
windows_6_1_enabled: true
windows_6_2_enabled: true
Expand Down
2 changes: 1 addition & 1 deletion Examples/auth-client-middleware-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/auth-server-middleware-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand All @@ -16,7 +16,7 @@ import PackageDescription

let package = Package(
name: "bidirectional-event-streams-server-example",
platforms: [.macOS(.v14)],
platforms: [.macOS(.v15)],
dependencies: [
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Handler: APIProtocol {
func getGreetingsStream(_ input: Operations.GetGreetingsStream.Input) async throws
-> Operations.GetGreetingsStream.Output
{
let eventStream = await self.storage.makeStream(input: input)
let eventStream = self.storage.makeStream(input: input)
/// To keep it simple, using JSON Lines, as it most straightforward and easy way to have streams.
/// For SSE and JSON Sequences cases please check `event-streams-server-example`.
let responseBody = Operations.GetGreetingsStream.Output.Ok.Body.applicationJsonl(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,46 @@
//===----------------------------------------------------------------------===//

import Foundation
import Synchronization

actor StreamStorage: Sendable {
final class StreamStorage: Sendable {
private typealias StreamType = AsyncStream<Components.Schemas.Greeting>
private var streams: [String: Task<Void, any Error>] = [:]
init() {}
private let streams: Mutex<[String: Task<Void, any Error>]>
init() { self.streams = .init([:]) }
private func finishedStream(id: String) {
guard self.streams[id] != nil else { return }
self.streams.removeValue(forKey: id)
self.streams.withLock { streams in
guard streams[id] != nil else { return }
streams.removeValue(forKey: id)
}
}
private func cancelStream(id: String) {
guard let task = self.streams[id] else { return }
self.streams.removeValue(forKey: id)
let task: Task<Void, any Error>? = self.streams.withLock { streams in
guard let task = streams[id] else { return nil }
streams.removeValue(forKey: id)
return task
}
guard let task else { return }
task.cancel()
print("Canceled stream \(id)")
}

private func handleTermination(
_ termination: AsyncStream<Components.Schemas.Greeting>.Continuation.Termination,
id: String
) {
switch termination {
case .cancelled: self.cancelStream(id: id)
case .finished: self.finishedStream(id: id)
@unknown default: self.finishedStream(id: id)
}
}

func makeStream(input: Operations.GetGreetingsStream.Input) -> AsyncStream<Components.Schemas.Greeting> {
let name = input.query.name ?? "Stranger"
let id = UUID().uuidString
print("Creating stream \(id) for name: \(name)")
let (stream, continuation) = StreamType.makeStream()
continuation.onTermination = { termination in
Task { [weak self] in
switch termination {
case .cancelled: await self?.cancelStream(id: id)
case .finished: await self?.finishedStream(id: id)
@unknown default: await self?.finishedStream(id: id)
}
}
}
continuation.onTermination = { termination in self.handleTermination(termination, id: id) }
let inputStream =
switch input.body {
case .applicationJsonl(let body): body.asDecodedJSONLines(of: Components.Schemas.Greeting.self)
Expand All @@ -56,7 +67,7 @@ actor StreamStorage: Sendable {
}
continuation.finish()
}
self.streams[id] = task
self.streams.withLock { streams in streams[id] = task }
return stream
}
}
2 changes: 1 addition & 1 deletion Examples/command-line-client-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import Foundation
import ArgumentParser

@main struct CommandLineClient: AsyncParsableCommand {
static var configuration: CommandConfiguration = .init(
static let configuration: CommandConfiguration = .init(
commandName: "CommandLineClient",
subcommands: [GreetCommand.self]
)
}

struct GreetCommand: AsyncParsableCommand {

static var configuration: CommandConfiguration = .init(commandName: "greet")
static let configuration: CommandConfiguration = .init(commandName: "greet")

@Option var name: String

Expand Down
2 changes: 1 addition & 1 deletion Examples/curated-client-library-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/event-streams-client-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/event-streams-server-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/hello-world-vapor-server-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/logging-middleware-oslog-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ extension LoggingMiddleware: ServerMiddleware {
body: OpenAPIRuntime.HTTPBody?,
metadata: OpenAPIRuntime.ServerRequestMetadata,
operationID: String,
next: @Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata)
next:
@Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata)
async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?)
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?) {
let (requestBodyToLog, requestBodyForNext) = try await bodyLoggingPolicy.process(body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ extension LoggingMiddleware: ServerMiddleware {
body: OpenAPIRuntime.HTTPBody?,
metadata: OpenAPIRuntime.ServerRequestMetadata,
operationID: String,
next: @Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata)
next:
@Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata)
async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?)
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?) {
let (requestBodyToLog, requestBodyForNext) = try await bodyLoggingPolicy.process(body)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/metrics-middleware-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/postgres-database-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/retrying-middleware-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/shared-types-client-server-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/streaming-chatgpt-proxy/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
import PackageDescription

let package = Package(
Expand Down
5 changes: 5 additions & 0 deletions Examples/streaming-chatgpt-proxy/Sources/ClientCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// https://github.com/swiftlang/swift/issues/77866
#if canImport(Glibc)
@preconcurrency import Glibc
#endif
import OpenAPIRuntime
import OpenAPIURLSession
import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Examples/swagger-ui-endpoint-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/tracing-middleware-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion Examples/type-overrides-example/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
2 changes: 1 addition & 1 deletion IntegrationTest/Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.10
// swift-tools-version:6.0
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftOpenAPIGenerator open source project
Expand Down
6 changes: 3 additions & 3 deletions IntegrationTest/Sources/MockTransportServer/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ actor SimpleAPIImpl: APIProtocol {
}

class MockServerTransport: ServerTransport {
typealias Handler = @Sendable (
HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata
) async throws -> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?)
typealias Handler =
@Sendable (HTTPTypes.HTTPRequest, OpenAPIRuntime.HTTPBody?, OpenAPIRuntime.ServerRequestMetadata) async throws
-> (HTTPTypes.HTTPResponse, OpenAPIRuntime.HTTPBody?)

func register(_ handler: @escaping Handler, method: HTTPTypes.HTTPRequest.Method, path: String) throws {
// noop.
Expand Down
Loading