From 27d1d3b59fcec01c9911d1b09c150240eff9f13e Mon Sep 17 00:00:00 2001 From: Javier Cicchelli Date: Mon, 29 Sep 2025 02:18:15 +0200 Subject: [PATCH] Renamed the DocCMiddleware.Configuration type in the library target as DocCConfiguration. --- .../Configurations/DoccConfiguration.swift | 50 ++++++++++++++++++ .../DoccMiddlewareConfiguration.swift | 52 ------------------- .../Public/Middlewares/DocCMiddleware.swift | 8 +-- .../Middlewares/DocCMiddlewareTests.swift | 9 ++-- 4 files changed, 57 insertions(+), 62 deletions(-) create mode 100644 Sources/HummingbirdDocC/Public/Configurations/DoccConfiguration.swift delete mode 100644 Sources/HummingbirdDocC/Public/Configurations/DoccMiddlewareConfiguration.swift diff --git a/Sources/HummingbirdDocC/Public/Configurations/DoccConfiguration.swift b/Sources/HummingbirdDocC/Public/Configurations/DoccConfiguration.swift new file mode 100644 index 0000000..760b784 --- /dev/null +++ b/Sources/HummingbirdDocC/Public/Configurations/DoccConfiguration.swift @@ -0,0 +1,50 @@ +// ===----------------------------------------------------------------------=== +// +// This source file is part of the Hummingbird DocC Middleware open source project +// +// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors +// Licensed under the EUPL 1.2 or later. +// +// See LICENSE for license information +// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors +// +// ===----------------------------------------------------------------------=== + +import class NIOPosix.NIOThreadPool + +/// A type that contains all the parameters to configure the ``DocCMiddleware`` middleware. +public struct DocCConfiguration: Sendable { + + // MARK: Properties + + /// A path to the physical location where the `DocC` documentation containers are stored. + let folderRoot: String + + /// A URI path that prefixes the `DocC` documentation resources. + let uriRoot: String + + /// A type that define a mechanism to use in case some blocking work needs to be performed for which no non-blocking API exists. + let threadPool: NIOThreadPool + + // MARK: Initializers + + /// Initializes this configuration type. + /// + /// > important: It is assumed that both the `uriRoot` and the `folderRoot` parameters should not be empty, and that they should be prefixed + /// with the `/` forward slash character. + /// + /// - Parameters: + /// - uriRoot: A URI path that prefixes the `DocC` documentation resources. + /// - folderRoot: A path to the physical location where the `DocC` documentation containers are stored. + /// - threadPool: A type that define a mechanism to use in case some blocking work needs to be performed for which no non-blocking API exists. + public init( + uriRoot: String, + folderRoot: String, + threadPool: NIOThreadPool = .singleton + ) { + self.folderRoot = folderRoot + self.uriRoot = uriRoot + self.threadPool = threadPool + } + +} diff --git a/Sources/HummingbirdDocC/Public/Configurations/DoccMiddlewareConfiguration.swift b/Sources/HummingbirdDocC/Public/Configurations/DoccMiddlewareConfiguration.swift deleted file mode 100644 index 0bc36c4..0000000 --- a/Sources/HummingbirdDocC/Public/Configurations/DoccMiddlewareConfiguration.swift +++ /dev/null @@ -1,52 +0,0 @@ -// ===----------------------------------------------------------------------=== -// -// This source file is part of the Hummingbird DocC Middleware open source project -// -// Copyright (c) 2025 Röck+Cöde VoF. and the Hummingbird DocC Middleware project authors -// Licensed under the EUPL 1.2 or later. -// -// See LICENSE for license information -// See CONTRIBUTORS for the list of Hummingbird DocC Middleware project authors -// -// ===----------------------------------------------------------------------=== - -import class NIOPosix.NIOThreadPool - -extension DocCMiddleware { - /// A type that contains all the parameters to configure the ``DocCMiddleware`` middleware. - public struct Configuration: Sendable { - - // MARK: Properties - - /// A path to the physical location where the `DocC` documentation containers are stored. - let folderRoot: String - - /// A URI path that prefixes the `DocC` documentation resources. - let uriRoot: String - - /// A type that define a mechanism to use in case some blocking work needs to be performed for which no non-blocking API exists. - let threadPool: NIOThreadPool - - // MARK: Initializers - - /// Initializes this configuration type. - /// - /// > important: It is assumed that both the `uriRoot` and the `folderRoot` parameters should not be empty, and that they should be prefixed - /// with the `/` forward slash character. - /// - /// - Parameters: - /// - uriRoot: A URI path that prefixes the `DocC` documentation resources. - /// - folderRoot: A path to the physical location where the `DocC` documentation containers are stored. - /// - threadPool: A type that define a mechanism to use in case some blocking work needs to be performed for which no non-blocking API exists. - public init( - uriRoot: String, - folderRoot: String, - threadPool: NIOThreadPool = .singleton - ) { - self.folderRoot = folderRoot - self.uriRoot = uriRoot - self.threadPool = threadPool - } - - } -} diff --git a/Sources/HummingbirdDocC/Public/Middlewares/DocCMiddleware.swift b/Sources/HummingbirdDocC/Public/Middlewares/DocCMiddleware.swift index 2f33c20..045bf60 100644 --- a/Sources/HummingbirdDocC/Public/Middlewares/DocCMiddleware.swift +++ b/Sources/HummingbirdDocC/Public/Middlewares/DocCMiddleware.swift @@ -46,9 +46,6 @@ public struct DocCMiddleware { // MARK: Properties - /// A type that contains the parameters to configure the middleware. - let configuration: Configuration - /// A type that conforms to a protocol that defines file system interactions. let fileProvider: FileSystemProvider @@ -74,7 +71,7 @@ public struct DocCMiddleware { /// - configuration: A type that contains the parameters to configure the middleware. /// - logger: A type that interacts with the logging system. public init( - configuration: Configuration, + configuration: DocCConfiguration, logger: Logger ) where FileSystemProvider == LocalFileSystem { self.init( @@ -94,12 +91,11 @@ public struct DocCMiddleware { /// - fileProvider: A type that conforms to the protocol that defines file system interactions. /// - logger: A type that interacts with the logging system. init( - configuration: Configuration, + configuration: DocCConfiguration, fileProvider: FileSystemProvider, logger: Logger, ) { self.logger = logger - self.configuration = configuration self.fileProvider = fileProvider self.prepareURIPath = .init(uriRoot: configuration.uriRoot) self.redirectURI = .init(logger: logger) diff --git a/Tests/HummingbirdDocC/Tests/Public/Middlewares/DocCMiddlewareTests.swift b/Tests/HummingbirdDocC/Tests/Public/Middlewares/DocCMiddlewareTests.swift index 704f7e5..965599e 100644 --- a/Tests/HummingbirdDocC/Tests/Public/Middlewares/DocCMiddlewareTests.swift +++ b/Tests/HummingbirdDocC/Tests/Public/Middlewares/DocCMiddlewareTests.swift @@ -20,6 +20,7 @@ import struct Hummingbird.LocalFileSystem import struct Hummingbird.Request import struct Logging.Logger +@testable import struct HummingbirdDocC.DocCConfiguration @testable import struct HummingbirdDocC.DocCMiddleware @Suite("DocC Middleware", .tags(.middleware)) @@ -290,7 +291,7 @@ private extension DocCMiddlewareTests { /// - configuration: A type that contains the parameters to configure the middleware. /// - logger: A type that interacts with the logging system. func assertInit( - configuration: DocCMiddleware.Configuration, + configuration: DocCConfiguration, logger: Logger = .test() ) { // GIVEN @@ -318,7 +319,7 @@ private extension DocCMiddlewareTests { /// - logger: A type that interacts with the logging system. /// - fileProvider: A type that conforms to the protocol that defines file system interactions, if any. func assertInit( - configuration: DocCMiddleware.Configuration, + configuration: DocCConfiguration, logger: Logger = .test(), fileProvider: FileSystemProvider ) { @@ -448,7 +449,7 @@ private extension DocCMiddlewareTests { default: .init(fileIdentifier: .init(), shouldLoadFile: false) } - let context: any RequestContext = RequestContextMock(logger: logger) + let context: RequestContextMock = .init(logger: logger) let request: Request = .test( method: .get, path: uriPath @@ -475,7 +476,7 @@ private extension DocCMiddlewareTests { .contentLength: (statusCode == .ok ? "36" : "0") ]) - let contentLength = try #require(result.body.contentLength) + let contentLength = #require(result.body.contentLength) if statusCode == .ok { #expect(contentLength > 0)