Skip to content

Commit 8976976

Browse files
Add OpenAPI to DocC converter implementation and tests
1 parent af84d14 commit 8976976

23 files changed

+3058
-2
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Advanced Topics
2+
3+
## Custom Templates
4+
5+
### Creating Custom Templates
6+
You can create custom documentation templates by extending the base template system:
7+
8+
```swift
9+
struct CustomTemplate: DocumentationTemplate {
10+
func render(symbol: Symbol) -> String {
11+
// Custom rendering logic
12+
}
13+
}
14+
```
15+
16+
### Template Configuration
17+
Configure templates in your `config.json`:
18+
19+
```json
20+
{
21+
"templates": {
22+
"default": "path/to/custom/template",
23+
"custom": {
24+
"style": "dark",
25+
"layout": "sidebar"
26+
}
27+
}
28+
}
29+
```
30+
31+
## Advanced Symbol Generation
32+
33+
### Custom Symbol Mappings
34+
Override default symbol mappings:
35+
36+
```swift
37+
struct CustomSymbolMapper: SymbolMapper {
38+
func map(openAPIComponent: OpenAPIComponent) -> Symbol {
39+
// Custom mapping logic
40+
}
41+
}
42+
```
43+
44+
### Symbol Relationships
45+
Define custom relationships between symbols:
46+
47+
```swift
48+
struct CustomRelationshipGenerator: RelationshipGenerator {
49+
func generateRelationships(symbols: [Symbol]) -> [Relationship] {
50+
// Custom relationship generation
51+
}
52+
}
53+
```
54+
55+
## Performance Optimization
56+
57+
### Caching
58+
Enable caching for improved performance:
59+
60+
```json
61+
{
62+
"cache": {
63+
"enabled": true,
64+
"directory": ".cache",
65+
"ttl": 3600
66+
}
67+
}
68+
```
69+
70+
### Parallel Processing
71+
Configure parallel processing options:
72+
73+
```json
74+
{
75+
"processing": {
76+
"maxConcurrent": 4,
77+
"chunkSize": 100
78+
}
79+
}
80+
```
81+
82+
## Integration with Build Systems
83+
84+
### Xcode Integration
85+
Add a build phase to your Xcode project:
86+
87+
```bash
88+
openapi-to-symbolgraph "${SRCROOT}/path/to/openapi.yaml" --output "${BUILT_PRODUCTS_DIR}/Documentation"
89+
```
90+
91+
### CI/CD Integration
92+
Example GitHub Actions workflow:
93+
94+
```yaml
95+
name: Generate Documentation
96+
on: [push, pull_request]
97+
jobs:
98+
build:
99+
runs-on: macos-latest
100+
steps:
101+
- uses: actions/checkout@v2
102+
- name: Generate Docs
103+
run: |
104+
swift run openapi-to-symbolgraph api.yaml
105+
```
106+
107+
## Troubleshooting
108+
109+
### Common Issues
110+
- **Memory Usage**: Adjust chunk size for large documents
111+
- **Performance**: Enable caching for repeated builds
112+
- **Template Errors**: Check template syntax and validation
113+
114+
### Debugging
115+
Enable debug logging:
116+
117+
```bash
118+
openapi-to-symbolgraph api.yaml --verbose --debug
119+
```
120+
121+
## Next Steps
122+
- Explore the [API Reference](APIReference.md)
123+
- Check out [Advanced Tutorials](Tutorial2.md)
124+
- Review [Best Practices](../Reference/BestPractices.md)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Getting Started with OpenAPI-DocC Integration
2+
3+
## Installation
4+
5+
### Using Swift Package Manager
6+
Add the following to your `Package.swift` file:
7+
8+
```swift
9+
dependencies: [
10+
.package(url: "https://github.com/yourusername/OpenAPI-DocC-Integration.git", from: "1.0.0")
11+
]
12+
```
13+
14+
### Manual Installation
15+
1. Clone the repository:
16+
```bash
17+
git clone https://github.com/yourusername/OpenAPI-DocC-Integration.git
18+
```
19+
2. Build the package:
20+
```bash
21+
swift build
22+
```
23+
24+
## Basic Usage
25+
26+
### Command Line Interface
27+
The simplest way to use the tool is through the command line:
28+
29+
```bash
30+
openapi-to-symbolgraph path/to/your/openapi.yaml
31+
```
32+
33+
This will generate a DocC-compatible symbol graph file.
34+
35+
### Programmatic Usage
36+
You can also use the library programmatically:
37+
38+
```swift
39+
import OpenAPIDocC
40+
41+
let converter = OpenAPIDocCConverter()
42+
let symbolGraph = try converter.convert(openAPIFile: "path/to/your/openapi.yaml")
43+
```
44+
45+
## Configuration
46+
47+
### Basic Configuration
48+
Create a `config.json` file in your project root:
49+
50+
```json
51+
{
52+
"outputPath": "docs",
53+
"template": "default",
54+
"includeExamples": true
55+
}
56+
```
57+
58+
### Advanced Configuration
59+
See [Advanced Topics](AdvancedTopics.md) for more configuration options.
60+
61+
## Next Steps
62+
- Try the [Basic Tutorial](Tutorial1.md)
63+
- Explore [Advanced Features](AdvancedTopics.md)
64+
- Check the [API Reference](APIReference.md)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Introduction to OpenAPI-DocC Integration
2+
3+
## Overview
4+
The OpenAPI-DocC Integration project provides a seamless way to generate DocC documentation from OpenAPI specifications. This tool bridges the gap between OpenAPI's comprehensive API description format and DocC's powerful documentation capabilities in the Swift ecosystem.
5+
6+
## Key Features
7+
- Convert OpenAPI documents (YAML/JSON) to DocC-compatible symbol graphs
8+
- Generate comprehensive API documentation
9+
- Support for OpenAPI 3.0 and 3.1 specifications
10+
- Customizable documentation templates
11+
- Integration with existing DocC workflows
12+
13+
## Why Use This Tool?
14+
- **Consistency**: Maintain a single source of truth for your API documentation
15+
- **Developer Experience**: Leverage familiar DocC documentation in Xcode
16+
- **Automation**: Automate documentation generation as part of your build process
17+
- **Rich Documentation**: Combine OpenAPI's API description with DocC's rich documentation features
18+
19+
## Prerequisites
20+
- Swift 5.7 or later
21+
- Xcode 14 or later (for DocC integration)
22+
- Basic understanding of OpenAPI specifications
23+
- Familiarity with Swift and DocC documentation
24+
25+
## Next Steps
26+
- [Getting Started](GettingStarted.md)
27+
- [Advanced Topics](AdvancedTopics.md)
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
# API Reference
2+
3+
## Core Types
4+
5+
### OpenAPIDocCConverter
6+
7+
The main converter class that handles the conversion from OpenAPI to DocC.
8+
9+
```swift
10+
public class OpenAPIDocCConverter {
11+
public init(configuration: Configuration = .default)
12+
public func convert(openAPIFile: String) throws -> SymbolGraph
13+
public func convert(openAPIData: Data, fileExtension: String) throws -> SymbolGraph
14+
}
15+
```
16+
17+
### Configuration
18+
19+
Configuration options for the converter.
20+
21+
```swift
22+
public struct Configuration {
23+
public var outputPath: String
24+
public var template: Template
25+
public var cache: CacheConfiguration
26+
public var processing: ProcessingConfiguration
27+
28+
public static var `default`: Configuration
29+
}
30+
```
31+
32+
## Templates
33+
34+
### DocumentationTemplate
35+
36+
Protocol for custom documentation templates.
37+
38+
```swift
39+
public protocol DocumentationTemplate {
40+
func render(symbol: Symbol) -> String
41+
}
42+
```
43+
44+
### DefaultTemplate
45+
46+
The default template implementation.
47+
48+
```swift
49+
public struct DefaultTemplate: DocumentationTemplate {
50+
public init()
51+
public func render(symbol: Symbol) -> String
52+
}
53+
```
54+
55+
## Symbol Mapping
56+
57+
### SymbolMapper
58+
59+
Protocol for custom symbol mapping.
60+
61+
```swift
62+
public protocol SymbolMapper {
63+
func map(openAPIComponent: OpenAPIComponent) -> Symbol
64+
}
65+
```
66+
67+
### DefaultSymbolMapper
68+
69+
The default symbol mapper implementation.
70+
71+
```swift
72+
public struct DefaultSymbolMapper: SymbolMapper {
73+
public init()
74+
public func map(openAPIComponent: OpenAPIComponent) -> Symbol
75+
}
76+
```
77+
78+
## Utilities
79+
80+
### URLTemplate
81+
82+
Utility for handling URL templates in OpenAPI specifications.
83+
84+
```swift
85+
public struct URLTemplate {
86+
public init(template: String)
87+
public func expand(parameters: [String: String]) -> String
88+
}
89+
```
90+
91+
### Validation
92+
93+
Utility for validating OpenAPI specifications.
94+
95+
```swift
96+
public struct Validation {
97+
public static func validate(_ document: OpenAPI.Document) throws
98+
public static func validate(_ schema: JSONSchema) throws
99+
}
100+
```
101+
102+
## Error Types
103+
104+
### ConversionError
105+
106+
Errors that can occur during conversion.
107+
108+
```swift
109+
public enum ConversionError: Error {
110+
case invalidFileType(String)
111+
case parsingError(String)
112+
case validationError(String)
113+
case templateError(String)
114+
}
115+
```
116+
117+
## Configuration Types
118+
119+
### CacheConfiguration
120+
121+
Configuration for caching.
122+
123+
```swift
124+
public struct CacheConfiguration {
125+
public var enabled: Bool
126+
public var directory: String
127+
public var ttl: TimeInterval
128+
}
129+
```
130+
131+
### ProcessingConfiguration
132+
133+
Configuration for parallel processing.
134+
135+
```swift
136+
public struct ProcessingConfiguration {
137+
public var maxConcurrent: Int
138+
public var chunkSize: Int
139+
}
140+
```
141+
142+
## Usage Examples
143+
144+
### Basic Conversion
145+
146+
```swift
147+
let converter = OpenAPIDocCConverter()
148+
let symbolGraph = try converter.convert(openAPIFile: "api.yaml")
149+
```
150+
151+
### Custom Configuration
152+
153+
```swift
154+
var config = Configuration.default
155+
config.outputPath = "custom/docs"
156+
config.template = CustomTemplate()
157+
let converter = OpenAPIDocCConverter(configuration: config)
158+
```
159+
160+
### Custom Symbol Mapping
161+
162+
```swift
163+
struct CustomMapper: SymbolMapper {
164+
func map(openAPIComponent: OpenAPIComponent) -> Symbol {
165+
// Custom mapping logic
166+
}
167+
}
168+
169+
let converter = OpenAPIDocCConverter()
170+
converter.symbolMapper = CustomMapper()
171+
```
172+
173+
## Related Documentation
174+
- [Data Types](DataTypes.md)
175+
- [Best Practices](BestPractices.md)
176+
- [Advanced Topics](../Guides/AdvancedTopics.md)

0 commit comments

Comments
 (0)