|
1 | | -# OpenAPI to DocC Symbol Graph |
| 1 | +# OpenAPI Integration with DocC |
2 | 2 |
|
3 | | -A tool to convert OpenAPI documents into DocC symbol graphs, enabling seamless integration of API documentation with Swift's DocC documentation system. |
| 3 | +This project provides tools and examples for integrating OpenAPI specifications with Apple's DocC documentation system. It allows developers to create beautiful, interactive documentation for REST APIs that matches the style and quality of Swift API documentation. |
4 | 4 |
|
5 | | -## Features |
| 5 | +## Overview |
6 | 6 |
|
7 | | -- Converts OpenAPI documents (JSON/YAML) to DocC symbol graphs |
8 | | -- Supports all HTTP methods (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS) |
9 | | -- Generates comprehensive documentation for: |
10 | | - - API endpoints |
11 | | - - Request parameters |
12 | | - - Request bodies |
13 | | - - Response types |
14 | | -- Preserves OpenAPI descriptions and metadata |
15 | | -- Command-line interface for easy integration |
| 7 | +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. |
16 | 8 |
|
17 | | -## Installation |
| 9 | +## Key Features |
18 | 10 |
|
19 | | -### Requirements |
| 11 | +- Convert OpenAPI 3.1.0 specifications to DocC-compatible format |
| 12 | +- Generate beautiful API documentation |
| 13 | +- Provide a consistent documentation experience for Swift developers |
| 14 | +- Support for documenting endpoints, schemas, parameters, and more |
20 | 15 |
|
21 | | -- Swift 5.7 or later |
22 | | -- macOS 12.0 or later |
| 16 | +## Getting Started |
23 | 17 |
|
24 | | -### Building from Source |
| 18 | +### Prerequisites |
| 19 | + |
| 20 | +- Xcode 15.0 or later |
| 21 | +- Swift 6.0 or later |
| 22 | +- Python 3 (for local documentation serving) |
| 23 | + |
| 24 | +### Installation |
25 | 25 |
|
26 | | -1. Clone the repository: |
27 | 26 | ```bash |
28 | | -git clone https://github.com/yourusername/OpenAPItoSymbolGraph.git |
29 | | -cd OpenAPItoSymbolGraph |
| 27 | +git clone https://github.com/ayushshrivastv/OpenAPI-integration-with-DocC.git |
| 28 | +cd OpenAPI-integration-with-DocC |
| 29 | +swift build |
30 | 30 | ``` |
31 | 31 |
|
32 | | -2. Build the package: |
| 32 | +### Usage |
| 33 | + |
| 34 | +1. Convert your OpenAPI specification to a SymbolGraph: |
| 35 | + |
33 | 36 | ```bash |
34 | | -swift build -c release |
| 37 | +swift run openapi-to-symbolgraph path/to/your/api.yaml --output-path api.symbolgraph.json |
35 | 38 | ``` |
36 | 39 |
|
37 | | -3. The executable will be available at `.build/release/openapi-to-symbolgraph` |
| 40 | +2. Create a DocC documentation catalog (see `API.docc` as an example) |
38 | 41 |
|
39 | | -## Usage |
| 42 | +3. Generate the documentation: |
40 | 43 |
|
41 | 44 | ```bash |
42 | | -openapi-to-symbolgraph <input-path> [--output-directory <directory>] [--output-file <filename>] |
| 45 | +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 |
43 | 46 | ``` |
44 | 47 |
|
45 | | -### Arguments |
| 48 | +## Viewing the Documentation |
| 49 | + |
| 50 | +### Online Documentation |
| 51 | + |
| 52 | +The latest documentation is automatically deployed to GitHub Pages and can be viewed at: |
| 53 | + |
| 54 | +[https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/](https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/) |
| 55 | + |
| 56 | +### Local Documentation Server |
46 | 57 |
|
47 | | -- `input-path`: Path to the OpenAPI document (JSON or YAML) |
48 | | -- `--output-directory`: Directory where the symbol graph will be saved (default: current directory) |
49 | | -- `--output-file`: Name of the output file (default: openapi.symbolgraph.json) |
| 58 | +You can serve the documentation locally using one of these methods: |
50 | 59 |
|
51 | | -### Example |
| 60 | +#### Using the helper script: |
52 | 61 |
|
53 | 62 | ```bash |
54 | | -openapi-to-symbolgraph api.yaml --output-directory docs --output-file api.symbolgraph.json |
| 63 | +./serve-docs.sh |
55 | 64 | ``` |
56 | 65 |
|
57 | | -## Integration with DocC |
| 66 | +#### Using Python 3 directly: |
58 | 67 |
|
59 | | -1. Generate the symbol graph: |
60 | 68 | ```bash |
61 | | -openapi-to-symbolgraph api.yaml |
| 69 | +python3 -m http.server 8000 --directory docs |
62 | 70 | ``` |
63 | 71 |
|
64 | | -2. Add the symbol graph to your DocC documentation: |
65 | | -```swift |
66 | | -import DocC |
| 72 | +Then open your browser to http://localhost:8000 |
67 | 73 |
|
68 | | -let documentation = Documentation( |
69 | | - symbolGraphs: ["openapi.symbolgraph.json"] |
70 | | -) |
71 | | -``` |
| 74 | +## Example |
| 75 | + |
| 76 | +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. |
| 77 | + |
| 78 | +## How It Works |
| 79 | + |
| 80 | +1. The OpenAPI specification is parsed using `OpenAPIKit` |
| 81 | +2. The specification is converted to a SymbolGraph, which is the format DocC uses for documentation |
| 82 | +3. DocC processes the SymbolGraph and generates the documentation |
| 83 | +4. The documentation can be served as a static website or deployed to GitHub Pages |
| 84 | + |
| 85 | +## GitHub Pages Deployment |
| 86 | + |
| 87 | +This repository is configured to automatically deploy documentation to GitHub Pages whenever changes are pushed to the main branch. The deployment process: |
| 88 | + |
| 89 | +1. Uses the GitHub Actions workflow defined in `.github/workflows/pages.yml` |
| 90 | +2. Takes the contents of the `docs` directory |
| 91 | +3. Deploys them to GitHub Pages |
| 92 | +4. Makes the documentation available at the URL: [https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/](https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/) |
72 | 93 |
|
73 | 94 | ## Contributing |
74 | 95 |
|
|
0 commit comments