Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - SwiftDocOrg/swift-doc: A documentation generator for Swift projects · GitHub
Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

swift-doc

CI

A package for generating documentation for Swift projects.

Given a directory of Swift files, swift-doc generates HTML or CommonMark (Markdown) files for each class, structure, enumeration, and protocol as well as top-level type aliases, functions, and variables.

Example Output

Requirements

Command-Line Utility

swift-doc can be used from the command-line on macOS and Linux.

Installation

Homebrew

Run the following command to install using Homebrew:

$ brew install swiftdocorg/formulae/swift-doc

If you already have swift-doc installed, run the following command to upgrade your installation:

$ brew upgrade swift-doc

If installing or upgrading fails with the message Error: Failed to download resource "swift-doc", try resetting your installation with the following commands:

$ brew uninstall swift-doc
$ brew untap swiftdocorg/formulae
$ brew install swiftdocorg/formulae/swift-doc

Docker

You can run swift-doc from the latest Docker image with the following commands:

$ docker pull swiftdoc/swift-doc:latest
$ docker run -it swiftdoc/swift-doc

Manually

Run the following commands to build and install manually:

$ git clone https://github.com/SwiftDocOrg/swift-doc
$ cd swift-doc
$ make install

If you're on Ubuntu Linux, you may need to first install the prerequisites by running the following command:

$ apt-get update
$ apt-get install -y libxml2-dev graphviz

Usage

OVERVIEW: A utility for generating documentation for Swift code.
USAGE: swift doc <subcommand>
OPTIONS:
--version Show the version.
-h, --help Show help information.
SUBCOMMANDS:
generate Generates Swift documentation
coverage Generates documentation coverage statistics for Swift
files
diagram Generates diagram of Swift symbol relationships

Note: The swift driver provides extensibility through subcommands. If you type an unknown subcommand like swift foo, the system looks for a command called swift-foo in your PATH. This mechanism allows swift-doc to be run either directly or as swift doc.

swift-doc generate

