Skip to content

Commit 76f4065

Browse files
Update project files
1 parent 7fdfe1f commit 76f4065

File tree

16 files changed

+737
-24
lines changed

16 files changed

+737
-24
lines changed

API.docc/API.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,30 @@
1-
# ``API``
1+
# REST API Documentation
22

3-
A sample API for testing OpenAPI to SymbolGraph conversion.
3+
A comprehensive REST API example documented with DocC.
44

55
## Overview
66

7-
This documentation is generated from an OpenAPI specification using the OpenAPI to SymbolGraph conversion tool.
7+
This documentation is generated from an OpenAPI specification, showcasing how REST APIs can be documented using DocC, the documentation compiler familiar to Swift developers.
88

9-
## Topics
9+
## Key Features
1010

11-
### Schemas
11+
- Auto-generated documentation from OpenAPI schemas
12+
- Integration with Swift DocC's navigation and search
13+
- Standard format for HTTP endpoints and request/response schemas
14+
- Consistent developer experience between Swift API docs and REST API docs
1215

13-
- ``User``
16+
## Topics
1417

1518
### Endpoints
1619

17-
- ``getUsers``
18-
- ``getUserById``
20+
- ``API/listUsers``
21+
- ``API/getUserById``
22+
- ``API/createUser``
23+
24+
### Data Models
25+
26+
- ``API/User``
27+
28+
### Getting Started
29+
30+
- <doc:Getting-Started>

API.docc/Getting-Started.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Getting Started
2+
3+
Learn how to integrate with our REST API.
4+
5+
## Overview
6+
7+
This guide will help you get started with integrating our REST API into your application. Our API uses standard HTTP methods and JSON for request and response bodies.
8+
9+
## Authentication
10+
11+
All endpoints require authentication. Include your API key in the headers of each request:
12+
13+
```swift
14+
var request = URLRequest(url: url)
15+
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
16+
```
17+
18+
## Using the API
19+
20+
### Swift Example
21+
22+
Here's a Swift example of how to get a list of users:
23+
24+
```swift
25+
import Foundation
26+
27+
func fetchUsers(completion: @escaping ([User]?, Error?) -> Void) {
28+
let url = URL(string: "https://api.example.com/users")!
29+
var request = URLRequest(url: url)
30+
request.httpMethod = "GET"
31+
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
32+
33+
let task = URLSession.shared.dataTask(with: request) { data, response, error in
34+
if let error = error {
35+
completion(nil, error)
36+
return
37+
}
38+
39+
guard let data = data else {
40+
completion(nil, NSError(domain: "No data", code: 0, userInfo: nil))
41+
return
42+
}
43+
44+
do {
45+
let users = try JSONDecoder().decode([User].self, from: data)
46+
completion(users, nil)
47+
} catch {
48+
completion(nil, error)
49+
}
50+
}
51+
52+
task.resume()
53+
}
54+
```
55+
56+
### Swift Async/Await Example
57+
58+
Using modern Swift concurrency:
59+
60+
```swift
61+
import Foundation
62+
63+
func fetchUsers() async throws -> [User] {
64+
let url = URL(string: "https://api.example.com/users")!
65+
var request = URLRequest(url: url)
66+
request.httpMethod = "GET"
67+
request.setValue("Bearer YOUR_API_KEY", forHTTPHeaderField: "Authorization")
68+
69+
let (data, _) = try await URLSession.shared.data(for: request)
70+
return try JSONDecoder().decode([User].self, from: data)
71+
}
72+
```
73+
74+
## Error Handling
75+
76+
Our API uses standard HTTP status codes:
77+
78+
- 200 - OK: Request succeeded
79+
- 400 - Bad Request: Invalid parameters
80+
- 401 - Unauthorized: Authentication failed
81+
- 404 - Not Found: Resource not found
82+
- 500 - Server Error: Something went wrong on our side
83+
84+
## Rate Limits
85+
86+
API requests are limited to 100 requests per minute per API key.

API.docc/Info.plist

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,10 @@
99
<key>CFBundleVersion</key>
1010
<string>1.0.0</string>
1111
<key>CFBundleDisplayName</key>
12-
<string>API Documentation</string>
13-
<key>DefaultCodeListingLanguage</key>
12+
<string>REST API Example</string>
13+
<key>CDDefaultCodeListingLanguage</key>
1414
<string>swift</string>
15-
<key>DefaultLanguage</key>
16-
<string>en-US</string>
17-
<key>DocSetPlatformFamily</key>
18-
<string>api</string>
19-
<key>Title</key>
20-
<string>API Documentation</string>
15+
<key>CDDefaultModuleKind</key>
16+
<string>Library</string>
2117
</dict>
22-
</plist>
18+
</plist>

DocsExample/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# OpenAPI Integration with DocC Example
2+
3+
This example demonstrates how to document a REST API using DocC, Apple's Documentation Compiler.
4+
5+
## Overview
6+
7+
The example showcases:
8+
1. Converting OpenAPI specifications to Swift DocC compatible documentation
9+
2. Generating developer-friendly API documentation
10+
3. Creating a consistent experience between Swift API docs and REST API docs
11+
12+
## Getting Started
13+
14+
### Prerequisites
15+
16+
- Xcode 15.0 or later
17+
- Swift 6.0 or later
18+
19+
### Running the Example
20+
21+
1. Clone this repository:
22+
```bash
23+
git clone https://github.com/ayushshrivastv/OpenAPI-integration-with-DocC.git
24+
cd OpenAPI-integration-with-DocC
25+
```
26+
27+
2. Build the tool:
28+
```bash
29+
swift build
30+
```
31+
32+
3. Convert an OpenAPI specification to a SymbolGraph:
33+
```bash
34+
swift run openapi-to-symbolgraph api.yaml --output-path api.symbolgraph.json
35+
```
36+
37+
4. Generate DocC documentation:
38+
```bash
39+
xcrun docc convert API.docc --fallback-display-name API --fallback-bundle-identifier com.example.API --fallback-bundle-version 1.0.0 --additional-symbol-graph-dir ./ --output-path ./docs
40+
```
41+
42+
5. View the documentation:
43+
```bash
44+
python -m http.server 8000 --directory docs
45+
```
46+
47+
Then open your browser to http://localhost:8000
48+
49+
## Example Documentation
50+
51+
For a quick preview, you can view the `index.html` file in this directory, which shows a sample of what the generated documentation looks like.
52+
53+
## Structure
54+
55+
- `api.yaml`: Sample OpenAPI specification
56+
- `API.docc`: DocC documentation catalog
57+
- `Sources`: Implementation of the OpenAPI to SymbolGraph converter
58+
- `DocsExample`: Example of the generated documentation
59+
60+
## How It Works
61+
62+
1. The OpenAPI specification is parsed and converted to a SymbolGraph JSON format
63+
2. DocC uses the SymbolGraph to generate documentation
64+
3. The documentation is served as a static website
65+
66+
## Contributing
67+
68+
Contributions are welcome! Please feel free to submit a Pull Request.

0 commit comments

Comments
 (0)