From 250486a31e824b7f01b9267452569ade2b9c4235 Mon Sep 17 00:00:00 2001 From: Pat Shaughnessy Date: Thu, 6 Nov 2025 16:58:25 -0800 Subject: [PATCH 1/3] Add a public initializer to RenderContentMetadata --- .../Content/RenderContentMetadata.swift | 9 ++++++ ...enderContentMetadataInitializerTests.swift | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift diff --git a/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift b/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift index 90da0dbd36..42e9a054b7 100644 --- a/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift +++ b/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift @@ -20,6 +20,15 @@ public struct RenderContentMetadata: Equatable, Codable { public var abstract: [RenderInlineContent]? /// An optional identifier for the device frame that should wrap this element. public var deviceFrame: String? + + /// Declare a public initializer, to allow clients linking to Swift DocC to + /// create RenderContentMetadata values. + public init(anchor: String? = nil, title: String? = nil, abstract: [RenderInlineContent]? = nil, deviceFrame: String? = nil) { + self.anchor = anchor + self.title = title + self.abstract = abstract + self.deviceFrame = deviceFrame + } } extension RenderContentMetadata { diff --git a/Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift b/Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift new file mode 100644 index 0000000000..1200249003 --- /dev/null +++ b/Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift @@ -0,0 +1,31 @@ +/* + This source file is part of the Swift.org open source project + + Copyright (c) 2025 Apple Inc. and the Swift project authors + Licensed under Apache License v2.0 with Runtime Library Exception + + See https://swift.org/LICENSE.txt for license information + See https://swift.org/CONTRIBUTORS.txt for Swift project authors +*/ + +// Import SwiftDocC without the @testable annotation, so we can test there +// is a public initializer for RenderContentMetadata. +import SwiftDocC +import XCTest + +class RenderContentMetadataInitializerTests: XCTestCase { + func testMetadataPublicInitializer() throws { + let metadata = RenderContentMetadata( + anchor: "anchor", + title: "title", + abstract: [], + deviceFrame: "device frame" + ) + + XCTAssertNotNil(metadata) + XCTAssertEqual("anchor", metadata.anchor) + XCTAssertEqual("title", metadata.title) + XCTAssertEqual([], metadata.abstract) + XCTAssertEqual("device frame", metadata.deviceFrame) + } +} From ef6322983f0ebdcff382379024eb43f647d64c25 Mon Sep 17 00:00:00 2001 From: Pat Shaughnessy Date: Fri, 7 Nov 2025 10:22:18 -0800 Subject: [PATCH 2/3] Update Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: David Rönnqvist --- .../Model/Rendering/Content/RenderContentMetadata.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift b/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift index 42e9a054b7..657276a0a1 100644 --- a/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift +++ b/Sources/SwiftDocC/Model/Rendering/Content/RenderContentMetadata.swift @@ -21,8 +21,12 @@ public struct RenderContentMetadata: Equatable, Codable { /// An optional identifier for the device frame that should wrap this element. public var deviceFrame: String? - /// Declare a public initializer, to allow clients linking to Swift DocC to - /// create RenderContentMetadata values. + /// Creates a new metadata value for a content element. + /// - Parameters: + /// - anchor: The named anchor of the content element. + /// - title: The customized title for the content element. + /// - abstract: The customized abstract for the content element. + /// - deviceFrame: The identifier for the device frame that should wrap the content element. public init(anchor: String? = nil, title: String? = nil, abstract: [RenderInlineContent]? = nil, deviceFrame: String? = nil) { self.anchor = anchor self.title = title From c587ac9de4a1215acc24c8c1ea61128e2843733c Mon Sep 17 00:00:00 2001 From: Pat Shaughnessy Date: Fri, 7 Nov 2025 10:44:38 -0800 Subject: [PATCH 3/3] Introduce PublicAPITests for verifying certain API are actually public. --- .../PublicAPITests.swift} | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) rename Tests/SwiftDocCTests/{Model/RenderContentMetadataInitializerTests.swift => PublicAPI/PublicAPITests.swift} (55%) diff --git a/Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift b/Tests/SwiftDocCTests/PublicAPI/PublicAPITests.swift similarity index 55% rename from Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift rename to Tests/SwiftDocCTests/PublicAPI/PublicAPITests.swift index 1200249003..0da80607c9 100644 --- a/Tests/SwiftDocCTests/Model/RenderContentMetadataInitializerTests.swift +++ b/Tests/SwiftDocCTests/PublicAPI/PublicAPITests.swift @@ -8,24 +8,20 @@ See https://swift.org/CONTRIBUTORS.txt for Swift project authors */ -// Import SwiftDocC without the @testable annotation, so we can test there -// is a public initializer for RenderContentMetadata. +// Import SwiftDocC without the @testable annotation, so we can test +// whether various API are actually public. import SwiftDocC + import XCTest -class RenderContentMetadataInitializerTests: XCTestCase { - func testMetadataPublicInitializer() throws { - let metadata = RenderContentMetadata( +class PublicAPITests: XCTestCase { + + func testPublicRenderContentMetadataInitializer() throws { + let _ = RenderContentMetadata( anchor: "anchor", title: "title", abstract: [], deviceFrame: "device frame" ) - - XCTAssertNotNil(metadata) - XCTAssertEqual("anchor", metadata.anchor) - XCTAssertEqual("title", metadata.title) - XCTAssertEqual([], metadata.abstract) - XCTAssertEqual("device frame", metadata.deviceFrame) } }