Introduction
With DocC now included in the Swift toolchain alongside SwiftPM, we have an opportunity to create tighter integration between these tools and streamline the documentation experience for Swift developers. This integration can remove friction from documentation generation and make high-quality API documentation accessible to the entire Swift ecosystem.
Motivation
Most SwiftPM packages today lack accessible documentation generation, creating a barrier for both package authors and consumers. While the underlying capability exists to automatically generate symbol graphs and produce polished HTML documentation for Swift libraries, accessing this functionality requires significant manual effort. Developers must add the DocC plugin to their package, configure command-line arguments for the sandbox environment, and understand the package's target structure well enough to specify the correct products and targets.
This complexity means that many valuable Swift packages remain undocumented, and developers exploring new packages often struggle to understand their APIs and capabilities. Swift developers should be able to generate comprehensive documentation for any package with a single command, regardless of their familiarity with plugin infrastructure or target configurations. This documentation can serve as both an entry point for understanding a package's capabilities and a solid foundation for building more comprehensive documentation over time.
The current friction particularly impacts newcomers to the Swift ecosystem and maintainers of smaller packages who may not have the time or expertise to navigate the current documentation setup process.
Proposal
Introduce a first-class SwiftPM command: swift package generate-documentation. This command automatically generates DocC archives in HTML for all package products and intelligently merges them into a unified, package-level archive that provides a cohesive browsing experience. The command handles the complexity of target discovery, symbol graph generation, and archive merging behind the scenes, requiring no configuration for basic use cases.
Here's the resulting interface that developers and package users would see:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π MyAwesomePackage Documentation π Search β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Navigator β β Content Area β β
β β β β β β
β β βΌ MyAwesome β β # Package β β
β β Package β β ## MyAwesomePackage β β
β β ββ Networking β β β β
β β ββ Utilities β β A comprehensive Swift package for building awesome β β
β β ββ UI β β applications with networking, utilities, and UI β β
β β ββ Core β β components. β β
β β β β β β
β β β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β β β π β β π§ β β π¨ β β β
β β β β β Networking β β Utilities β β UI β β β
β β β β β β β β β β β β
β β β β β HTTP client β β Extensions β β UI β β β
β β β β β and helpers β β and helpers β β components β β β
β β β β β β β β β β β β
β β β β β \[View β\] β β \[View β\] β β \[View β\] β β β
β β β β βββββββββββββββ βββββββββββββββ βββββββββββββββ β β
β β β β β β
β β β β βββββββββββββββ β β
β β β β β βοΈ β β β
β β β β β Core β β β
β β β β β β β β
β β β β β Foundation β β β
β β β β β types and β β β
β β β β β protocols β β β
β β β β β β β β
β β β β β \[View β\] β β β
β β β β βββββββββββββββ β β
β β β β β β
β β β β β β
β βββββββββββββββββββ βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Package authors can enhance the auto-generated documentation by adding DocC catalogs (.docc directories) to their targets. These catalogs enable rich, custom content including tutorials, getting-started guides, and conceptual documentation that complements the automatically generated API reference. This approach allows packages to evolve from basic API documentation to comprehensive developer resources without requiring a complete documentation rewrite.
For executable targets that use Swift Argument Parser or are capable of generating a compatible tool-info JSON, the command automatically extracts the complete command-line structure and converts it into documentation-ready symbol graphs. This makes CLI tools as discoverable and well-documented as library APIs, bridging the gap between different types of Swift products. The command-line structure is intelligently mapped to Swift-like types that integrate seamlessly with DocC's rendering capabilities.
The --internal flag extends documentation generation to include internal targets that aren't exposed as public products. This feature proves valuable for open-source projects where contributors need to understand package architecture and implementation details, or for organizations documenting internal APIs for their development teams.
Impact on Existing Packages
Packages currently using the DocC plugin will continue working without any changes. The existing plugin takes precedence over this new command, ensuring backward compatibility. This means teams can migrate to the new approach at their own pace without disrupting existing workflows.
Packages without existing documentation infrastructure immediately gain access to documentation generation for both public and internal APIs. This eases documentation creation across the Swift ecosystem, particularly benefiting smaller projects and individual developers.
DocC catalogs and detailed API comments work seamlessly with both the existing plugin system and this new command. This compatibility means package authors can incrementally improve their documentation by adding doc comments, DocC catalogs, and enhanced CLI command/option/flag descriptions, with all approaches building on the same foundation.
Alternatives
The existing DocC plugin could be enhanced to incorporate some of these simplifications, particularly around target discovery and configuration defaults. However, this approach wouldn't achieve the same level of package-level integration or the seamless merging of multiple products into a unified documentation experience that this proposal enables. Also, it wonβt remove the requirement to manually add the plugin to a package.
Future Directions
This foundation creates opportunities to extend documentation generation to additional product types that are becoming increasingly important in the Swift ecosystem, including Swift macros, package plugins, and potentially even test targets for packages that want to document their testing strategies and utilities.
We can expand DocC's API coverage to better support command-line interfaces with dedicated documentation patterns, moving beyond the current approach of mapping CLI structures to Swift types. This could include specialized API descriptions and rendering for command hierarchies, option groups, and usage examples that are more natural for command-line tools.
Future enhancements could integrate README.md content directly into package landing pages, eliminating the need for authors to maintain duplicate introductory content across readme files and documentation catalogs. This integration would create a more cohesive experience where a package's GitHub presence and its generated documentation tell the same story with consistent messaging and examples.