Skip to content

Commit 496639f

Browse files
change sha512Checksum back into a non-optional property (#443)
rdar://103602701
1 parent 150eb7d commit 496639f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

Sources/SwiftDocC/Model/Rendering/RenderNodeTranslator.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
792792
downloadReferences[url.description] = DownloadReference(
793793
identifier: downloadIdentifier,
794794
renderURL: url,
795-
sha512Checksum: nil
795+
checksum: nil
796796
)
797797
} else if let fileReference = callToAction.file {
798798
let downloadIdentifier = createAndRegisterRenderReference(forMedia: fileReference, assetContext: .download)
@@ -1583,7 +1583,7 @@ public struct RenderNodeTranslator: SemanticVisitor {
15831583
let downloadData = try context.dataProvider.contentsOfURL(downloadURL, in: bundle)
15841584
downloadReference = DownloadReference(identifier: mediaReference,
15851585
renderURL: downloadURL,
1586-
sha512Checksum: Checksum.sha512(of: downloadData))
1586+
checksum: Checksum.sha512(of: downloadData))
15871587
} catch {
15881588
// It seems this is the way to error out of here.
15891589
return mediaReference

Sources/SwiftDocC/Model/Rendering/Tutorial/References/DownloadReference.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,32 +28,44 @@ public struct DownloadReference: RenderReference, URLReference {
2828
public var url: URL
2929

3030
/// The SHA512 hash value for the resource.
31-
public var sha512Checksum: String?
31+
public var checksum: String?
32+
33+
@available(*, deprecated, renamed: "checksum")
34+
public var sha512Checksum: String {
35+
get {
36+
return checksum ?? ""
37+
}
38+
set {
39+
if newValue.isEmpty {
40+
self.checksum = nil
41+
} else {
42+
self.checksum = newValue
43+
}
44+
}
45+
}
3246

3347
/// Creates a new reference to a downloadable resource.
3448
///
3549
/// - Parameters:
3650
/// - identifier: An identifier for the resource's reference.
3751
/// - url: The path to the resource.
3852
/// - sha512Checksum: The SHA512 hash value for the resource.
39-
public init(identifier: RenderReferenceIdentifier, renderURL url: URL, sha512Checksum: String?) {
53+
public init(identifier: RenderReferenceIdentifier, renderURL url: URL, checksum: String?) {
4054
self.identifier = identifier
4155
self.url = url
42-
self.sha512Checksum = sha512Checksum
56+
self.checksum = checksum
4357
}
44-
45-
enum CodingKeys: String, CodingKey {
46-
case type
47-
case identifier
48-
case url
49-
case sha512Checksum = "checksum"
58+
59+
@available(*, deprecated, message: "Use 'init(identifier:renderURL:checksum:)' instead")
60+
public init(identifier: RenderReferenceIdentifier, renderURL url: URL, sha512Checksum: String) {
61+
self.init(identifier: identifier, renderURL: url, checksum: sha512Checksum)
5062
}
5163

5264
public func encode(to encoder: Encoder) throws {
5365
var container = encoder.container(keyedBy: CodingKeys.self)
5466
try container.encode(type.rawValue, forKey: .type)
5567
try container.encode(identifier, forKey: .identifier)
56-
try container.encodeIfPresent(sha512Checksum, forKey: .sha512Checksum)
68+
try container.encodeIfPresent(checksum, forKey: .checksum)
5769

5870
// Render URL
5971
try container.encode(renderURL(for: url), forKey: .url)

0 commit comments

Comments
 (0)