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
6 changes: 3 additions & 3 deletions Sources/CLI/client/AppleDocumentationClient+DTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct DocumentationMetadataDTO: Decodable, Sendable {
let modules: [DocumentationModule]
let platforms: [DocumentationPlatform]
let roleHeading: String
let symbolKind: String
let symbolKind: String?
let title: String

private enum CodingKeys: CodingKey {
Expand All @@ -124,10 +124,10 @@ struct DocumentationMetadataDTO: Decodable, Sendable {

init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
modules = try container.decode([DocumentationModule].self, forKey: .modules)
modules = try container.decodeIfPresent([DocumentationModule].self, forKey: .modules) ?? []
platforms = try container.decodeIfPresent([DocumentationPlatform].self, forKey: .platforms) ?? []
roleHeading = try container.decode(String.self, forKey: .roleHeading)
symbolKind = try container.decode(String.self, forKey: .symbolKind)
symbolKind = try container.decodeIfPresent(String.self, forKey: .symbolKind)
title = try container.decode(String.self, forKey: .title)
}
}
Expand Down
9 changes: 5 additions & 4 deletions Sources/CLI/renderer/TextTypeDocumentationRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ struct TextTypeDocumentationRenderer: Sendable {
let content = DocumentationContentRenderer(references: page.references)
let metadata = ([page.metadata.roleHeading] + page.metadata.modules.map(\.name))
.filter { !$0.isEmpty }.joined(separator: " · ")
var sections = [
layout.heading(page.metadata.title, prominent: true) + "\n" + metadata
+ "\nSymbol kind: " + page.metadata.symbolKind
]
var header = layout.heading(page.metadata.title, prominent: true) + "\n" + metadata
if let symbolKind = page.metadata.symbolKind {
header += "\nSymbol kind: " + symbolKind
}
var sections = [header]

let abstract = content.inlineText(page.abstract)
if !abstract.isEmpty {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,46 @@ struct DefaultTypeDocumentationRendererTests {
)
}

@Test("renders articles without module or symbol metadata")
func rendersArticleWithoutSymbolMetadata() throws {
// -- Arrange --
let rawJSON = """
{
"kind": "article",
"abstract": [{"text": "Distribute binaries in Swift packages.", "type": "text"}],
"metadata": {
"role": "article",
"roleHeading": "Article",
"title": "Distributing binary frameworks as Swift packages"
},
"primaryContentSections": [{
"kind": "content",
"content": [
{"type": "heading", "level": 2, "text": "Overview"},
{
"type": "paragraph",
"inlineContent": [{"type": "text", "text": "Create an XCFramework bundle."}]
}
]
}],
"references": {}
}
"""
let document = try makeDocument(rawJSON)
let renderer = DefaultTypeDocumentationRenderer(output: .text)

// -- Act --
let output = try renderer.render(document)

// -- Assert --
#expect(output.hasPrefix("Distributing binary frameworks as Swift packages\n"))
#expect(output.contains("\nArticle\n\n Distribute binaries in Swift packages."))
#expect(output.contains("Overview\n────────\n\n Create an XCFramework bundle."))
#expect(!output.contains("Symbol kind:"))
#expect(!output.contains("Availability"))
#expect(!output.contains("Declaration"))
}

@Test("returns Apple's DocC JSON unchanged")
func rendersRawJSON() throws {
// -- Arrange --
Expand Down
Loading