Skip to content

Commit 8cddd57

Browse files
authored
Available directive docs (#990)
1 parent 320410f commit 8cddd57

File tree

4 files changed

+244
-75
lines changed

4 files changed

+244
-75
lines changed

Sources/SwiftDocC/Semantics/Metadata/Availability.swift

+27-39
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2022-2023 Apple Inc. and the Swift project authors
4+
Copyright (c) 2022-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -12,50 +12,38 @@ import Foundation
1212
import Markdown
1313

1414
extension Metadata {
15-
/// A directive that sets the platform availability information for a documentation page.
15+
/// A directive that specifies when a documentation page is available for a given platform.
1616
///
17-
/// `@Available` is analogous to the `@available` attribute in Swift: It allows you to specify a
18-
/// platform version that the page relates to. To specify a platform and version, list the platform
19-
/// name and use the `introduced` argument. In addition, you can also specify a deprecated
20-
/// version, using the `deprecated` argument:
17+
/// Whenever possible, prefer to specify availability information using in-source annotations such as the `@available` attribute in Swift or the `API_AVAILABLE` macro in Objective-C.
18+
/// Using in-source annotations ensures that your documentation matches the availability of your API.
19+
/// If you duplicate availability information in the documentation markup, the information from the `@Available` directive overrides the information for the in-source annotations from that platform and risks being inaccurate.
2120
///
22-
/// ```markdown
23-
/// @Available(macOS, introduced: "12.0")
24-
/// @Available(macOS, introduced: "12.0", deprecated: "14.0")
25-
/// ```
26-
///
27-
/// Any text can be given to the first argument, and will be displayed in the page's
28-
/// availability data. The platforms `iOS`, `macOS`, `watchOS`, and `tvOS` will be matched
29-
/// case-insensitively, but anything else will be printed verbatim.
30-
///
31-
/// To provide a platform name with spaces in it, provide it as a quoted string:
32-
///
33-
/// ```markdown
34-
/// @Available("My Package", introduced: "1.0")
35-
/// ```
36-
///
37-
/// Only strings which are valid semantic version numbers may be passed to the `introduced` and `deprecated` arguments. Specifying an incomplete version number is allowed, as long as all components of the version are valid numbers:
21+
/// If your source language doesn't have a mechanism for specifying API availability or if you're writing articles about a newly introduced or deprecated API,
22+
/// you can use the `@Available` directive to specify when you introduced, and optionally deprecated, an API or documentation page for a given platform.
3823
///
39-
/// ```markdown
40-
/// @Available("My Package", introduced: "1.0.0")
41-
/// @Available("My Package", introduced: "1.0")
42-
/// @Available("My Package", introduced: "1")
43-
/// @Available("My Package", introduced: "1.0.0", deprecated: "2.3.2")
44-
/// ```
45-
///
46-
/// If an invalid semantic version number is provided, a compiler warning will be issued and the directive will be ignored.
47-
///
48-
/// This directive is available on both articles and documentation extension files. In extension
49-
/// files, the information overrides any information from the symbol itself.
50-
///
51-
/// This directive is only valid within a ``Metadata`` directive:
24+
/// Each `@Available` directive specifies the availability information for a single platform.
25+
/// The directive matches the `iOS`, `macOS`, `watchOS`, and `tvOS` platform names case-insensitively.
26+
/// Any other platform names are displayed verbatim.
27+
/// If a platform name contains whitespace, commas, or other special characters you need to surround it with quotation marks (`"`).
5228
///
5329
/// ```markdown
5430
/// @Metadata {
55-
/// @Available(macOS, introduced: "12.0")
5631
/// @Available(iOS, introduced: "15.0")
32+
/// @Available(macOS, introduced: "12.0", deprecated: "14.0")
33+
/// @Available("My Package", introduced: "1.2.3")
5734
/// }
5835
/// ```
36+
///
37+
/// Both the "introduced" and "deprecated" parameters take string representations of semantic version numbers (major`.`minor`.`patch).
38+
/// If you omit the "patch" or "minor" components, they are assumed to be `0`.
39+
/// This means that `"1.0.0"`, `"1.0"`, and `"1"` all specify the same semantic version.
40+
///
41+
/// > Earlier Versions:
42+
/// > Before Swift-DocC 6.0, the `@Available` directive didn't support the "deprecated" parameter.
43+
///
44+
/// > Tip:
45+
/// > In addition to specifying the version when you deprecated an API or documentation page,
46+
/// > you can use the ``DeprecationSummary`` directive to provide the reader with additional information about the deprecation or refer them to a replacement API.
5947
public final class Availability: Semantic, AutomaticDirectiveConvertible {
6048
public static let directiveName: String = "Available"
6149
public static let introducedVersion = "5.8"
@@ -97,15 +85,15 @@ extension Metadata {
9785
}
9886
}
9987

100-
/// The platform that this argument's information applies to.
88+
/// The platform name that this version information applies to.
10189
@DirectiveArgumentWrapped(name: .unnamed)
10290
public var platform: Platform
10391

104-
/// The platform version that this page was introduced in.
92+
/// The semantic version (major`.`minor`.`patch) when you introduced this API or documentation page.
10593
@DirectiveArgumentWrapped
10694
public var introduced: SemanticVersion
10795

108-
/// The platform version that this page was deprecated in.
96+
/// The semantic version (major`.`minor`.`patch) when you deprecated this API or documentation page.
10997
@DirectiveArgumentWrapped
11098
public var deprecated: SemanticVersion? = nil
11199

Sources/SwiftDocC/Semantics/Symbol/DeprecationSummary.swift

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2023 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -11,7 +11,24 @@
1111
import Foundation
1212
import Markdown
1313

14-
/// A directive to add custom deprecation summary to an already deprecated symbol.
14+
/// A directive that specifies a custom deprecation summary message to an already deprecated symbol.
15+
///
16+
/// Many in-source deprecation annotations—such as the `@available` attribute in Swift—allow you to specify a plain text deprecation message.
17+
/// You can use the `@DeprecationSummary` directive to override that deprecation message with one or more paragraphs of formatted documentation markup.
18+
/// For example,
19+
///
20+
/// ```md
21+
/// @DeprecationSummary {
22+
/// This method is unsafe because it could potentially cause buffer overruns.
23+
/// Use ``getBytes(_:length:)`` or ``getBytes(_:range:)`` instead.
24+
/// }
25+
/// ```
26+
///
27+
/// You can use the `@DeprecationSummary` directive top-level in both articles and documentation extension files.
28+
///
29+
/// > Tip:
30+
/// > If you are writing a custom deprecation summary message for an API or documentation page that isn't already deprecated,
31+
/// > you should also deprecate it—using in-source annotations when possible or ``Available`` directives when in-source annotations aren't available—so that the reader knows the version when you deprecated that API or documentation page.
1532
public final class DeprecationSummary: Semantic, AutomaticDirectiveConvertible {
1633
public static let introducedVersion = "5.5"
1734
public let originalMarkup: BlockDirective
@@ -28,8 +45,6 @@ public final class DeprecationSummary: Semantic, AutomaticDirectiveConvertible {
2845
"content" : \DeprecationSummary._content
2946
]
3047

31-
static var hiddenFromDocumentation = true
32-
3348
/// Creates a new deprecation summary from the content of the given directive.
3449
/// - Parameters:
3550
/// - originalMarkup: The source markup as a directive.

0 commit comments

Comments
 (0)