Skip to content

Commit 3f8542b

Browse files
authored
Fixes #165 - Enable documentation comment validation in swift-format (#188)
### Motivation This is for better documentation Fixes #165 ### Modifications Enabled some rules in .swift-format ### Result The .swift-format will be changed and the rules will reflect into the project ### Test Plan Run tests and CI
1 parent a8db309 commit 3f8542b

File tree

72 files changed

+408
-55
lines changed

Some content is hidden

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

72 files changed

+408
-55
lines changed

.swift-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"prioritizeKeepingFunctionOutputTogether" : false,
1717
"respectsExistingLineBreaks" : true,
1818
"rules" : {
19-
"AllPublicDeclarationsHaveDocumentation" : false,
19+
"AllPublicDeclarationsHaveDocumentation" : true,
2020
"AlwaysUseLowerCamelCase" : false,
2121
"AmbiguousTrailingClosureOverload" : true,
2222
"BeginDocumentationCommentWithOneLineSummary" : false,
@@ -50,7 +50,7 @@
5050
"UseSynthesizedInitializer" : true,
5151
"UseTripleSlashForDocumentationComments" : true,
5252
"UseWhereClausesInForLoops" : false,
53-
"ValidateDocumentationComments" : false
53+
"ValidateDocumentationComments" : true
5454
},
5555
"spacesAroundRangeFormationOperators" : false,
5656
"tabWidth" : 8,

