Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Sources/CLI/client/AppleDocumentationClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ extension DefaultAppleDocumentationClient {
}

private func typeDestination(name: String, technology: String) -> DocumentationDestination {
// Only CLI Swift names use dots as hierarchy separators. Resolved links retain their exact paths.
let components = name.replacingOccurrences(of: ".", with: "/").split(separator: "/")
// Slash-separated DocC paths may contain dots in disambiguation suffixes.
let pathName = name.contains("/") ? name : name.replacingOccurrences(of: ".", with: "/")
let components = pathName.split(separator: "/")
let path = "/documentation/\(technology.lowercased())/" + components.joined(separator: "/").lowercased()
return DocumentationDestination(technology: technology.lowercased(), path: path)
}
Expand Down
23 changes: 23 additions & 0 deletions Tests/CLITests/client/AppleDocumentationClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ struct AppleDocumentationClientTests {
#expect(await transport.requestedURLs == [expectedURL])
}

@Test("preserves disambiguation suffixes in DocC paths")
func preservesDocCPathSuffix() async throws {
// -- Arrange --
let expectedURL = try #require(
URL(
string: "https://developer.apple.com/tutorials/data/documentation/swiftui/griditem/size-swift.enum.json"
)
)
let data = Data("{}".utf8)
let transport = HTTPTestTransport(responses: [expectedURL: .http(data: data)])
let client = DefaultAppleDocumentationClient(
logger: Logger(label: "test") { _ in SwiftLogNoOpLogHandler() },
dependencies: transport
)

// -- Act --
let document = try await client.fetchType(named: "griditem/size-swift.enum", technology: "swiftui")

// -- Assert --
#expect(document.data == data)
#expect(await transport.requestedURLs == [expectedURL])
}

@Test("reports unsuccessful documentation responses")
func reportsHTTPError() async throws {
// -- Arrange --
Expand Down
Loading