Skip to content

Commit 20a0c8b

Browse files
authored
Encode absolute presentation URL if present (#1346)
* Add missing fields in Equatable implementation The `Equatable` implementation of `LinkDestinationSummary` was missing some of the new fields which were added recently. This commit adds them. * Encode absolute presentation URL if present Support for absolute URLs in link summaries was added in 7db36ad. It added support for absolute URLs when decoding a link summary, but not when encoding it: https://github.com/swiftlang/swift-docc/blob/cfcd96f0e992af2287661f6a26e8398096f6bc1e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L772-L773 https://github.com/swiftlang/swift-docc/blob/cfcd96f0e992af2287661f6a26e8398096f6bc1e/Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift#L728 Both are needed when using an external link resolver, as the external link resolver needs to encode the entity to send to DocC. Fixes rdar://164628218.
1 parent cfcd96f commit 20a0c8b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Sources/SwiftDocC/LinkTargets/LinkDestinationSummary.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ public struct LinkDestinationSummary: Codable, Equatable {
112112
// so that external documentation sources don't need to provide that data.
113113
// Adding new required properties is considered breaking change since existing external documentation sources
114114
// wouldn't necessarily meet these new requirements.
115-
115+
// Make sure to update the encoding, decoding and Equatable implementations when adding new properties.
116+
116117
/// A collection of identifiers that all relate to some common task, as described by the title.
117118
public struct TaskGroup: Codable, Equatable {
118119
/// The title of this task group
@@ -725,7 +726,7 @@ extension LinkDestinationSummary {
725726
} else {
726727
try container.encode(kind, forKey: .kind)
727728
}
728-
try container.encode(relativePresentationURL, forKey: .relativePresentationURL)
729+
try container.encode(absolutePresentationURL ?? relativePresentationURL, forKey: .relativePresentationURL)
729730
try container.encode(referenceURL, forKey: .referenceURL)
730731
try container.encode(title, forKey: .title)
731732
try container.encodeIfPresent(abstract, forKey: .abstract)
@@ -935,12 +936,15 @@ extension LinkDestinationSummary {
935936
guard lhs.kind == rhs.kind else { return false }
936937
guard lhs.language == rhs.language else { return false }
937938
guard lhs.relativePresentationURL == rhs.relativePresentationURL else { return false }
939+
guard lhs.absolutePresentationURL == rhs.absolutePresentationURL else { return false }
938940
guard lhs.title == rhs.title else { return false }
939941
guard lhs.abstract == rhs.abstract else { return false }
940942
guard lhs.availableLanguages == rhs.availableLanguages else { return false }
941943
guard lhs.platforms == rhs.platforms else { return false }
942944
guard lhs.taskGroups == rhs.taskGroups else { return false }
945+
guard lhs.plainTextDeclaration == rhs.plainTextDeclaration else { return false }
943946
guard lhs.subheadingDeclarationFragments == rhs.subheadingDeclarationFragments else { return false }
947+
guard lhs.navigatorDeclarationFragments == rhs.navigatorDeclarationFragments else { return false }
944948
guard lhs.redirects == rhs.redirects else { return false }
945949
guard lhs.topicImages == rhs.topicImages else { return false }
946950
guard lhs.variants == rhs.variants else { return false }

Tests/SwiftDocCTests/Infrastructure/ExternalReferenceResolverTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,10 @@ class ExternalReferenceResolverTests: XCTestCase {
14201420
""".utf8))
14211421
XCTAssertEqual(externalEntity.relativePresentationURL.absoluteString, "/path/to/something")
14221422
XCTAssertEqual(externalEntity.absolutePresentationURL?.absoluteString, "https://com.example/path/to/something")
1423-
1423+
1424+
// Test that encoding the link summary preserves the absolute URL
1425+
try assertRoundTripCoding(externalEntity)
1426+
14241427
let resolver = Resolver(entityToReturn: externalEntity)
14251428

14261429
var configuration = DocumentationContext.Configuration()

0 commit comments

Comments
 (0)