Skip to content

Commit 0b31014

Browse files
committed
Updating everything to work with first Vapor beta
1 parent ccf40d9 commit 0b31014

File tree

14 files changed

+96
-90
lines changed

14 files changed

+96
-90
lines changed

Package.resolved

Lines changed: 44 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import PackageDescription
44
let package = Package(
55
name: "jsonapi-openapi-test-server",
66
platforms: [
7-
.macOS(.v10_12)
7+
.macOS(.v10_14)
88
],
99
products: [
1010
.library(name: "jsonapi-openapi-test-server", targets: ["App"]),

Sources/APITest/main.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88
import APITesting
99
import Vapor
1010

11-
func configure(_ services: inout Services) {
11+
func configure(_ app: Application) {
1212
// Commands
13-
services.register(APITestCommand.self) { _ in
13+
app.register(APITestCommand.self) { _ in
1414
return try .init()
1515
}
16-
services.register(CommandConfiguration.self) { container in
16+
app.register(CommandConfiguration.self) { container in
1717
var commandConfig = CommandConfiguration()
18-
try commandConfig.use(container.make(APITestCommand.self), as: "test", isDefault: true)
18+
commandConfig.use(container.make(APITestCommand.self), as: "test", isDefault: true)
1919
return commandConfig
2020
}
2121
}
2222

23-
let app = Application(environment: try .detect(),
24-
configure: configure)
23+
let app = Application(environment: try .detect())
24+
25+
configure(app)
2526

2627
try app.boot()
2728
try app.run()

Sources/APITesting/APITestCommand.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,19 @@ public func openAPIDoc(on loop: EventLoop,
129129
headers.add(name: .authorization, value: HTTPClient.Authorization.basic(username: username, password: password).headerValue)
130130
}
131131

132-
return client.get(url, headers: headers).flatMapThrowing {
132+
let request: HTTPClient.Request
133+
do {
134+
request = try HTTPClient.Request(url: url.string,
135+
method: .GET,
136+
headers: headers)
137+
} catch {
138+
return loop.makeFailedFuture(Abort(.badRequest))
139+
}
140+
141+
return client.execute(request: request).flatMapThrowing { response in
133142
try client.syncShutdown()
134-
return try $0.content.decode(OpenAPI.Document.self)
143+
return try ClientResponse(status: response.status, headers: response.headers, body: response.body)
144+
.content.decode(OpenAPI.Document.self)
135145
}
136146
}
137147

Sources/App/Models/API/API_APITestDescriptor.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,9 @@ extension API {
123123
Includes(values: resource.1.map { Include1($0) })
124124
}
125125

126-
return resourceFuture.and(includesFuture)
127-
.map { (resource, includes) in
128-
SingleAPITestDescriptorResponse.SuccessDocument(apiDescription: .none,
129-
body: .init(resourceObject: resource.0),
130-
includes: includes,
131-
meta: .none,
132-
links: .none)
126+
return responseFuture.and(includesFuture)
127+
.map { (response, includes) in
128+
response.including(includes)
133129
}
134130
}
135131
}

Sources/App/Models/DB/APITestDescriptor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public final class APITestDescriptor: Model {
2121
@Field(key: "status")
2222
var status: Status
2323

24-
@Children(from: \.$apiTestDescriptor)
24+
@Children(for: \.$apiTestDescriptor)
2525
var messages: [APITestMessage]
2626

2727
/// Create a new test descriptor. It is strongly recommended that

Sources/App/app.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import Vapor
22

33
/// Creates an instance of `Application`. This is called from `main.swift` in the run target.
44
public func app(_ env: Environment) throws -> Application {
5-
let app = Application(environment: env, configure: configure)
6-
try boot(app)
5+
var environment = env
6+
try LoggingSystem.bootstrap(from: &environment)
7+
let app = Application(environment: environment)
8+
try configure(app)
79
return app
810
}

Sources/App/boot.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

Sources/App/configure.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,24 @@ import Vapor
44
import APITesting
55

66
/// Called before your application initializes.
7-
public func configure(_ services: inout Services) {
7+
public func configure(_ app: Application) throws {
88
// Register providers first
9-
services.provider(FluentProvider())
10-
11-
// Register routes
12-
services.register(Routes.self, routes)
9+
app.provider(FluentProvider())
1310

1411
// Register middleware
15-
services.register(MiddlewareConfiguration.self) { container in
16-
var middlewares = MiddlewareConfiguration()
17-
middlewares.use(ErrorMiddleware.default(environment: container.environment)) // Catches errors and converts to HTTP response
18-
return middlewares
12+
app.register(extension: MiddlewareConfiguration.self) { middlewares, app in
13+
middlewares.use(ErrorMiddleware.default(environment: app.environment))
1914
}
2015

2116
// Configure databases
22-
services.extend(Databases.self, databases)
23-
services.register(Database.self) { container in
24-
return try container.make(Databases.self).database(.psql)!
17+
app.register(extension: Databases.self, databases)
18+
app.register(Database.self) { app in
19+
return app.make(Databases.self).database(.psql)!
2520
}
2621

2722
// Configure migrations
28-
services.register(Migrations.self, migrations)
23+
app.register(Migrations.self, migrations)
24+
25+
// Register routes
26+
try routes(app)
2927
}

Sources/App/databases.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import Vapor
33
import FluentPostgresDriver
44

5-
public func databases(_ databases: inout Databases, _ container: Container) throws {
6-
try databases.postgres(config: Environment.dbConfig())
5+
public func databases(_ databases: inout Databases, _ app: Application) throws {
6+
try databases.postgres(configuration: Environment.dbConfig(),
7+
poolConfiguration: app.make(),
8+
on: app.make())
79
}

0 commit comments

Comments
 (0)