OVERVIEW: Generates Swift documentation
USAGE: swift doc generate [<inputs> ...] --module-name <module-name> [--output <output>] [--format <format>] [--base-url <base-url>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files. OPTIONS:
-n, --module-name <module-name>
The name of the module -o, --output <output> The path for generated output (default:
.build/documentation)
-f, --format <format> The output format (default: commonmark)
--base-url <base-url> The base URL used for all relative URLs in generated
documents. (default: /)
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The generate subcommand takes one or more paths and enumerates them recursively, collecting all Swift files into a single "module" and generating documentation accordingly. Any hidden directories are skipped, including .git and other directories with paths starting with a dot (.). Top-level Tests directories are skipped as well.

$ swift doc generate path/to/SwiftProject --module-name SwiftProject
$ tree .build/documentation
$ documentation/
├── Home
├── (...)
├── _Footer.md
└── _Sidebar.md

By default, output files are written to .build/documentation in CommonMark / GitHub Wiki format, but you can change that with the --output and --format option flags.

$ swift doc generate path/to/SwiftProject/Sources --module-name SwiftProject --output Documentation --format html
$ Documentation/
├── (...)
└── index.html

By default, swift-doc includes only symbols declared as public or open in the generated documentation. To include internal or private declarations, pass the --minimum-access-level flag with the specified access level.

swift-doc coverage

OVERVIEW: Generates documentation coverage statistics for Swift files
USAGE: swift doc coverage [<inputs> ...] [--output <output>]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
-o, --output <output> The path for generated report --minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The coverage subcommand generates documentation coverage statistics for Swift files.

$ git clone https://github.com/SwiftDocOrg/SwiftSemantics.git
$ swift run swift-doc coverage SwiftSemantics/Sources --output "dcov.json"
$ cat dcov.json | jq ".data.totals"
{
"count": 207,
"documented": 199,
"percent": 96.1352657004831
}
$ cat dcov.json | jq ".data.symbols[] | select(.documented == false)"
{
"file": "SwiftSemantics/Supporting Types/GenericRequirement.swift",
"line": 67,
"column": 6,
"name": "GenericRequirement.init?(_:)",
"type": "Initializer",
"documented": false
}
...

While there are plenty of tools for assessing test coverage for code, we weren't able to find anything analogous for documentation coverage. To this end, we've contrived a simple JSON format inspired by llvm-cov.

If you know of an existing standard that you think might be better suited for this purpose, please reach out by opening an Issue!

swift-doc diagram

OVERVIEW: Generates diagram of Swift symbol relationships
USAGE: swift doc diagram [<inputs> ...]
ARGUMENTS:
<inputs> One or more paths to a directory containing Swift files.
OPTIONS:
--minimum-access-level <minimum-access-level>
The minimum access level of the symbols which should
be included. (default: public)
-h, --help Show help information.

The diagram subcommand generates a graph of APIs in DOT format that can be rendered by GraphViz into a diagram.

$ swift run swift-doc diagram Alamofire/Source > Alamofire.gv
$ head Alamofire.gv
digraph Anonymous {
"Session" [shape=box];
"NetworkReachabilityManager" [shape=box];
"URLEncodedFormEncoder" [shape=box,peripheries=2];
"ServerTrustManager" [shape=box];
"MultipartFormData" [shape=box];
subgraph cluster_Request {
"DataRequest" [shape=box];
"Request" [shape=box];
$ dot -T svg Alamofire.gv > Alamofire.svg

Here's an excerpt of the graph generated for Alamofire:

Excerpt of swift-doc-api Diagram for Alamofire

GitHub Action

This repository also hosts a GitHub Action that you can incorporate into your project's workflow.

The CommonMark files generated by swift-doc are formatted for publication to your project's GitHub Wiki, which you can do with github-wiki-publish-action. Alternatively, you could specify HTML format to publish documentation to GitHub Pages or bundle them into a release artifact.

Inputs

  • inputs: A path to a directory containing Swift (.swift) files in your workspace. (Default: "./Sources")
  • format: The output format ("commonmark" or "html") (Default: "commonmark")
  • module-name: The name of the module.
  • base-url: The base URL for all relative URLs generated in documents. (Default: "/")
  • output: The path for generated output. (Default: "./.build/documentation")

Example Workflow

# .github/workflows/documentation.ymlname: Documentationon: [push]jobs:
build:
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v1
- name: Generate Documentationuses: SwiftDocOrg/swift-doc@masterwith:
inputs: "Sources"module-name: MyLibraryoutput: "Documentation"
- name: Upload Documentation to Wikiuses: SwiftDocOrg/github-wiki-publish-action@v1with:
path: "Documentation"env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}

Development

Web Assets

CSS assets used by the HTML output format are processed and generated by PostCSS. To make changes to these assets, you'll need to have Node.js and a package manager, such as npm, installed on your machine.

Navigate to the .node directory and run npm install to download the required tools and libraries.

$ cd .node
$ npm install

Note: package.json is located at a hidden .node subdirectory to prevent Xcode from displaying or indexing the contents of node_modules when opening the main project.

From the .node directory, run the watch script to start watching for changes to files in the Assets folder. Whenever an asset source file is added, removed, or updated, its corresponding (unoptimized) product is automatically generated in the Sources/swift-doc/Generated folder.

$ npm run watch

When you're happy with the results, commit any changes to the source files in Assets as well as the generated files in Sources/swift-doc/Generated.

$ git add Assets Sources/swift-doc/Generated
$ git commit

Release Process

The following information is primarily for the benefit of project maintainers. That said, if you have any suggestions for how to improve this process, please let us know by opening an issue.

Follow these steps to release a new version of swift-doc:

  • Verify that the latest commit passed all CI checks.
  • Update the Changelog by creating a new heading for the release and modifying the last path component for the unreleased link reference.
  • Update the version constant in the command-line executable.
  • Create a new commit with the message "Bump version to $VERSION", where $VERSION is a SemVer-compatible version number.
  • Tag that commit with the tag name "$VERSION"
  • Run the command git push origin master --tags
  • Create a new release that corresponds to the new tag.

Known Issues

  • Xcode cannot run unit tests (U) when opening the swift-doc package directly, as opposed first to generating an Xcode project file with swift package generate-xcodeproj. (The reported error is: Library not loaded: @rpath/lib_InternalSwiftSyntaxParser.dylib). As a workaround, you can install the latest toolchain and enable it in "Xcode > Preferences > Components > Toolchains". Alternatively, you can run unit tests from the command line with swift test.

License

MIT

Contact

Mattt (@mattt)

About

A documentation generator for Swift projects

Topics

Resources

Stars

1.7k stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages