diff --git a/Sources/CLI/client/AppleDocumentationClient.swift b/Sources/CLI/client/AppleDocumentationClient.swift index de6ef04..b8ded84 100644 --- a/Sources/CLI/client/AppleDocumentationClient.swift +++ b/Sources/CLI/client/AppleDocumentationClient.swift @@ -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) } diff --git a/Tests/CLITests/client/AppleDocumentationClientTests.swift b/Tests/CLITests/client/AppleDocumentationClientTests.swift index 3c25d81..3c276d1 100644 --- a/Tests/CLITests/client/AppleDocumentationClientTests.swift +++ b/Tests/CLITests/client/AppleDocumentationClientTests.swift @@ -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 --