Skip to content

Commit 864453f

Browse files
Don't display beta tags for symbols with availability items without introduced version. (#1086)
Don't display beta tags for symbols with availability items without introduced version. This change makes symbols without introduced versions but with deprecated versions to be marked as `beta`. Before this change a symbol with availability items without introduced versions were being marked as beta. rdar://139245007
1 parent 5a690ce commit 864453f

File tree

3 files changed

+80
-21
lines changed

3 files changed

+80
-21
lines changed

Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public class DocumentationContentRenderer {
206206
}
207207

208208
/// Given a node, returns if it's a beta documentation symbol or not.
209+
///
210+
/// Symbols are only considered "in beta" if they are in beta for all platforms that they are available for.
209211
func isBeta(_ node: DocumentationNode) -> Bool {
210212
// We verify that this is a symbol with defined availability
211213
// and that we're feeding in a current set of platforms to the context.
@@ -219,9 +221,14 @@ public class DocumentationContentRenderer {
219221
// Verify that if current platforms are in beta, they match the introduced version of the symbol
220222
for availability in symbolAvailability {
221223
// If not available on this platform, skip to next platform.
222-
guard !availability.isUnconditionallyUnavailable, let introduced = availability.introducedVersion else {
224+
guard !availability.isUnconditionallyUnavailable else {
223225
continue
224226
}
227+
228+
// If the symbol doesn't have an introduced version for one of those platforms, we don't consider it "in beta".
229+
guard let introduced = availability.introducedVersion else {
230+
return false
231+
}
225232

226233
// If we don't have introduced and current versions for the current platform
227234
// we can't tell if the symbol is beta.

Tests/SwiftDocCTests/Model/SemaToRenderNodeTests.swift

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,19 +1913,24 @@ Document
19131913
}
19141914

19151915
func testRendersBetaViolators() throws {
1916-
func makeTestBundle(currentPlatforms: [String : PlatformVersion]?, file: StaticString = #file, line: UInt = #line) throws -> (DocumentationBundle, DocumentationContext, ResolvedTopicReference) {
1916+
func makeTestBundle(currentPlatforms: [String : PlatformVersion]?, file: StaticString = #file, line: UInt = #line, referencePath: String) throws -> (DocumentationBundle, DocumentationContext, ResolvedTopicReference) {
19171917
var configuration = DocumentationContext.Configuration()
1918+
// Add missing platforms if their fallback platform is present.
1919+
var currentPlatforms = currentPlatforms ?? [:]
1920+
for (platform, fallbackPlatform) in DefaultAvailability.fallbackPlatforms where currentPlatforms[platform.displayName] == nil {
1921+
currentPlatforms[platform.displayName] = currentPlatforms[fallbackPlatform.displayName]
1922+
}
19181923
configuration.externalMetadata.currentPlatforms = currentPlatforms
19191924

19201925
let (_, bundle, context) = try testBundleAndContext(named: "TestBundle", configuration: configuration)
19211926

1922-
let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: "/documentation/MyKit/MyClass", sourceLanguage: .swift)
1927+
let reference = ResolvedTopicReference(bundleIdentifier: bundle.identifier, path: referencePath, sourceLanguage: .swift)
19231928
return (bundle, context, reference)
19241929
}
19251930

19261931
// Not a beta platform
19271932
do {
1928-
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: nil)
1933+
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: nil, referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19291934

19301935
let node = try context.entity(with: reference)
19311936
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
@@ -1940,7 +1945,7 @@ Document
19401945

19411946
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
19421947
"Custom Name": PlatformVersion(VersionTriplet(100, 0, 0), beta: true)
1943-
])
1948+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19441949
let node = try context.entity(with: reference)
19451950
(node.semantic as? Symbol)?.availability = SymbolGraph.Symbol.Availability(availability: [])
19461951
let documentationContentRendered = DocumentationContentRenderer(documentationContext: context, bundle: bundle)
@@ -1953,7 +1958,7 @@ Document
19531958
do {
19541959
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
19551960
"tvOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true)
1956-
])
1961+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19571962

19581963
let node = try context.entity(with: reference)
19591964
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
@@ -1967,7 +1972,7 @@ Document
19671972
do {
19681973
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
19691974
"macOS": PlatformVersion(VersionTriplet(100, 0, 0), beta: true)
1970-
])
1975+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19711976

19721977
let node = try context.entity(with: reference)
19731978
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
@@ -1981,21 +1986,21 @@ Document
19811986
do {
19821987
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
19831988
"macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true)
1984-
])
1989+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19851990

19861991
let node = try context.entity(with: reference)
19871992
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
19881993

19891994
// Verify platform beta was plumbed all the way to the render JSON
1990-
XCTAssertEqual(renderNode.metadata.platforms?.first(where: { $0.name == "macOS" })?.isBeta, true)
1995+
XCTAssertEqual(renderNode.metadata.platforms?.first(where: { $0.name == "macOS"})?.isBeta, true)
19911996
}
19921997

19931998
// Beta platform earlier than the introduced version
19941999

