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
17 changes: 17 additions & 0 deletions Sources/CLI/client/AppleDocumentationClient+DTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ struct DocumentationMetadataDTO: Decodable, Sendable {
let roleHeading: String
let symbolKind: String
let title: String

private enum CodingKeys: CodingKey {
case modules
case platforms
case roleHeading
case symbolKind
case title
}

init(from decoder: any Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
modules = try container.decode([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)
title = try container.decode(String.self, forKey: .title)
}
}

struct DocumentationModule: Decodable, Sendable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,39 @@ struct DefaultTypeDocumentationRendererTests {
)
}

@Test("renders text when platform metadata is omitted")
func rendersTextWithoutPlatforms() throws {
// -- Arrange --
let rawJSON = """
{
"abstract": [{"text": "The Swift package manifest representation.", "type": "text"}],
"metadata": {
"modules": [{"name": "PackageDescription"}],
"roleHeading": "Structure",
"symbolKind": "struct",
"title": "Package"
},
"primaryContentSections": [],
"references": {}
}
"""
let document = try makeDocument(rawJSON)
let renderer = DefaultTypeDocumentationRenderer(output: .text)

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

// -- Assert --
#expect(
output == """
Package
Structure · PackageDescription

The Swift package manifest representation.
"""
)
}

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