Skip to content

Commit a5436f4

Browse files
Merge branch 'main' into feature/organize-examples
Signed-off-by: Ayush Srivastava <ayush.srivastav@icloud.com>
2 parents ada4968 + 7faca7d commit a5436f4

File tree

1 file changed

+63
-85
lines changed

1 file changed

+63
-85
lines changed

README.md

Lines changed: 63 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
11
# OpenAPI Integration with DocC
22

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.
3+
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.
44

55
## Overview
66

77
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.
88

9-
## Key Features
10-
11-
- Convert OpenAPI 3.x 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
9+
![2048](https://github.com/user-attachments/assets/f9a751be-9d2f-43f0-8346-04af7edaea57)
1510

1611
## Project Structure
1712

1813
The project is organized into several modules:
1914

20-
- `Sources/OpenAPI` - Core functionality for parsing OpenAPI specifications.
21-
- `Sources/OpenAPItoSymbolGraph` - Main implementation for converting OpenAPI models to SymbolGraph.
22-
- `Sources/Integration` - Integration points, potentially including the CLI tool.
23-
- `Sources/openapi-to-symbolgraph` - The command-line executable target.
24-
- `Tests/OpenAPItoSymbolGraphTests` - Unit and integration tests.
15+
- `Sources/Core` - Core functionality and data models
16+
- `Sources/CLI` - Command-line interface
17+
- `Sources/OpenAPItoSymbolGraph` - Main implementation with submodules:
18+
- `Mapping` - Mappers between OpenAPI and SymbolGraph
19+
- `Utils/DocC` - DocC integration utilities
20+
21+
## Key Features
22+
23+
- Convert OpenAPI 3.1.0 specifications to DocC compatible format
24+
- Generate API documentation
25+
- Provide a consistent documentation experience for Swift developers
26+
- Support for documenting endpoints, schemas, parameters, and more
2527

2628
## Getting Started
2729

2830
### Prerequisites
2931

30-
- Xcode 15.0 or later (requires Swift 5.9+ for DocC support)
31-
- Swift command-line tools configured (`xcrun`)
32+
- Xcode 15.0 or later
33+
- Swift 6.0 or later
34+
- Python 3 (for local documentation serving)
3235

3336
### Installation
3437

@@ -38,107 +41,82 @@ cd OpenAPI-integration-with-DocC
3841
swift build
3942
```
4043

41-
### Usage Steps
42-
43-
1. **Obtain your OpenAPI Specification:** Ensure you have your API specification in a `.yaml`, `.yml`, or `.json` file (OpenAPI v3.x format).
44-
2. **Generate SymbolGraph:** Run the command-line tool, providing the path to your OpenAPI file.
45-
46-
```bash
47-
swift run openapi-to-symbolgraph <path_to_your_openapi_spec> --output-path <desired_symbolgraph_name>.symbolgraph.json
48-
```
49-
50-
3. **Prepare SymbolGraph Directory:** Move the generated `.symbolgraph.json` file into a dedicated directory (e.g., `symbolgraphs`).
51-
52-
```bash
53-
mkdir symbolgraphs
54-
mv <desired_symbolgraph_name>.symbolgraph.json symbolgraphs/
55-
```
56-
57-
4. **Create a DocC Catalog:** Create a basic documentation catalog directory (e.g., `MyAPI.docc`). This needs at least one markdown file to serve as the root landing page.
58-
59-
```bash
60-
mkdir MyAPI.docc
61-
# Create a root file, e.g., MyAPI.docc/MyAPI.md
62-
echo "# MyAPI\\n\\nAPI Documentation landing page." > MyAPI.docc/MyAPI.md
63-
```
64-
65-
5. **Generate DocC Archive:** Use `xcrun docc convert` to combine your catalog and symbol graph into a `.doccarchive`.
44+
### Usage
6645

67-
```bash
68-
xcrun docc convert MyAPI.docc --additional-symbol-graph-dir symbolgraphs --output-path MyAPI.doccarchive
69-
```
46+
1. Convert your OpenAPI specification to a SymbolGraph:
7047

71-
6. **View Documentation:** Open the generated `MyAPI.doccarchive` file in Xcode, or host it on a web server.
72-
73-
### Example: Swift Package Registry API
74-
75-
This example demonstrates generating documentation for the official Swift Package Registry API.
48+
```bash
49+
swift run openapi-to-symbolgraph Examples/api.yaml --output-path api.symbolgraph.json
50+
```
7651

77-
1. **Download the Spec:**
52+
### Example with Pet Store API
7853

79-
```bash
80-
# Create a directory for test resources if it doesn't exist
81-
mkdir -p Tests/OpenAPItoSymbolGraphTests/Resources
54+
The tool has also been tested with the standard Swagger Pet Store OpenAPI definition:
8255

83-
# Download the registry spec
84-
curl -o Tests/OpenAPItoSymbolGraphTests/Resources/registry.openapi.yaml https://raw.githubusercontent.com/swiftlang/swift-package-manager/main/Documentation/PackageRegistry/registry.openapi.yaml
85-
```
56+
```bash
57+
# Download the Pet Store spec (if you haven't already)
58+
# curl -o Examples/petstore.yaml https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml
8659

87-
2. **Generate SymbolGraph:**
60+
# Convert the Pet Store spec
8861

89-
```bash
90-
swift run openapi-to-symbolgraph Tests/OpenAPItoSymbolGraphTests/Resources/registry.openapi.yaml --output-path registry.symbolgraph.json
91-
```
62+
swift run openapi-to-symbolgraph Examples/petstore.yaml --output-path petstore.symbolgraph.json
63+
```
9264

93-
3. **Prepare Directory:**
65+
2. Create a DocC documentation catalog (see `API.docc` as an example)
9466

95-
```bash
96-
mkdir -p symbolgraphs # Ensure directory exists
97-
mv registry.symbolgraph.json symbolgraphs/
98-
```
67+
3. Generate the documentation:
9968

100-
4. **Create Catalog:** (We created `RegistryAPI.docc` earlier)
69+
```bash
70+
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
71+
```
10172

102-
```bash
103-
# Ensure the catalog exists and has a root file
104-
mkdir -p RegistryAPI.docc
105-
echo "# RegistryAPI\\n\\nSwift Package Registry API documentation." > RegistryAPI.docc/RegistryAPI.md
106-
```
73+
## Viewing the Documentation
10774

108-
5. **Generate Archive:**
75+
The `docs/` directory in this repository contains the pre-generated DocC documentation website output for the **Swagger Pet Store API**, which was built using the `petstore.symbolgraph.json` generated by this tool and the `API.docc` catalog.
10976

110-
```bash
111-
xcrun docc convert RegistryAPI.docc --additional-symbol-graph-dir symbolgraphs --output-path RegistryAPI.doccarchive
112-
```
77+
### Documentation
11378

114-
This creates `RegistryAPI.doccarchive`, which contains the generated documentation for the Swift Package Registry API.
79+
The latest documentation is automatically deployed to GitHub Pages and can be viewed at:
11580

116-
## Viewing the Documentation
81+
[https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/](https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/)
11782

118-
You can view generated `.doccarchive` files in Xcode or host them online.
83+
### Local Documentation Server
11984

120-
### Example Pet Store Documentation (Pre-built)
85+
You can serve the documentation locally using one of these methods:
12186

122-
The `docs/` directory in this repository contains pre-generated DocC website output for the **Swagger Pet Store API**. This was built using `Examples/petstore.yaml` and an example `API.docc` catalog.
87+
#### Using the helper script:
12388

124-
**View Online:** [https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/](https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/)
89+
```bash
90+
./serve-docs.sh
91+
```
12592

126-
**Serve Locally:**
93+
#### Using Python 3 directly:
12794

12895
```bash
129-
# Serve the pre-built Pet Store docs
13096
python3 -m http.server 8000 --directory docs
13197
```
13298

133-
Then open http://localhost:8000 in your browser.
99+
Then open your browser to http://localhost:8000
134100

135-
## Testing
101+
## Example
136102

137-
The tool includes a comprehensive test suite (`swift test`) covering parsing, conversion, and command-line arguments, using examples like the Pet Store API and the Swift Package Registry API.
103+
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.
104+
105+
## How It Works
106+
107+
1. The OpenAPI specification is parsed using `OpenAPIKit`
108+
2. The specification is converted to a SymbolGraph, which is the format DocC uses for documentation
109+
3. DocC processes the SymbolGraph and generates the documentation
110+
4. The documentation can be served as a static website or deployed to GitHub Pages
138111

139112
## GitHub Pages Deployment
140113

141-
This repository automatically deploys the pre-built Pet Store documentation from the `docs` directory to GitHub Pages via the `.github/workflows/pages.yml` workflow.
114+
This repository is configured to automatically deploy documentation to GitHub Pages whenever changes are pushed to the main branch. The deployment process:
115+
116+
1. Uses the GitHub Actions workflow defined in `.github/workflows/pages.yml`
117+
2. Takes the contents of the `docs` directory
118+
3. Deploys them to GitHub Pages
119+
4. Makes the documentation available at the URL: [https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/](https://ayushshrivastv.github.io/OpenAPI-integration-with-DocC/)
142120

143121
## Contributing
144122

0 commit comments

Comments
 (0)