Skip to content

Commit 9c01b32

Browse files
Update Examples and IntegrationTest to use idiomatic naming (#706)
### Motivation Since idiomatic naming is our new recommended setting, use it in Examples and IntegrationTest. ### Modifications Added idiomatic naming to all examples and made any necessary changes. Plus a few modernizations, like moving to Hummingbird 2.0 and to Prometheus 2.0. ### Result More up-to-date examples, easier to copy out by adopters, they now get our recommended starting settings. ### Test Plan Ran and tested locally. --------- Co-authored-by: Si Beaumont <[email protected]>
1 parent dcfb1ed commit 9c01b32

File tree

82 files changed

+244
-204
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+244
-204
lines changed

Diff for: Examples/HelloWorldiOSClientAppExample/HelloWorldiOSClientApp.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,15 @@
609609
repositoryURL = "https://github.com/apple/swift-openapi-generator.git";
610610
requirement = {
611611
kind = upToNextMajorVersion;
612-
minimumVersion = 1.0.0;
612+
minimumVersion = 1.6.0;
613613
};
614614
};
615615
3A133D0E2B1F2A600008DD5E /* XCRemoteSwiftPackageReference "swift-openapi-runtime" */ = {
616616
isa = XCRemoteSwiftPackageReference;
617617
repositoryURL = "https://github.com/apple/swift-openapi-runtime.git";
618618
requirement = {
619619
kind = upToNextMajorVersion;
620-
minimumVersion = 1.0.0;
620+
minimumVersion = 1.7.0;
621621
};
622622
};
623623
3A133D112B1F2A730008DD5E /* XCRemoteSwiftPackageReference "swift-openapi-urlsession" */ = {

Diff for: Examples/HelloWorldiOSClientAppExample/HelloWorldiOSClientApp/ContentView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct ContentView: View {
6060

6161
// A mock client used in previews and tests to avoid making live network calls.
6262
struct MockClient: APIProtocol {
63-
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
63+
func getGreeting(_ input: Operations.GetGreeting.Input) async throws -> Operations.GetGreeting.Output {
6464
let name = input.query.name ?? "Stranger"
6565
return .ok(.init(body: .json(.init(message: "(Mock) Hello, \(name)!"))))
6666
}

Diff for: Examples/HelloWorldiOSClientAppExample/HelloWorldiOSClientApp/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/auth-client-middleware-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "auth-client-middleware-example",
1919
platforms: [.macOS(.v11), .iOS(.v14), .tvOS(.v14), .watchOS(.v7), .visionOS(.v1)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
2424
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.2"),
2525
],

Diff for: Examples/auth-client-middleware-example/Sources/HelloWorldURLSessionClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/auth-server-middleware-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "auth-server-middleware-example",
1919
platforms: [.macOS(.v10_15)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", from: "1.0.0"),
2424
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],

Diff for: Examples/auth-server-middleware-example/Sources/HelloWorldVaporServer/HelloWorldVaporServer.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import Vapor
1717
import AuthenticationServerMiddleware
1818

1919
struct Handler: APIProtocol {
20-
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
20+
func getGreeting(_ input: Operations.GetGreeting.Input) async throws -> Operations.GetGreeting.Output {
2121
// Extract the authenticated user, if present.
2222
// If unauthenticated, return the 401 HTTP status code.
2323
// Note that the 401 is defined in the OpenAPI document, allowing the client
@@ -32,7 +32,7 @@ struct Handler: APIProtocol {
3232

3333
@main struct HelloWorldVaporServer {
3434
static func main() async throws {
35-
let app = Vapor.Application()
35+
let app = try await Vapor.Application.make()
3636
let transport = VaporTransport(routesBuilder: app)
3737
let handler = Handler()
3838
try handler.registerHandlers(

Diff for: Examples/auth-server-middleware-example/Sources/HelloWorldVaporServer/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- server
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/bidirectional-event-streams-client-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "bidirectional-event-streams-client-example",
1919
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.2.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"),
2424
],
2525
targets: [

Diff for: Examples/bidirectional-event-streams-client-example/Sources/BidirectionalEventStreamsClient/BidirectionalEventStreamsClient.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ import Foundation
2727
let (stream, continuation) = AsyncStream<Components.Schemas.Greeting>.makeStream()
2828
/// To keep it simple, using JSON Lines, as it most straightforward and easy way to have streams.
2929
/// For SSE and JSON Sequences cases please check `event-streams-client-example`.
30-
let requestBody: Operations.getGreetingsStream.Input.Body = .application_jsonl(
30+
let requestBody: Operations.GetGreetingsStream.Input.Body = .applicationJsonl(
3131
.init(stream.asEncodedJSONLines(), length: .unknown, iterationBehavior: .single)
3232
)
3333
let response = try await client.getGreetingsStream(query: .init(name: "Example"), body: requestBody)
34-
let greetingStream = try response.ok.body.application_jsonl.asDecodedJSONLines(
34+
let greetingStream = try response.ok.body.applicationJsonl.asDecodedJSONLines(
3535
of: Components.Schemas.Greeting.self
3636
)
3737
try await withThrowingTaskGroup(of: Void.self) { group in

Diff for: Examples/bidirectional-event-streams-client-example/Sources/BidirectionalEventStreamsClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/bidirectional-event-streams-server-example/Package.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import PackageDescription
1616

1717
let package = Package(
1818
name: "bidirectional-event-streams-server-example",
19-
platforms: [.macOS(.v10_15)],
19+
platforms: [.macOS(.v14)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.2.0"),
23-
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.0.0-rc.1"),
24-
.package(url: "https://github.com/swift-server/swift-openapi-hummingbird.git", from: "2.0.0-beta.4"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
23+
.package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "2.5.0"),
24+
.package(url: "https://github.com/swift-server/swift-openapi-hummingbird.git", from: "2.0.1"),
2525
],
2626
targets: [
2727
.executableTarget(

Diff for: Examples/bidirectional-event-streams-server-example/Sources/BidirectionalEventStreamsServer/BidirectionalEventStreamsServer.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ import Foundation
1818

1919
struct Handler: APIProtocol {
2020
private let storage: StreamStorage = .init()
21-
func getGreetingsStream(_ input: Operations.getGreetingsStream.Input) async throws
22-
-> Operations.getGreetingsStream.Output
21+
func getGreetingsStream(_ input: Operations.GetGreetingsStream.Input) async throws
22+
-> Operations.GetGreetingsStream.Output
2323
{
2424
let eventStream = await self.storage.makeStream(input: input)
2525
/// To keep it simple, using JSON Lines, as it most straightforward and easy way to have streams.
2626
/// For SSE and JSON Sequences cases please check `event-streams-server-example`.
27-
let responseBody = Operations.getGreetingsStream.Output.Ok.Body.application_jsonl(
27+
let responseBody = Operations.GetGreetingsStream.Output.Ok.Body.applicationJsonl(
2828
.init(eventStream.asEncodedJSONLines(), length: .unknown, iterationBehavior: .single)
2929
)
3030
return .ok(.init(body: responseBody))

Diff for: Examples/bidirectional-event-streams-server-example/Sources/BidirectionalEventStreamsServer/GreetingStream.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ actor StreamStorage: Sendable {
2828
task.cancel()
2929
print("Canceled stream \(id)")
3030
}
31-
func makeStream(input: Operations.getGreetingsStream.Input) -> AsyncStream<Components.Schemas.Greeting> {
31+
func makeStream(input: Operations.GetGreetingsStream.Input) -> AsyncStream<Components.Schemas.Greeting> {
3232
let name = input.query.name ?? "Stranger"
3333
let id = UUID().uuidString
3434
print("Creating stream \(id) for name: \(name)")
@@ -44,7 +44,7 @@ actor StreamStorage: Sendable {
4444
}
4545
let inputStream =
4646
switch input.body {
47-
case .application_jsonl(let body): body.asDecodedJSONLines(of: Components.Schemas.Greeting.self)
47+
case .applicationJsonl(let body): body.asDecodedJSONLines(of: Components.Schemas.Greeting.self)
4848
}
4949
let task = Task<Void, any Error> {
5050
for try await message in inputStream {

Diff for: Examples/bidirectional-event-streams-server-example/Sources/BidirectionalEventStreamsServer/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- server
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/command-line-client-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "command-line-client-example",
1919
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
2424
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.0"),
2525
],

Diff for: Examples/command-line-client-example/Sources/CommandLineClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/curated-client-library-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ let package = Package(
1919
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
2020
products: [.library(name: "CuratedLibraryClient", targets: ["CuratedLibraryClient"])],
2121
dependencies: [
22-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
23-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
23+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2424
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
2525
],
2626
targets: [

Diff for: Examples/curated-client-library-example/Sources/CuratedLibraryClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/curated-client-library-example/Tests/CuratedLibraryClientTests/CuratedLibraryClientTests.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct TestClient: APIProtocol {
4949
var name: String?
5050
}
5151

52-
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
52+
func getGreeting(_ input: Operations.GetGreeting.Input) async throws -> Operations.GetGreeting.Output {
5353
guard !shouldFail else { throw TestError(name: input.query.name) }
5454
let name = input.query.name ?? "Stranger"
5555
return .ok(.init(body: .json(.init(message: "(Test) Hello, \(name)!"))))

Diff for: Examples/event-streams-client-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "event-streams-client-example",
1919
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.2.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/apple/swift-openapi-urlsession", from: "1.0.0"),
2424
],
2525
targets: [

Diff for: Examples/event-streams-client-example/Sources/EventStreamsClient/EventStreamsClient.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import Foundation
2222
print("Fetching greetings using JSON Lines")
2323
let response = try await client.getGreetingsStream(
2424
query: .init(name: "Example", count: 3),
25-
headers: .init(accept: [.init(contentType: .application_jsonl)])
25+
headers: .init(accept: [.init(contentType: .applicationJsonl)])
2626
)
27-
let greetingStream = try response.ok.body.application_jsonl.asDecodedJSONLines(
27+
let greetingStream = try response.ok.body.applicationJsonl.asDecodedJSONLines(
2828
of: Components.Schemas.Greeting.self
2929
)
3030
for try await greeting in greetingStream { print("Got greeting: \(greeting.message)") }
@@ -33,9 +33,9 @@ import Foundation
3333
print("Fetching greetings using JSON Sequence")
3434
let response = try await client.getGreetingsStream(
3535
query: .init(name: "Example", count: 3),
36-
headers: .init(accept: [.init(contentType: .application_json_hyphen_seq)])
36+
headers: .init(accept: [.init(contentType: .applicationJsonSeq)])
3737
)
38-
let greetingStream = try response.ok.body.application_json_hyphen_seq.asDecodedJSONSequence(
38+
let greetingStream = try response.ok.body.applicationJsonSeq.asDecodedJSONSequence(
3939
of: Components.Schemas.Greeting.self
4040
)
4141
for try await greeting in greetingStream { print("Got greeting: \(greeting.message)") }
@@ -44,9 +44,9 @@ import Foundation
4444
print("Fetching greetings using Server-sent Events")
4545
let response = try await client.getGreetingsStream(
4646
query: .init(name: "Example", count: 3),
47-
headers: .init(accept: [.init(contentType: .text_event_hyphen_stream)])
47+
headers: .init(accept: [.init(contentType: .textEventStream)])
4848
)
49-
let greetingStream = try response.ok.body.text_event_hyphen_stream.asDecodedServerSentEventsWithJSONData(
49+
let greetingStream = try response.ok.body.textEventStream.asDecodedServerSentEventsWithJSONData(
5050
of: Components.Schemas.Greeting.self
5151
)
5252
for try await greeting in greetingStream { print("Got greeting: \(greeting.data?.message ?? "<nil>")") }

Diff for: Examples/event-streams-client-example/Sources/EventStreamsClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/event-streams-server-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "event-streams-server-example",
1919
platforms: [.macOS(.v10_15)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.2.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-vapor", from: "1.0.0"),
2424
.package(url: "https://github.com/vapor/vapor", from: "4.89.0"),
2525
],

Diff for: Examples/event-streams-server-example/Sources/EventStreamsServer/EventStreamsServer.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ import Vapor
1717

1818
struct Handler: APIProtocol {
1919
private let storage: StreamStorage = .init()
20-
func getGreetingsStream(_ input: Operations.getGreetingsStream.Input) async throws
21-
-> Operations.getGreetingsStream.Output
20+
func getGreetingsStream(_ input: Operations.GetGreetingsStream.Input) async throws
21+
-> Operations.GetGreetingsStream.Output
2222
{
2323
let name = input.query.name ?? "Stranger"
2424
let count = input.query.count ?? 10
2525
let eventStream = storage.makeStream(name: name, count: count)
26-
let responseBody: Operations.getGreetingsStream.Output.Ok.Body
26+
let responseBody: Operations.GetGreetingsStream.Output.Ok.Body
2727
// Default to `application/jsonl`, if no other content type requested through the `Accept` header.
28-
let chosenContentType = input.headers.accept.sortedByQuality().first ?? .init(contentType: .application_jsonl)
28+
let chosenContentType = input.headers.accept.sortedByQuality().first ?? .init(contentType: .applicationJsonl)
2929
switch chosenContentType.contentType {
30-
case .application_jsonl, .other:
31-
responseBody = .application_jsonl(
30+
case .applicationJsonl, .other:
31+
responseBody = .applicationJsonl(
3232
.init(eventStream.asEncodedJSONLines(), length: .unknown, iterationBehavior: .single)
3333
)
34-
case .application_json_hyphen_seq:
35-
responseBody = .application_json_hyphen_seq(
34+
case .applicationJsonSeq:
35+
responseBody = .applicationJsonSeq(
3636
.init(eventStream.asEncodedJSONSequence(), length: .unknown, iterationBehavior: .single)
3737
)
38-
case .text_event_hyphen_stream:
39-
responseBody = .text_event_hyphen_stream(
38+
case .textEventStream:
39+
responseBody = .textEventStream(
4040
.init(
4141
eventStream.map { greeting in
4242
ServerSentEventWithJSONData(
@@ -58,7 +58,7 @@ struct Handler: APIProtocol {
5858

5959
@main struct EventStreamsServer {
6060
static func main() async throws {
61-
let app = Vapor.Application()
61+
let app = try await Vapor.Application.make()
6262
let transport = VaporTransport(routesBuilder: app)
6363
let handler = Handler()
6464
try handler.registerHandlers(on: transport, serverURL: URL(string: "/api")!)

Diff for: Examples/event-streams-server-example/Sources/EventStreamsServer/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- server
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/hello-world-async-http-client-example/Package.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ let package = Package(
1818
name: "hello-world-async-http-client-example",
1919
platforms: [.macOS(.v10_15), .iOS(.v13), .tvOS(.v13), .watchOS(.v6), .visionOS(.v1)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
2323
.package(url: "https://github.com/swift-server/swift-openapi-async-http-client", from: "1.0.0"),
2424
],
2525
targets: [

Diff for: Examples/hello-world-async-http-client-example/Sources/HelloWorldAsyncHTTPClient/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- client
44
accessModifier: internal
5+
namingStrategy: idiomatic

Diff for: Examples/hello-world-hummingbird-server-example/Package.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import PackageDescription
1616

1717
let package = Package(
1818
name: "hello-world-hummingbird-server-example",
19-
platforms: [.macOS(.v10_15)],
19+
platforms: [.macOS(.v14)],
2020
dependencies: [
21-
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.0.0"),
22-
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.0.0"),
23-
.package(url: "https://github.com/swift-server/swift-openapi-hummingbird", from: "1.0.0"),
24-
.package(url: "https://github.com/hummingbird-project/hummingbird", from: "1.10.1"),
21+
.package(url: "https://github.com/apple/swift-openapi-generator", from: "1.6.0"),
22+
.package(url: "https://github.com/apple/swift-openapi-runtime", from: "1.7.0"),
23+
.package(url: "https://github.com/swift-server/swift-openapi-hummingbird", from: "2.0.1"),
24+
.package(url: "https://github.com/hummingbird-project/hummingbird", from: "2.5.0"),
2525
],
2626
targets: [
2727
.executableTarget(

Diff for: Examples/hello-world-hummingbird-server-example/Sources/HelloWorldHummingbirdServer/HelloWorldHummingbirdServer.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ import Hummingbird
1717
import Foundation
1818

1919
struct Handler: APIProtocol {
20-
func getGreeting(_ input: Operations.getGreeting.Input) async throws -> Operations.getGreeting.Output {
20+
func getGreeting(_ input: Operations.GetGreeting.Input) async throws -> Operations.GetGreeting.Output {
2121
let name = input.query.name ?? "Stranger"
2222
return .ok(.init(body: .json(.init(message: "Hello, \(name)!"))))
2323
}
2424
}
2525

2626
@main struct HelloWorldHummingbirdServer {
2727
static func main() async throws {
28-
let app = Hummingbird.HBApplication()
29-
let transport = HBOpenAPITransport(app)
28+
let router = Router()
3029
let handler = Handler()
31-
try handler.registerHandlers(on: transport, serverURL: URL(string: "/api")!)
32-
try await app.asyncRun()
30+
try handler.registerHandlers(on: router, serverURL: URL(string: "/api")!)
31+
let app = Application(router: router, configuration: .init())
32+
try await app.run()
3333
}
3434
}

Diff for: Examples/hello-world-hummingbird-server-example/Sources/HelloWorldHummingbirdServer/openapi-generator-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ generate:
22
- types
33
- server
44
accessModifier: internal
5+
namingStrategy: idiomatic

0 commit comments

Comments
 (0)