Skip to content

Commit b931341

Browse files
authored
Enable documentation comment validation in swift-format (#59)
1 parent 506953d commit b931341

37 files changed

+584
-69
lines changed

.swift-format

+2-2
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" : false,
5151
"UseTripleSlashForDocumentationComments" : true,
5252
"UseWhereClausesInForLoops" : false,
53-
"ValidateDocumentationComments" : false
53+
"ValidateDocumentationComments" : true
5454
},
5555
"spacesAroundRangeFormationOperators" : false,
5656
"tabWidth" : 8,

Sources/OpenAPIRuntime/Base/Acceptable.swift

+19-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public struct QualityValue: Sendable, Hashable {
3535

3636
/// Creates a new quality value from the provided floating-point number.
3737
///
38-
/// - Precondition: The value must be between 0.0 and 1.0, inclusive.
38+
/// - Parameter doubleValue: The floating-point number representing the quality value.
39+
/// - Precondition: The `doubleValue` must be between 0.0 and 1.0, inclusive.
3940
public init(doubleValue: Double) {
4041
precondition(
4142
doubleValue >= 0.0 && doubleValue <= 1.0,
@@ -51,19 +52,27 @@ public struct QualityValue: Sendable, Hashable {
5152
}
5253

5354
extension QualityValue: RawRepresentable {
55+
/// Creates a new `QualityValue` instance from a raw string value.
56+
///
57+
/// - Parameter rawValue: A string representing the quality value.
5458
public init?(rawValue: String) {
5559
guard let doubleValue = Double(rawValue) else {
5660
return nil
5761
}
5862
self.init(doubleValue: doubleValue)
5963
}
6064

65+
/// The raw string representation of the `QualityValue`.
6166
public var rawValue: String {
6267
String(format: "%0.3f", doubleValue)
6368
}
6469
}
6570

6671
extension QualityValue: ExpressibleByIntegerLiteral {
72+
/// Creates a new `QualityValue` instance from an integer literal value.
73+
///
74+
/// - Parameter value: An integer literal value representing the quality value.
75+
/// - Precondition: The `integerLiteral` must be between 0.0 and 1.0, inclusive.
6776
public init(integerLiteral value: UInt16) {
6877
precondition(
6978
value >= 0 && value <= 1,
@@ -74,6 +83,9 @@ extension QualityValue: ExpressibleByIntegerLiteral {
7483
}
7584

7685
extension QualityValue: ExpressibleByFloatLiteral {
86+
/// Creates a new `QualityValue` instance from a floating-point literal value.
87+
///
88+
/// - Parameter value: A floating-point literal value representing the quality value.
7789
public init(floatLiteral value: Double) {
7890
self.init(doubleValue: value)
7991
}
@@ -106,10 +118,10 @@ public struct AcceptHeaderContentType<ContentType: AcceptableProtocol>: Sendable
106118
public var quality: QualityValue
107119

108120
/// Creates a new content type from the provided parameters.
121+
///
109122
/// - Parameters:
110-
/// - value: The value representing the content type.
123+
/// - contentType: The value representing the content type.
111124
/// - quality: The quality of the content type, between 0.0 and 1.0.
112-
/// - Precondition: Quality must be in the range 0.0 and 1.0 inclusive.
113125
public init(contentType: ContentType, quality: QualityValue = 1.0) {
114126
self.quality = quality
115127
self.contentType = contentType
@@ -123,6 +135,9 @@ public struct AcceptHeaderContentType<ContentType: AcceptableProtocol>: Sendable
123135
}
124136

125137
extension AcceptHeaderContentType: RawRepresentable {
138+
/// Initializes an `AcceptHeaderContentType` instance from its raw string value.
139+
///
140+
/// - Parameter rawValue: The raw string value representing the content type.
126141
public init?(rawValue: String) {
127142
guard let validMimeType = OpenAPIMIMEType(rawValue) else {
128143
// Invalid MIME type.
@@ -145,6 +160,7 @@ extension AcceptHeaderContentType: RawRepresentable {
145160
self.init(contentType: typeAndSubtype, quality: quality)
146161
}
147162

163+
/// The raw representation of the content negotiation as a MIME type string.
148164
public var rawValue: String {
149165
contentType.rawValue + (quality.isDefault ? "" : "; q=\(quality.rawValue)")
150166
}

Sources/OpenAPIRuntime/Base/Base64EncodedData.swift

+8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public struct Base64EncodedData: Sendable, Hashable {
6262
}
6363

6464
extension Base64EncodedData: Codable {
65+
/// Initializes a `Base64EncodedData` instance by decoding a base64-encoded string.
66+
///
67+
/// - Parameter decoder: The decoder from which to decode the base64-encoded string.
68+
/// - Throws: `RuntimeError.invalidBase64String`: If the provided string could not be successfully decoded as base64 data.
6569
public init(from decoder: any Decoder) throws {
6670
let container = try decoder.singleValueContainer()
6771
let base64EncodedString = try container.decode(String.self)
@@ -75,6 +79,10 @@ extension Base64EncodedData: Codable {
7579
self.init(data: ArraySlice(data))
7680
}
7781

82+
/// Encodes the binary data as a base64-encoded string.
83+
///
84+
/// - Parameter encoder: The encoder to which the base64-encoded string is written.
85+
/// - Throws: An error if the binary data cannot be successfully encoded as a base64 string.
7886
public func encode(to encoder: any Encoder) throws {
7987
var container = encoder.singleValueContainer()
8088

Sources/OpenAPIRuntime/Base/OpenAPIMIMEType.swift

+22
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ public struct OpenAPIMIMEType: Equatable {
2929
/// A concrete value, spelled as `type/subtype`.
3030
case concrete(type: String, subtype: String)
3131

32+
/// Compares two MIME type kinds for equality.
33+
///
34+
/// - Parameters:
35+
/// - lhs: The left-hand side MIME type kind.
36+
/// - rhs: The right-hand side MIME type kind.
37+
///
38+
/// - Returns: `true` if the MIME type kinds are equal, otherwise `false`.
3239
public static func == (lhs: Kind, rhs: Kind) -> Bool {
3340
switch (lhs, rhs) {
3441
case (.any, .any):
@@ -59,6 +66,13 @@ public struct OpenAPIMIMEType: Equatable {
5966
self.parameters = parameters
6067
}
6168

69+
/// Compares two MIME types for equality.
70+
///
71+
/// - Parameters:
72+
/// - lhs: The left-hand side MIME type.
73+
/// - rhs: The right-hand side MIME type.
74+
///
75+
/// - Returns: `true` if the MIME types are equal, otherwise `false`.
6276
public static func == (lhs: OpenAPIMIMEType, rhs: OpenAPIMIMEType) -> Bool {
6377
guard lhs.kind == rhs.kind else {
6478
return false
@@ -85,6 +99,9 @@ public struct OpenAPIMIMEType: Equatable {
8599
}
86100

87101
extension OpenAPIMIMEType.Kind: LosslessStringConvertible {
102+
/// Initializes a MIME type kind from a string description.
103+
///
104+
/// - Parameter description: A string description of the MIME type kind.
88105
public init?(_ description: String) {
89106
let typeAndSubtype =
90107
description
@@ -106,6 +123,7 @@ extension OpenAPIMIMEType.Kind: LosslessStringConvertible {
106123
}
107124
}
108125

126+
/// A textual representation of the MIME type kind.
109127
public var description: String {
110128
switch self {
111129
case .any:
@@ -119,6 +137,9 @@ extension OpenAPIMIMEType.Kind: LosslessStringConvertible {
119137
}
120138

121139
extension OpenAPIMIMEType: LosslessStringConvertible {
140+
/// Initializes an `OpenAPIMIMEType` instance based on a string description.
141+
///
142+
/// - Parameter description: A string description of the MIME.
122143
public init?(_ description: String) {
123144
var components =
124145
description
@@ -157,6 +178,7 @@ extension OpenAPIMIMEType: LosslessStringConvertible {
157178
)
158179
}
159180

181+
/// A string description of the MIME type.
160182
public var description: String {
161183
([kind.description]
162184
+ parameters

Sources/OpenAPIRuntime/Base/OpenAPIValue.swift

+68
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
9898

9999
// MARK: Decodable
100100

101+
/// Initializes an `OpenAPIValueContainer` by decoding it from a decoder.
102+
///
103+
/// - Parameter decoder: The decoder to read data from.
104+
/// - Throws: An error if the decoding process encounters issues or if the data is corrupted.
101105
public init(from decoder: any Decoder) throws {
102106
let container = try decoder.singleValueContainer()
103107
if container.decodeNil() {
@@ -124,6 +128,10 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
124128

125129
// MARK: Encodable
126130

131+
/// Encodes the `OpenAPIValueContainer` and writes it to an encoder.
132+
///
133+
/// - Parameter encoder: The encoder to which the value should be encoded.
134+
/// - Throws: An error if the encoding process encounters issues or if the value is invalid.
127135
public func encode(to encoder: any Encoder) throws {
128136
var container = encoder.singleValueContainer()
129137
guard let value = value else {
@@ -153,6 +161,12 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
153161

154162
// MARK: Equatable
155163

164+
/// Compares two `OpenAPIValueContainer` instances for equality.
165+
///
166+
/// - Parameters:
167+
/// - lhs: The left-hand side `OpenAPIValueContainer` to compare.
168+
/// - rhs: The right-hand side `OpenAPIValueContainer` to compare.
169+
/// - Returns: `true` if the two instances are equal, `false` otherwise.
156170
public static func == (lhs: OpenAPIValueContainer, rhs: OpenAPIValueContainer) -> Bool {
157171
switch (lhs.value, rhs.value) {
158172
case (nil, nil), is (Void, Void):
@@ -201,6 +215,9 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
201215

202216
// MARK: Hashable
203217

218+
/// Hashes the `OpenAPIValueContainer` instance into a hasher.
219+
///
220+
/// - Parameter hasher: The hasher used to compute the hash value.
204221
public func hash(into hasher: inout Hasher) {
205222
switch value {
206223
case let value as Bool:
@@ -227,30 +244,45 @@ public struct OpenAPIValueContainer: Codable, Hashable, Sendable {
227244
}
228245

229246
extension OpenAPIValueContainer: ExpressibleByBooleanLiteral {
247+
/// Creates an `OpenAPIValueContainer` with the provided boolean value.
248+
///
249+
/// - Parameter value: The boolean value to store in the container.
230250
public init(booleanLiteral value: BooleanLiteralType) {
231251
self.init(validatedValue: value)
232252
}
233253
}
234254

235255
extension OpenAPIValueContainer: ExpressibleByStringLiteral {
256+
/// Creates an `OpenAPIValueContainer` with the provided string value.
257+
///
258+
/// - Parameter value: The string value to store in the container.
236259
public init(stringLiteral value: String) {
237260
self.init(validatedValue: value)
238261
}
239262
}
240263

241264
extension OpenAPIValueContainer: ExpressibleByNilLiteral {
265+
/// Creates an `OpenAPIValueContainer` with a `nil` value.
266+
///
267+
/// - Parameter nilLiteral: The `nil` literal.
242268
public init(nilLiteral: ()) {
243269
self.init(validatedValue: nil)
244270
}
245271
}
246272

247273
extension OpenAPIValueContainer: ExpressibleByIntegerLiteral {
274+
/// Creates an `OpenAPIValueContainer` with the provided integer value.
275+
///
276+
/// - Parameter value: The integer value to store in the container.
248277
public init(integerLiteral value: Int) {
249278
self.init(validatedValue: value)
250279
}
251280
}
252281

253282
extension OpenAPIValueContainer: ExpressibleByFloatLiteral {
283+
/// Creates an `OpenAPIValueContainer` with the provided floating-point value.
284+
///
285+
/// - Parameter value: The floating-point value to store in the container.
254286
public init(floatLiteral value: Double) {
255287
self.init(validatedValue: value)
256288
}
@@ -317,6 +349,10 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
317349

318350
// MARK: Decodable
319351

352+
/// Creates an `OpenAPIValueContainer` by decoding it from a single-value container in a given decoder.
353+
///
354+
/// - Parameter decoder: The decoder used to decode the container.
355+
/// - Throws: An error if the decoding process encounters an issue or if the data does not match the expected format.
320356
public init(from decoder: any Decoder) throws {
321357
let container = try decoder.singleValueContainer()
322358
let item = try container.decode([String: OpenAPIValueContainer].self)
@@ -325,13 +361,24 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
325361

326362
// MARK: Encodable
327363

364+
/// Encodes the `OpenAPIValueContainer` into a format that can be stored or transmitted via the given encoder.
365+
///
366+
/// - Parameter encoder: The encoder used to perform the encoding.
367+
/// - Throws: An error if the encoding process encounters an issue or if the data does not match the expected format.
328368
public func encode(to encoder: any Encoder) throws {
329369
var container = encoder.singleValueContainer()
330370
try container.encode(value.mapValues(OpenAPIValueContainer.init(validatedValue:)))
331371
}
332372

333373
// MARK: Equatable
334374

375+
/// Compares two `OpenAPIObjectContainer` instances for equality by comparing their inner key-value dictionaries.
376+
///
377+
/// - Parameters:
378+
/// - lhs: The left-hand side `OpenAPIObjectContainer` to compare.
379+
/// - rhs: The right-hand side `OpenAPIObjectContainer` to compare.
380+
///
381+
/// - Returns: `true` if the `OpenAPIObjectContainer` instances are equal, `false` otherwise.
335382
public static func == (lhs: OpenAPIObjectContainer, rhs: OpenAPIObjectContainer) -> Bool {
336383
let lv = lhs.value
337384
let rv = rhs.value
@@ -352,6 +399,9 @@ public struct OpenAPIObjectContainer: Codable, Hashable, Sendable {
352399

353400
// MARK: Hashable
354401

402+
/// Hashes the `OpenAPIObjectContainer` instance into the provided `Hasher`.
403+
///
404+
/// - Parameter hasher: The `Hasher` into which the hash value is combined.
355405
public func hash(into hasher: inout Hasher) {
356406
for (key, itemValue) in value {
357407
hasher.combine(key)
@@ -414,12 +464,17 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
414464
/// Returns the specified value cast to an array of supported values.
415465
/// - Parameter value: An array with untyped values.
416466
/// - Returns: A cast value if values are supported, nil otherwise.
467+
/// - Throws: An error if casting to supported values fails for any element.
417468
static func tryCast(_ value: [(any Sendable)?]) throws -> [(any Sendable)?] {
418469
return try value.map(OpenAPIValueContainer.tryCast(_:))
419470
}
420471

421472
// MARK: Decodable
422473

474+
/// Initializes a new instance by decoding a validated array of values from a decoder.
475+
///
476+
/// - Parameter decoder: The decoder to use for decoding the array of values.
477+
/// - Throws: An error if the decoding process fails or if the decoded values cannot be validated.
423478
public init(from decoder: any Decoder) throws {
424479
let container = try decoder.singleValueContainer()
425480
let item = try container.decode([OpenAPIValueContainer].self)
@@ -428,13 +483,23 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
428483

429484
// MARK: Encodable
430485

486+
/// Encodes the array of validated values and stores the result in the given encoder.
487+
///
488+
/// - Parameter encoder: The encoder to use for encoding the array of values.
489+
/// - Throws: An error if the encoding process fails.
431490
public func encode(to encoder: any Encoder) throws {
432491
var container = encoder.singleValueContainer()
433492
try container.encode(value.map(OpenAPIValueContainer.init(validatedValue:)))
434493
}
435494

436495
// MARK: Equatable
437496

497+
/// Compares two `OpenAPIArrayContainer` instances for equality.
498+
///
499+
/// - Parameters:
500+
/// - lhs: The left-hand side `OpenAPIArrayContainer` to compare.
501+
/// - rhs: The right-hand side `OpenAPIArrayContainer` to compare.
502+
/// - Returns: `true` if the two `OpenAPIArrayContainer` instances are equal, `false` otherwise.
438503
public static func == (lhs: OpenAPIArrayContainer, rhs: OpenAPIArrayContainer) -> Bool {
439504
let lv = lhs.value
440505
let rv = rhs.value
@@ -449,6 +514,9 @@ public struct OpenAPIArrayContainer: Codable, Hashable, Sendable {
449514

450515
// MARK: Hashable
451516

517+
/// Hashes the `OpenAPIArrayContainer` instance into a hasher.
518+
///
519+
/// - Parameter hasher: The hasher used to compute the hash value.
452520
public func hash(into hasher: inout Hasher) {
453521
for item in value {
454522
hasher.combine(OpenAPIValueContainer(validatedValue: item))

Sources/OpenAPIRuntime/Base/WarningSuppressingAnnotations.swift

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
///
2424
/// There should be no runtime impact in release builds, as the function is inlined and
2525
/// has no executable code.
26+
/// - Parameter value: The value for which you want to suppress "variable was never mutated, change to let" warnings.
2627
@_spi(Generated)
2728
@inline(__always)
2829
public func suppressMutabilityWarning<T>(_ value: inout T) {}
@@ -38,6 +39,7 @@ public func suppressMutabilityWarning<T>(_ value: inout T) {}
3839
///
3940
/// There should be no runtime impact in release builds, as the function is inlined and
4041
/// has no executable code.
42+
/// - Parameter value: The value for which you want to suppress "variable unused" warnings.
4143
@_spi(Generated)
4244
@inline(__always)
4345
public func suppressUnusedWarning<T>(_ value: T) {}

0 commit comments

Comments
 (0)