Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
20 changes: 1 addition & 19 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ let package = Package(
.package(url: "https://github.com/SwiftPackageIndex/SemanticVersion.git", from: "0.3.0"),
.package(url: "https://github.com/SwiftPackageIndex/ShellOut.git", from: "3.1.4"),
.package(url: "https://github.com/swiftlang/swift-package-manager.git", branch: "release/5.10"),
.package(url: "https://github.com/dankinsoid/VaporToOpenAPI.git", from: "4.4.4"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VaporToOpenAPI is not thread-safe. It causes crashes when running tests in parallel. Rather than create openapi.json dynamically on the fly from the routes, we should switch to using the swift-openapi-generator.

Since the OpenAPI spec isn't a critical piece I've simply removed it for now.

.package(url: "https://github.com/pointfreeco/swift-custom-dump.git", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.8.0"),
.package(url: "https://github.com/pointfreeco/swift-parsing.git", from: "0.12.0"),
Expand Down Expand Up @@ -75,7 +74,6 @@ let package = Package(
.product(name: "SwiftPMDataModel-auto", package: "swift-package-manager"),
.product(name: "SwiftPMPackageCollections", package: "swift-package-manager"),
.product(name: "Vapor", package: "vapor"),
.product(name: "VaporToOpenAPI", package: "VaporToOpenAPI"),
.product(name: "SotoCognitoAuthentication", package: "soto-cognito-authentication")
],
swiftSettings: swiftSettings,
Expand Down
18 changes: 12 additions & 6 deletions Sources/App/Controllers/API/Types+WithExample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@

import Foundation

import VaporToOpenAPI
import DependencyResolution
import PackageCollectionsSigning

#warning("Keep this?")

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Query Performance Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?

Check warning on line 20 in Sources/App/Controllers/API/Types+WithExample.swift

View workflow job for this annotation

GitHub Actions / Test

Keep this?
protocol WithExample { }


// MARK: - External types

extension Date: VaporToOpenAPI.WithExample {
extension Date: WithExample {
public static var example: Self { .init(rfc1123: "Sat, 25 Apr 2020 10:55:00 UTC")! }
}

extension UUID: WithExample {
static var example: Self { .init() }
}


// MARK: - Internal types

Expand Down Expand Up @@ -101,7 +107,7 @@
}
}

extension PackageCollectionModel.V1.Collection: VaporToOpenAPI.WithExample {
extension PackageCollectionModel.V1.Collection: WithExample {
public static var example: Self {
.init(name: "Packages by mona",
overview: "A collection of packages authored by mona from the Swift Package Index",
Expand All @@ -120,7 +126,7 @@
}
}

extension PackageCollectionModel.V1.Signature.Certificate: VaporToOpenAPI.WithExample {
extension PackageCollectionModel.V1.Signature.Certificate: WithExample {
public static var example: Self {
.init(subject: .init(userID: "V676TFACYJ",
commonName: "Swift Package Collection: SPI Operations Limited",
Expand All @@ -133,13 +139,13 @@
}
}

extension PackageCollectionModel.V1.Signature: VaporToOpenAPI.WithExample {
extension PackageCollectionModel.V1.Signature: WithExample {
public static var example: Self {
.init(signature: "ewogICJhbGciIDogIlJ...<snip>...WD1pXXPrkvVJlv4w", certificate: .example)
}
}

extension PackageCollectionSigning.Model.SignedCollection: VaporToOpenAPI.WithExample {
extension PackageCollectionSigning.Model.SignedCollection: WithExample {
public static var example: Self {
.init(collection: .example, signature: .example)
}
Expand Down
7 changes: 4 additions & 3 deletions Sources/App/Core/AppMetrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
import Dependencies
import Metrics
import Prometheus
import Synchronization
import Vapor


enum AppMetrics {

nonisolated(unsafe) static var initialized = false
static let initialized = Mutex(false)

static func bootstrap() {
// prevent tests from boostrapping multiple times
guard !initialized else { return }
defer { initialized = true }
guard !initialized.withLock({ $0 }) else { return }
defer { initialized.withLock{ $0 = true } }
let client = PrometheusClient()
MetricsSystem.bootstrap(PrometheusMetricsFactory(client: client))
}
Expand Down
13 changes: 0 additions & 13 deletions Sources/App/Core/Authentication/User.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Authentication
import Dependencies
import JWTKit
import Vapor
import VaporToOpenAPI


struct User: Authenticatable, Equatable {
Expand Down Expand Up @@ -67,15 +66,3 @@ extension User {
}
}
}


extension AuthSchemeObject {
static var apiBearerToken: Self {
.bearer(id: "api_token",
description: "Token used for API access.")
}
static var builderBearerToken: Self {
.bearer(id: "builder_token",
description: "Token used for build result reporting.")
}
}
1 change: 0 additions & 1 deletion Sources/App/Core/Extensions/PSQLError+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import PostgresKit

extension PostgresNIO.PostgresError.Code: @unchecked Swift.Sendable {}

extension PSQLError {
// TODO: upstream to FluentKit's DatabaseError
Expand Down
4 changes: 2 additions & 2 deletions Sources/App/configure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Vapor


@discardableResult
public func configure(_ app: Application) async throws -> String {
public func configure(_ app: Application, databasePort: Int? = nil) async throws -> String {
#if DEBUG && os(macOS)
// The bundle is only loaded if /Applications/InjectionIII.app exists on the local development machine.
// Requires InjectionIII 4.7.3 or higher to be loaded for compatibility with Package.swift files.
Expand Down Expand Up @@ -55,7 +55,7 @@ public func configure(_ app: Application) async throws -> String {
// Setup database connection
guard
let host = Environment.get("DATABASE_HOST"),
let port = Environment.get("DATABASE_PORT").flatMap(Int.init),
let port = databasePort ?? Environment.get("DATABASE_PORT").flatMap(Int.init),
let username = Environment.get("DATABASE_USERNAME"),
let password = Environment.get("DATABASE_PASSWORD"),
let database = Environment.get("DATABASE_NAME")
Expand Down
36 changes: 18 additions & 18 deletions Sources/App/routes+documentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,76 +22,76 @@ func docRoutes(_ app: Application) throws {
// redirected to the fully formed documentation URL.
app.get(":owner", ":repository", "documentation") { req -> Response in
req.redirect(to: SiteURL.relativeURL(for: try await req.getDocRedirect(), fragment: .documentation))
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", "documentation", "**") { req -> Response in
req.redirect(to: SiteURL.relativeURL(for: try await req.getDocRedirect(), fragment: .documentation))
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", "tutorials", "**") { req -> Response in
req.redirect(to: SiteURL.relativeURL(for: try await req.getDocRedirect(), fragment: .tutorials))
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "documentation") { req -> Response in
req.redirect(to: SiteURL.relativeURL(for: try await req.getDocRedirect(), fragment: .documentation))
}.excludeFromOpenAPI()
}

// Stable URLs with reference (real reference or ~)
app.get(":owner", ":repository", ":reference", "documentation", ":archive") {
let route = try await $0.getDocRoute(fragment: .documentation)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "documentation", ":archive", "**") {
let route = try await $0.getDocRoute(fragment: .documentation)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", .fragment(.faviconIco)) {
let route = try await $0.getDocRoute(fragment: .faviconIco)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", .fragment(.faviconSvg)) {
let route = try await $0.getDocRoute(fragment: .faviconSvg)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "css", "**") {
let route = try await $0.getDocRoute(fragment: .css)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "data", "**") {
let route = try await $0.getDocRoute(fragment: .data)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "images", "**") {
let fragment: DocRoute.Fragment = $0.parameters.hasSuffix(".svg", caseInsensitive: true) ? .svgImages : .images
let route = try await $0.getDocRoute(fragment: fragment)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "img", "**") {
let fragment: DocRoute.Fragment = $0.parameters.hasSuffix(".svg", caseInsensitive: true) ? .svgImg : .img
let route = try await $0.getDocRoute(fragment: fragment)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "index", "**") {
let route = try await $0.getDocRoute(fragment: .index)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "js", "**") {
let route = try await $0.getDocRoute(fragment: .js)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", .fragment(.linkablePaths)) {
let route = try await $0.getDocRoute(fragment: .linkablePaths)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", .fragment(.themeSettings)) {
let route = try await $0.getDocRoute(fragment: .themeSettings)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "tutorials", "**") {
let route = try await $0.getDocRoute(fragment: .tutorials)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
app.get(":owner", ":repository", ":reference", "videos", "**") {
let route = try await $0.getDocRoute(fragment: .videos)
return try await PackageController.documentation(req: $0, route: route)
}.excludeFromOpenAPI()
}
}


Expand Down
Loading
Loading