Skip to content

ayushshrivastv/OpenAPI-Integration-with-DocC

Repository files navigation

OpenAPI Integration with DocC

The project aims to bridge the gap between OpenAPI specifications and Swift's DocC documentation framework by developing a tool that automates the generation of DocC documentation from OpenAPI files.

Overview

OpenAPI is the industry standard for documenting HTTP services, but Swift developers are already familiar with DocC for their Swift and Objective-C API documentation. This project bridges that gap by converting OpenAPI specifications into a format that DocC can understand and render.

2048

Project Structure

The project is organized into several modules:

  • Sources/Core - Core functionality and data models
  • Sources/CLI - Command-line interface
  • Sources/OpenAPItoSymbolGraph - Main implementation with submodules:
    • Mapping - Mappers between OpenAPI and SymbolGraph
    • Utils/DocC - DocC integration utilities

Key Features

  • Convert OpenAPI 3.1.0 specifications to DocC compatible format
  • Generate API documentation
  • Provide a consistent documentation experience for Swift developers
  • Support for documenting endpoints, schemas, parameters, and more

Getting Started

Prerequisites

  • Xcode 15.0 or later
  • Swift 6.0 or later
  • Python 3 (for local documentation serving)

Installation

git clone https://github.com/ayushshrivastv/OpenAPI-integration-with-DocC.git
cd OpenAPI-integration-with-DocC
swift build

Usage

  1. Convert your OpenAPI specification to a SymbolGraph:
swift run openapi-to-symbolgraph Examples/api.yaml --output-path api.symbolgraph.json
  1. Generate the documentation using our helper script:
./scripts/build-docs.sh

Or manually with DocC:

xcrun docc convert YourAPI.docc --fallback-display-name YourAPI --fallback-bundle-identifier com.example.YourAPI --fallback-bundle-version 1.0.0 --additional-symbol-graph-dir ./ --output-path ./docs

Viewing the Documentation

The docs/ directory in this repository contains the pre-generated DocC documentation website output for the Swift Package Registry API, which was built using the registry.symbolgraph.json generated by this tool and the RegistryAPI.docc catalog.

Documentation

The latest documentation is automatically deployed to GitHub Pages and can be viewed at:

https://ayushshrivastv.github.io/OpenAPI-Integration-with-DocC/

Local Documentation Server

You can serve the documentation locally using one of these methods:

Using the local preview script (recommended):

./scripts/local-preview.sh

This script serves the documentation directory and opens it in your browser. You will be automatically redirected to the API documentation.

Using the server script:

./scripts/serve-docs.sh

Using Python 3 directly:

python3 -m http.server 8000 --directory docs

Then open your browser to http://localhost:8000

Example

Check out the DocsExample directory for a working example of a REST API documented with DocC. It showcases how endpoints, schemas, and examples appear in the DocC format.

How It Works

  1. The OpenAPI specification is parsed using OpenAPIKit
  2. The specification is converted to a SymbolGraph, which is the format DocC uses for documentation
  3. DocC processes the SymbolGraph and generates the documentation
  4. The documentation can be served as a static website or deployed to GitHub Pages

GitHub Pages Deployment

This repository is configured to automatically deploy documentation to GitHub Pages whenever changes are pushed to the main branch. The deployment process:

  1. Uses the GitHub Actions workflow defined in .github/workflows/pages.yml
  2. Builds the documentation from the OpenAPI specification
  3. Takes the contents of the docs directory
  4. Deploys them to GitHub Pages
  5. Makes the documentation available at the URL: https://ayushshrivastv.github.io/OpenAPI-Integration-with-DocC/

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

OpenAPI Integration with DocC

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages