Skip to content

Commit b17fdf5

Browse files
authored
Add missing documentation comments (#157)
Motivation ---------- All public declarations should have documentation comments, but a number did not. The linter configuration previously accepted these files but now rejects them; the linter depends on the upstream `swift` container image, which is updated from time to time. Modifications ------------- Add documentation comments for public declarations identified by the format linter. Result ------ All public declarations are documented. Test Plan --------- The linter passes locally. No functional change, all unit tests continue to pass.
1 parent 9417b63 commit b17fdf5

File tree

8 files changed

+74
-1
lines changed

8 files changed

+74
-1
lines changed

Plugins/ContainerImageBuilder/runner.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import Foundation
1616

17+
/// Error code returned if the process terminates because of an uncaught signal.
1718
public enum ExitCode: Error { case rawValue(Int32) }
1819

1920
/// Runs `command` with the given arguments and environment variables, capturing standard output and standard error.

Sources/ContainerRegistry/AuthHandler.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ func parseChallenge(_ s: String) throws -> BearerChallenge {
110110
return res
111111
}
112112

113+
/// AuthChallenge represents an HTTP `WWW-Authenticate` challenge header.
113114
public enum AuthChallenge: Equatable {
114115
case none
115116
case basic(String)
@@ -156,6 +157,15 @@ public struct AuthHandler {
156157
return nil
157158
}
158159

160+
/// Respond to an HTTP `WWW-Authenticate` challenge header sent by a container registry.
161+
/// - Parameters:
162+
/// - registry: The registry which issued the challenge.
163+
/// - repository: The repository path within the registry for which permission is to be requested.
164+
/// - actions: The repository actions for which permission is to be requested.
165+
/// - scheme: The challenge header to which to respond.
166+
/// - client: An HTTPClient instance to use when contacting the registry.
167+
/// - Returns: An `Authorization` header appropriate to the challenge.
168+
/// - Throws: If scheme is `Bearer` and an error occurs when contacting the OAuth server.
159169
public func auth(
160170
registry: URL,
161171
repository: ImageReference.Repository,

Sources/ContainerRegistry/HTTPClient.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import FoundationNetworking
1919
import HTTPTypes
2020
import HTTPTypesFoundation
2121

22-
// HEAD does not include a response body so if an error is thrown, data will be nil
22+
/// An error encountered while making an HTTP request
23+
///
24+
/// The response to a `HEAD` request does not include a body so if an error is thrown, `data` will be `nil`
2325
public enum HTTPClientError: Error {
2426
case unexpectedStatusCode(status: HTTPResponse.Status, response: HTTPResponse, data: Data?)
2527
case unexpectedContentType(String)

Sources/ContainerRegistry/ImageReference.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public struct ImageReference: Sendable, Equatable, CustomStringConvertible, Cust
6666
/// The tag or digest identifying the image.
6767
public var reference: Reference
6868

69+
/// Error thrown when an `ImageReference` string cannot be parsed.
6970
public enum ValidationError: Error {
7071
case unexpected(String)
7172
}
@@ -114,6 +115,11 @@ public struct ImageReference: Sendable, Equatable, CustomStringConvertible, Cust
114115
self.reference = reference
115116
}
116117

118+
/// Returns a Boolean value indicating whether two `ImageReference` values are equal.
119+
/// - Parameters:
120+
/// - lhs: First `ImageReference` to compare
121+
/// - rhs: Second `ImageReference` to compare
122+
/// - Returns: `True` if the `ImageReferences` are equal, otherwise `false`
117123
public static func == (lhs: ImageReference, rhs: ImageReference) -> Bool {
118124
"\(lhs)" == "\(rhs)"
119125
}
@@ -138,12 +144,16 @@ extension ImageReference {
138144
public struct Repository: Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
139145
var value: String
140146

147+
/// Error thrown when a `Repository` string cannot be parsed.
141148
public enum ValidationError: Error, Equatable {
142149
case emptyString
143150
case containsUppercaseLetters(String)
144151
case invalidReferenceFormat(String)
145152
}
146153

154+
/// Creates an `ImageReference.Repository` instance from a string.
155+
/// - Parameter rawValue: A repository string
156+
/// - Throws: If `rawValue` cannot be parsed
147157
public init(_ rawValue: String) throws {
148158
// Reference handling in github.com/distribution reports empty and uppercase as specific errors.
149159
// All other errors caused are reported as generic format errors.
@@ -164,6 +174,7 @@ extension ImageReference {
164174
value = rawValue
165175
}
166176

177+
/// Printable description of a Reference in a form which can be understood by a runtime
167178
public var description: String {
168179
value
169180
}
@@ -185,12 +196,16 @@ extension ImageReference {
185196
public struct Tag: Reference, Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
186197
var value: String
187198

199+
/// Error thrown when a `Tag` cannot be parsed.
188200
public enum ValidationError: Error, Equatable {
189201
case emptyString
190202
case invalidReferenceFormat(String)
191203
case tooLong(String)
192204
}
193205

206+
/// Creates a `Tag` instance from a string.
207+
/// - Parameter rawValue: A tag string
208+
/// - Throws: If `rawValue` cannot be parsed
194209
public init(_ rawValue: String) throws {
195210
guard rawValue.count > 0 else {
196211
throw ValidationError.emptyString
@@ -209,12 +224,19 @@ extension ImageReference {
209224
value = rawValue
210225
}
211226

227+
/// Returns a Boolean value indicating whether two `Tag` values are equal.
228+
/// - Parameters:
229+
/// - lhs: First `Tag` to compare
230+
/// - rhs: Second `Tag` to compare
231+
/// - Returns: `True` if the `Tag` are equal, otherwise `false`
212232
public static func == (lhs: Tag, rhs: Tag) -> Bool {
213233
lhs.value == rhs.value
214234
}
215235

236+
/// Value which separates the `tag` from the registry and repository parts of a image reference with a human readable tag
216237
public var separator: String = ":"
217238

239+
/// Printable description of a Tag in a form which can be understood by a runtime
218240
public var description: String {
219241
"\(value)"
220242
}
@@ -227,10 +249,14 @@ extension ImageReference {
227249

228250
/// Digest identifies a specific blob by the hash of the blob's contents.
229251
public struct Digest: Reference, Sendable, Equatable, CustomStringConvertible, CustomDebugStringConvertible {
252+
/// Represents a digest algorithm
230253
public enum Algorithm: String, Sendable {
231254
case sha256 = "sha256"
232255
case sha512 = "sha512"
233256

257+
/// Creates an `Algorithm` instance from a string.
258+
/// - Parameter rawValue: An algorithm string
259+
/// - Throws: If `rawValue` cannot be parsed
234260
init(fromString rawValue: String) throws {
235261
guard let algorithm = Algorithm(rawValue: rawValue) else {
236262
throw RegistryClientError.invalidDigestAlgorithm(rawValue)
@@ -242,11 +268,15 @@ extension ImageReference {
242268
var algorithm: Algorithm
243269
var value: String
244270

271+
/// Error thrown when a `Digest` cannot be parsed.
245272
public enum ValidationError: Error, Equatable {
246273
case emptyString
247274
case invalidReferenceFormat(String)
248275
}
249276

277+
/// Creates a `Digest` instance from a string.
278+
/// - Parameter rawValue: A digest string
279+
/// - Throws: If `rawValue` cannot be parsed
250280
public init(_ rawValue: String) throws {
251281
guard rawValue.count > 0 else {
252282
throw ValidationError.emptyString
@@ -271,12 +301,19 @@ extension ImageReference {
271301
throw ValidationError.invalidReferenceFormat(rawValue)
272302
}
273303

304+
/// Returns a Boolean value indicating whether two `Digest` values are equal.
305+
/// - Parameters:
306+
/// - lhs: First `Digest` to compare
307+
/// - rhs: Second `Digest` to compare
308+
/// - Returns: `True` if the `Digest` are equal, otherwise `false`
274309
public static func == (lhs: Digest, rhs: Digest) -> Bool {
275310
lhs.algorithm == rhs.algorithm && lhs.value == rhs.value
276311
}
277312

313+
/// Value which separates the `digest` from the registry and repository parts of an image reference with a digest
278314
public var separator: String = "@"
279315

316+
/// Printable description of a Digest in a form which can be understood by a runtime
280317
public var description: String {
281318
"\(algorithm):\(value)"
282319
}

Sources/ContainerRegistry/RegistryClient.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import FoundationNetworking
1919
import HTTPTypes
2020
import Basics
2121

22+
/// An error encountered while communicating with a container registry.
2223
public enum RegistryClientError: Error {
2324
case registryParseError(String)
2425
case invalidRegistryPath(String)

Sources/ContainerRegistry/Schema.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public struct ImageConfigurationRootFS: Codable, Hashable, Sendable {
176176
self.diff_ids = diff_ids
177177
}
178178

179+
/// Field name mapping
179180
public enum CodingKeys: String, CodingKey {
180181
case _type = "type"
181182
case diff_ids
@@ -400,6 +401,7 @@ public struct Platform: Codable, Hashable, Sendable {
400401
self.features = features
401402
}
402403

404+
/// Field name mapping
403405
public enum CodingKeys: String, CodingKey {
404406
case architecture
405407
case os

Sources/ContainerRegistry/ScratchImage.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public struct ScratchImage {
2727
var manifestDescriptor: ContentDescriptor
2828
var index: ImageIndex
2929

30+
/// Construct a `ScratchImage` structure, representing a scratch container image with no contents.
31+
/// - Parameters:
32+
/// - architecture: The CPU architecture encoded in the scratch image layer. The scratch layer is empty, but this value should match any layers stacked on top of it.
33+
/// - os: The operating system name encoded in the scratch image layer. The scratch layer is empty, but this value should match any layers stacked on top of it.
3034
public init(architecture: String, os: String) {
3135
self.encoder = containerJSONEncoder()
3236

Sources/Tar/tar.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,22 @@ public struct TarHeader {
242242
/// Filename prefix - prepended to name
243243
var prefix: String = ""
244244

245+
/// Construct a Tar archive header block
246+
/// - Parameters:
247+
/// - name: File name
248+
/// - mode: Access mode
249+
/// - uid: File owner's user ID
250+
/// - gid: File's group ID
251+
/// - size: File size in octets
252+
/// - mtime: Last modification time
253+
/// - typeflag: Type of file represented by this header
254+
/// - linkname: Reference to a previous file in the archive. Only valid when `typeflag` is `.LNKTYPE`. This is an internal link in the archive file, _not_ a symbolic link.
255+
/// - uname: File owner's user name
256+
/// - gname: File's group name
257+
/// - devmajor: Device major number. Only valid when `typeflag` is `.BLKTYPE` or `.CHRTYPE`.
258+
/// - devminor: Device minor number. Only valid when `typeflag` is `.BLKTYPE` or `.CHRTYPE`.
259+
/// - prefix: Optional filename prefix, allowing file names longer than 100 octets to be stored.
260+
/// - Throws: If the value of any field cannot be represented in a Tar header.
245261
public init(
246262
name: String,
247263
mode: Int = 0o555,

0 commit comments

Comments
 (0)