Examples/GreetingService/Sources/GreetingService/GreetingService.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ struct Handler: APIProtocol {
3232

3333
@main
3434
struct Main {
35+
/// The entry point of the program.
36+
///
37+
/// This is where the execution of the program begins. Any code you want to run
38+
/// when the program starts should be placed within this method.
39+
///
40+
/// Example:
41+
/// ```
42+
/// public static func main() {
43+
/// print("Hello, World!")
44+
/// }
45+
/// ```
46+
/// - Throws: An error of type `Error` if there's an issue creating or running the Vapor application.
3547
public static func main() throws {
3648
// Create a Vapor application.
3749
let app = Vapor.Application()

Sources/PetstoreConsumerTestCore/Assertions.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import Foundation
1515
import XCTest
1616
import OpenAPIRuntime
1717

18+
/// Asserts that the stringified data matches the expected string value.
1819
public func XCTAssertEqualStringifiedData(
1920
_ expression1: @autoclosure () throws -> Data?,
2021
_ expression2: @autoclosure () throws -> String,
@@ -33,7 +34,7 @@ public func XCTAssertEqualStringifiedData(
3334
XCTFail(error.localizedDescription, file: file, line: line)
3435
}
3536
}
36-
37+
/// Asserts that the stringified data matches the expected string value.
3738
public func XCTAssertEqualStringifiedData<S: Sequence>(
3839
_ expression1: @autoclosure () throws -> S?,
3940
_ expression2: @autoclosure () throws -> String,
@@ -52,7 +53,7 @@ public func XCTAssertEqualStringifiedData<S: Sequence>(
5253
XCTFail(error.localizedDescription, file: file, line: line)
5354
}
5455
}
55-
56+
/// Asserts that the stringified data matches the expected string value.
5657
public func XCTAssertEqualStringifiedData(
5758
_ expression1: @autoclosure () throws -> HTTPBody?,
5859
_ expression2: @autoclosure () throws -> String,

Sources/PetstoreConsumerTestCore/Common.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public enum TestError: Swift.Error, LocalizedError, CustomStringConvertible, Sen
2121
case unexpectedValue(any Sendable)
2222
case unexpectedMissingRequestBody
2323

24+
/// A human-readable description of the error.
2425
public var description: String {
2526
switch self {
2627
case .noHandlerFound(let method, let path):
@@ -34,6 +35,7 @@ public enum TestError: Swift.Error, LocalizedError, CustomStringConvertible, Sen
3435
}
3536
}
3637

38+
/// A localized description of the error suitable for presenting to the user.
3739
public var errorDescription: String? {
3840
description
3941
}

Sources/PetstoreConsumerTestCore/TestClientTransport.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,47 @@ import OpenAPIRuntime
1515
import Foundation
1616
import HTTPTypes
1717

18+
/// A test implementation of the `ClientTransport` protocol.
19+
///
20+
/// The `TestClientTransport` struct provides a way to simulate network calls by
21+
/// utilizing a custom `CallHandler` closure. This allows testing the behavior of
22+
/// client-side API interactions in controlled scenarios.
23+
///
24+
/// Example usage:
25+
/// ```swift
26+
/// let testTransport = TestClientTransport { request, baseURL, operationID in
27+
/// // Simulate response logic here
28+
/// return Response(...)
29+
/// }
30+
///
31+
/// let client = APIClient(transport: testTransport)
32+
/// ```
1833
public struct TestClientTransport: ClientTransport {
1934

35+
/// A typealias representing a call handler closure for processing client requests.
2036
public typealias CallHandler = @Sendable (HTTPRequest, HTTPBody?, URL, String) async throws -> (
2137
HTTPResponse, HTTPBody?
2238
)
2339

40+
/// The call handler responsible for processing client requests.
2441
public let callHandler: CallHandler
2542

43+
/// Initializes a `TestClientTransport` instance with a custom call handler.
44+
///
45+
/// - Parameter callHandler: The closure responsible for processing client requests.
2646
public init(callHandler: @escaping CallHandler) {
2747
self.callHandler = callHandler
2848
}
2949

50+
/// Sends a client request using the test transport.
51+
///
52+
/// - Parameters:
53+
/// - request: The request to send.
54+
/// - body: The optional HTTP body to include in the request.
55+
/// - baseURL: The base URL for the request.
56+
/// - operationID: The ID of the operation being performed.
57+
/// - Returns: The response received from the call handler.
58+
/// - Throws: An error if the call handler encounters an issue.
3059
public func send(
3160
_ request: HTTPRequest,
3261
body: HTTPBody?,

Sources/PetstoreConsumerTestCore/TestServerTransport.swift

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,35 +14,77 @@
1414
import OpenAPIRuntime
1515
import HTTPTypes
1616

17+
/// A test implementation of the `ServerTransport` protocol for simulating server-side API handling.
18+
///
19+
/// The `TestServerTransport` class allows you to define custom operations and handlers that
20+
/// simulate server-side API handling. This is useful for testing and verifying the behavior of
21+
/// your server-related code without the need for actual network interactions.
22+
///
23+
/// Example usage:
24+
/// ```swift
25+
/// let testTransport = TestServerTransport()
26+
/// try testTransport.register { request, metadata in
27+
/// // Simulate server response logic here
28+
/// return Response(...)
29+
/// }
30+
///
31+
/// let server = MyServer(transport: testTransport)
32+
/// ```
1733
public final class TestServerTransport: ServerTransport {
18-
34+
/// Represents the input parameters for an API operation.
1935
public struct OperationInputs: Equatable {
36+
/// The HTTP method of the operation.
2037
public var method: HTTPRequest.Method
38+
/// The path components of the operation's route.
2139
public var path: String
2240

41+
/// Initializes a new instance of `OperationInputs`.
42+
///
43+
/// - Parameters:
44+
/// - method: The HTTP method of the operation.
45+
/// - path: The path components of the operation's route.
2346
public init(method: HTTPRequest.Method, path: String) {
2447
self.method = method
2548
self.path = path
2649
}
2750
}
2851

52+
/// A typealias representing a handler closure for processing server requests.
2953
public typealias Handler = @Sendable (HTTPRequest, HTTPBody?, ServerRequestMetadata) async throws -> (
3054
HTTPResponse, HTTPBody?
3155
)
3256

57+
/// Represents an operation with its inputs and associated handler.
3358
public struct Operation {
59+
/// The input parameters for the API operation.
3460
public var inputs: OperationInputs
61+
/// The closure representing the server operation logic.
3562
public var closure: Handler
3663

64+
/// Initializes a new instance of `Operation`.
65+
///
66+
/// - Parameters:
67+
/// - inputs: The input parameters for the API operation.
68+
/// - closure: The closure representing the server operation logic
3769
public init(inputs: OperationInputs, closure: @escaping Handler) {
3870
self.inputs = inputs
3971
self.closure = closure
4072
}
4173
}
4274

75+
/// Initializes a new instance of `TestServerTransport`.
4376
public init() {}
77+
78+
/// The array of registered operations.
4479
public private(set) var registered: [Operation] = []
4580

81+
/// Registers a new API operation handler with specific parameters.
82+
///
83+
/// - Parameters:
84+
/// - handler: The closure representing the server operation logic.
85+
/// - method: The HTTP method of the operation.
86+
/// - path: The path components of the operation.
87+
/// - Throws: An error if there's an issue registering the operation.
4688
public func register(
4789
_ handler: @Sendable @escaping (HTTPRequest, HTTPBody?, ServerRequestMetadata) async throws -> (
4890
HTTPResponse, HTTPBody?

Sources/_OpenAPIGeneratorCore/Diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,14 @@ public struct Diagnostic: Error, Codable, Sendable {
142142
}
143143

144144
extension Diagnostic.Severity: CustomStringConvertible {
145+
/// A textual representation of the diagnostic severity.
145146
public var description: String {
146147
rawValue
147148
}
148149
}
149150

150151
extension Diagnostic: CustomStringConvertible {
152+
/// A textual representation of the diagnostic, including location, severity, message, and context.
151153
public var description: String {
152154
var prefix = ""
153155
if let location = location {
@@ -163,6 +165,7 @@ extension Diagnostic: CustomStringConvertible {
163165
}
164166

165167
extension Diagnostic: LocalizedError {
168+
/// A localized description of the diagnostic.
166169
public var errorDescription: String? {
167170
description
168171
}
@@ -321,6 +324,9 @@ struct PrintingDiagnosticCollector: DiagnosticCollector {
321324
/// Creates a new collector.
322325
public init() {}
323326

327+
/// Emits a diagnostic message by printing it to the standard output.
328+
///
329+
/// - Parameter diagnostic: The diagnostic message to emit.
324330
public func emit(_ diagnostic: Diagnostic) {
325331
print(diagnostic.description)
326332
}
@@ -331,6 +337,9 @@ public struct StdErrPrintingDiagnosticCollector: DiagnosticCollector, Sendable {
331337
/// Creates a new collector.
332338
public init() {}
333339

340+
/// Emits a diagnostic message to standard error.
341+
///
342+
/// - Parameter diagnostic: The diagnostic message to emit.
334343
public func emit(_ diagnostic: Diagnostic) {
335344
stdErrHandle.write(diagnostic.description)
336345
}

Sources/_OpenAPIGeneratorCore/Extensions/Foundation.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extension Data {
3030
extension InMemoryInputFile {
3131
/// Creates a new in-memory file by reading the contents at the specified path.
3232
/// - Parameter url: The path to the file to read.
33+
/// - Throws: An error if there's an issue reading the file or initializing the in-memory file.
3334
init(fromFileAt url: URL) throws {
3435
try self.init(absolutePath: url, contents: Data(contentsOf: url))
3536
}
@@ -50,6 +51,12 @@ extension InMemoryOutputFile {
5051
let stdErrHandle = FileHandle.standardError
5152

5253
extension FileHandle: TextOutputStream {
54+
/// Writes the given string to the file handle.
55+
///
56+
/// This method writes the provided string to the file handle using its UTF-8
57+
/// representation.
58+
///
59+
/// - Parameter string: The string to be written to the file handle.
5360
public func write(_ string: String) {
5461
write(Data(string.utf8))
5562
}

Sources/_OpenAPIGeneratorCore/Extensions/OpenAPIKit.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ extension Either {
1818
/// Returns the contained value, looking it up in the specified
1919
/// OpenAPI components if it contains a reference.
2020
/// - Parameter components: The Components section of the OpenAPI document.
21+
/// - Returns: The resolved value from the `Either` instance.
22+
/// - Throws: An error if there's an issue looking up the value in the components.
2123
func resolve(
2224
in components: OpenAPI.Components
2325
) throws -> B where A == OpenAPI.Reference<B> {

Sources/_OpenAPIGeneratorCore/Extensions/String.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fileprivate extension String {
3131
/// Returns a copy of the string with the first letter modified by
3232
/// the specified closure.
3333
/// - Parameter transformation: A closure that modifies the first letter.
34+
/// - Returns: A new string with the modified first letter, or the original string if no letter is found.
3435
func transformingFirstLetter<T>(_ transformation: (Character) -> T) -> String where T: StringProtocol {
3536
guard let firstLetterIndex = self.firstIndex(where: \.isLetter) else {
3637
return self

Sources/_OpenAPIGeneratorCore/GeneratorMode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ extension GeneratorMode {
6767
}
6868

6969
extension GeneratorMode: Comparable {
70+
/// Compares modes based on their order.
7071
public static func < (lhs: GeneratorMode, rhs: GeneratorMode) -> Bool {
7172
lhs.order < rhs.order
7273
}

Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct GeneratorPipeline {
6767
/// recoverable diagnostics, such as unsupported features.
6868
/// - Parameter input: The input of the parsing stage.
6969
/// - Returns: The output of the rendering stage.
70+
/// - Throws: An error if a non-recoverable issue occurs during pipeline execution.
7071
func run(_ input: RawInput) throws -> RenderedOutput {
7172
try renderSwiftFilesStage.run(
7273
translateOpenAPIToStructuredSwiftStage.run(
@@ -97,6 +98,7 @@ public func runGenerator(
9798
/// Creates a new pipeline instance.
9899
/// - Parameters:
99100
/// - parser: An OpenAPI document parser.
101+
/// - validator: A validator for parsed OpenAPI documents.
100102
/// - translator: A translator from OpenAPI to Swift.
101103
/// - renderer: A Swift code renderer.
102104
/// - formatter: A Swift code formatter.

Sources/_OpenAPIGeneratorCore/GeneratorPipelineStage.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ struct GeneratorPipelineStage<Input, Output> {
3636
/// value or throwing an error.
3737
/// - Parameter input: An input value.
3838
/// - Returns: An output value.
39+
/// - Throws: An error if an issue occurs during the stage execution.
3940
func run(_ input: Input) throws -> Output {
4041
let hookedInput = try self.preTransitionHooks.reduce(input) { try $1($0) }
4142
let output = try self.transition(hookedInput)

Sources/_OpenAPIGeneratorCore/Layers/RenderedSwiftRepresentation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public struct InMemoryOutputFile: Sendable {
6363
}
6464

6565
extension InMemoryOutputFile: Comparable {
66+
/// Compares two `InMemoryOutputFile` instances based on `baseName` and contents for ordering.
6667
public static func < (lhs: InMemoryOutputFile, rhs: InMemoryOutputFile) -> Bool {
6768
guard lhs.baseName == rhs.baseName else {
6869
return lhs.baseName < rhs.baseName

0 commit comments

Comments
 (0)