Skip to content

Commit d6e1217

Browse files
authored
Adding deprecated to @available directive (#851)
Adding deprecated argument to the directive @available and updates documentation to include the new argument
1 parent e0a862c commit d6e1217

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

Sources/SwiftDocC/Model/Rendering/Symbol/AvailabilityRenderMetadataItem.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public struct AvailabilityRenderItem: Codable, Hashable, Equatable {
147147
let platformName = PlatformName(metadataPlatform: availability.platform)
148148
name = platformName?.displayName
149149
introduced = availability.introduced
150+
deprecated = availability.deprecated
150151
}
151152

152153
/// Creates a new item with the given platform name and version string.

Sources/SwiftDocC/Semantics/Metadata/Availability.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ extension Metadata {
1616
///
1717
/// `@Available` is analogous to the `@available` attribute in Swift: It allows you to specify a
1818
/// platform version that the page relates to. To specify a platform and version, list the platform
19-
/// name and use the `introduced` argument:
19+
/// name and use the `introduced` argument. In addition, you can also specify a deprecated
20+
/// version, using the `deprecated` argument:
2021
///
2122
/// ```markdown
2223
/// @Available(macOS, introduced: "12.0")
24+
/// @Available(macOS, introduced: "12.0", deprecated: "14.0")
2325
/// ```
2426
///
2527
/// Any text can be given to the first argument, and will be displayed in the page's
@@ -48,8 +50,6 @@ extension Metadata {
4850
public static let introducedVersion = "5.8"
4951

5052
public enum Platform: RawRepresentable, Hashable, DirectiveArgumentValueConvertible {
51-
// FIXME: re-add `case any = "*"` when `isBeta` and `isDeprecated` are implemented
52-
// cf. https://github.com/apple/swift-docc/issues/441
5353
case macOS, iOS, watchOS, tvOS
5454

5555
case other(String)
@@ -90,16 +90,18 @@ extension Metadata {
9090
@DirectiveArgumentWrapped(name: .unnamed)
9191
public var platform: Platform
9292

93-
/// The platform version that this page applies to.
93+
/// The platform version that this page was introduced in.
9494
@DirectiveArgumentWrapped
9595
public var introduced: String
9696

97-
// FIXME: `isBeta` and `isDeprecated` properties/arguments
98-
// cf. https://github.com/apple/swift-docc/issues/441
97+
/// The platform version that this page was deprecated in.
98+
@DirectiveArgumentWrapped
99+
public var deprecated: String? = nil
99100

100101
static var keyPaths: [String : AnyKeyPath] = [
101102
"platform" : \Availability._platform,
102103
"introduced" : \Availability._introduced,
104+
"deprecated" : \Availability._deprecated,
103105
]
104106

105107
public let originalMarkup: Markdown.BlockDirective

Tests/SwiftDocCTests/Semantics/MetadataAvailabilityTests.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,7 @@ class MetadataAvailabilityTests: XCTestCase {
6363
func testValidDirective() throws {
6464
// assemble all the combinations of arguments you could give
6565
let validArguments: [String] = [
66-
// FIXME: isBeta and isDeprecated are unused (https://github.com/apple/swift-docc/issues/441)
67-
// "isBeta: true",
68-
// "isDeprecated: true",
69-
// "isBeta: true, isDeprecated: true",
66+
"deprecated: \"1.0\"",
7067
]
7168
// separate those that give a version so we can test the `*` platform separately
7269
var validArgumentsWithVersion = ["introduced: \"1.0\""]
@@ -90,17 +87,12 @@ class MetadataAvailabilityTests: XCTestCase {
9087
try assertValidAvailability(source: "@Available(\"My Package\", \(args))")
9188
}
9289

93-
// also test for giving no platform
94-
for args in validArguments {
95-
try assertValidAvailability(source: "@Available(\(args))")
96-
}
97-
98-
// basic validity test for giving several directives
99-
// FIXME: re-add isBeta after that is implemented (https://github.com/apple/swift-docc/issues/441)
10090
let source = """
10191
@Metadata {
10292
@Available(macOS, introduced: "11.0")
10393
@Available(iOS, introduced: "15.0")
94+
@Available(watchOS, introduced: "7.0", deprecated: "9.0")
95+
@Available("My Package", introduced: "0.1", deprecated: "1.0")
10496
}
10597
"""
10698
try assertValidMetadata(source: source)

0 commit comments

Comments
 (0)