19952000
do {
19962001
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
19972002
"macOS": PlatformVersion(VersionTriplet(10, 14, 0), beta: true)
1998-
])
2003+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
19992004

20002005
let node = try context.entity(with: reference)
20012006
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
@@ -2004,36 +2009,36 @@ Document
20042009
XCTAssertEqual(renderNode.metadata.platforms?.first(where: { $0.name == "macOS" })?.isBeta, true)
20052010
}
20062011

2007-
// Set only some platforms to beta & the exact version MyClass is being introduced at
2012+
// Set only some platforms to beta & the exact version globalFunction is being introduced at
20082013

20092014
do {
20102015
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
20112016
"macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true),
20122017
"watchOS": PlatformVersion(VersionTriplet(9, 0, 0), beta: true),
20132018
"tvOS": PlatformVersion(VersionTriplet(1, 0, 0), beta: true),
2014-
])
2019+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
20152020

20162021
let node = try context.entity(with: reference)
20172022
let renderNode = try DocumentationNodeConverter(bundle: bundle, context: context).convert(node)
20182023

2019-
// Verify task group link is beta
2020-
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, false)
2024+
// Verify task group link is not in beta betas "iOS" is not being marked as beta
2025+
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, false)
20212026
}
20222027

2023-
// Set all platforms to beta & the exact version MyClass is being introduced at to test beta SDK documentation
2028+
// Set all platforms to beta & the exact version globalFunction is being introduced at to test beta SDK documentation
20242029
do {
20252030
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
20262031
"macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true),
20272032
"watchOS": PlatformVersion(VersionTriplet(6, 0, 0), beta: true),
20282033
"tvOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true),
2029-
"iOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true),
2030-
])
2034+
"iOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true)
2035+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
20312036

20322037
let node = try context.entity(with: reference)
20332038
let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node))
20342039

20352040
// Verify task group link is beta
2036-
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, true)
2041+
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true)
20372042
}
20382043

20392044
// Set all platforms to beta where the symbol is available,
@@ -2045,13 +2050,13 @@ Document
20452050
"iOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true),
20462051
"FictionalOS": PlatformVersion(VersionTriplet(42, 0, 0), beta: false),
20472052
"ImaginaryOS": PlatformVersion(VersionTriplet(3, 3, 3), beta: false),
2048-
])
2053+
], referencePath: "/documentation/MyKit/globalFunction(_:considering:)")
20492054

20502055
let node = try context.entity(with: reference)
20512056
let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node))
20522057

20532058
// Verify task group link is beta
2054-
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, true)
2059+
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true)
20552060

20562061
// Add ImaginaryOS platform - but make it unconditionally unavailable and
20572062
// verify that it doesn't affect the beta status
@@ -2064,7 +2069,24 @@ Document
20642069
let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node))
20652070

20662071
// Verify task group link is beta
2067-
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, true)
2072+
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/globalFunction(_:considering:)"] as? TopicRenderReference)?.isBeta, true)
2073+
}
2074+
2075+
// Set all platforms to beta & the exact version MyClass is being introduced.
2076+
// Expect the symbol to no be in beta sinceit does not have an introduced version for iOS
2077+
do {
2078+
let (bundle, context, reference) = try makeTestBundle(currentPlatforms: [
2079+
"macOS": PlatformVersion(VersionTriplet(10, 15, 0), beta: true),
2080+
"watchOS": PlatformVersion(VersionTriplet(6, 0, 0), beta: true),
2081+
"tvOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true),
2082+
"iOS": PlatformVersion(VersionTriplet(13, 0, 0), beta: true)
2083+
], referencePath: "/documentation/MyKit")
2084+
2085+
let node = try context.entity(with: reference)
2086+
let renderNode = try XCTUnwrap(DocumentationNodeConverter(bundle: bundle, context: context).convert(node))
2087+
2088+
// Verify task group link is not in beta because `iOS` does not have an introduced version
2089+
XCTAssertEqual((renderNode.references["doc://org.swift.docc.example/documentation/MyKit/MyClass"] as? TopicRenderReference)?.isBeta, false)
20682090
}
20692091
}
20702092

Tests/SwiftDocCTests/Test Bundles/TestBundle.docc/mykit-iOS.symbols.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,36 @@
409409
],
410410
"title" : "globalFunction(_:considering:)"
411411
},
412+
"availability" : [
413+
{
414+
"domain": "macOS",
415+
"introduced": {
416+
"major": 10,
417+
"minor": 15
418+
}
419+
},
420+
{
421+
"domain": "watchOS",
422+
"introduced": {
423+
"major": 6,
424+
"minor": 0
425+
}
426+
},
427+
{
428+
"domain": "tvOS",
429+
"introduced": {
430+
"major": 13,
431+
"minor": 0
432+
}
433+
},
434+
{
435+
"domain": "iOS",
436+
"introduced": {
437+
"major": 13,
438+
"minor": 0
439+
}
440+
}
441+
],
412442
"pathComponents" : [
413443
"globalFunction(_:considering:)"
414444
]

0 commit comments

Comments
 (0)