Skip to content

Commit ae985dd

Browse files
Add module-name parameter to make DocC integration more flexible
1 parent 7798eac commit ae985dd

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

Sources/CLI/main.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct OpenAPIToSymbolGraph: ParsableCommand {
1717
@Option(name: .long, help: "Path where the symbol graph file should be written", transform: { $0 })
1818
var outputPath: String = "openapi.symbolgraph.json"
1919

20+
@Option(name: .long, help: "Name to use for the module in the symbol graph", transform: { $0 })
21+
var moduleName: String?
22+
2023
mutating func run() throws {
2124
// Check file extension
2225
let fileExtension = URL(fileURLWithPath: inputPath).pathExtension.lowercased()
@@ -37,7 +40,7 @@ struct OpenAPIToSymbolGraph: ParsableCommand {
3740
let document = try parser.parse(fileContent)
3841

3942
// Convert to symbol graph
40-
let converter = Integration.OpenAPIDocCConverter()
43+
let converter = Integration.OpenAPIDocCConverter(moduleName: moduleName)
4144
let symbolGraph = converter.convert(document)
4245

4346
// Write the symbol graph to file

Sources/DocC/Generators/SymbolGraphGenerator.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import SymbolKit
44

55
/// A generator that converts OpenAPI documents to DocC symbol graphs
66
public struct SymbolGraphGenerator {
7+
/// The name to use for the module
8+
public var moduleName: String?
9+
710
/// Creates a new symbol graph generator
8-
public init() {}
11+
public init(moduleName: String? = nil) {
12+
self.moduleName = moduleName
13+
}
914

1015
/// Generates a symbol graph from an OpenAPI document
1116
/// - Parameter document: The OpenAPI document to convert
@@ -106,14 +111,15 @@ public struct SymbolGraphGenerator {
106111
}
107112

108113
private func createModuleSymbol(from info: Info) -> SymbolKit.SymbolGraph.Symbol {
114+
let moduleName = self.moduleName ?? info.title
109115
let identifier = SymbolKit.SymbolGraph.Symbol.Identifier(
110116
precise: "module",
111117
interfaceLanguage: "openapi"
112118
)
113119

114120
let names = SymbolKit.SymbolGraph.Symbol.Names(
115-
title: info.title,
116-
navigator: [.init(kind: .text, spelling: info.title, preciseIdentifier: nil)],
121+
title: moduleName,
122+
navigator: [.init(kind: .text, spelling: moduleName, preciseIdentifier: nil)],
117123
subHeading: nil,
118124
prose: nil
119125
)
@@ -128,7 +134,7 @@ public struct SymbolGraphGenerator {
128134
return SymbolKit.SymbolGraph.Symbol(
129135
identifier: identifier,
130136
names: names,
131-
pathComponents: [info.title],
137+
pathComponents: [moduleName],
132138
docComment: docComment,
133139
accessLevel: SymbolKit.SymbolGraph.Symbol.AccessControl(rawValue: "public"),
134140
kind: .init(parsedIdentifier: .module, displayName: "Module"),
@@ -292,7 +298,7 @@ public struct SymbolGraphGenerator {
292298

293299
private func createModule(from info: Info) -> SymbolKit.SymbolGraph.Module {
294300
return SymbolKit.SymbolGraph.Module(
295-
name: info.title,
301+
name: self.moduleName ?? info.title,
296302
platform: SymbolKit.SymbolGraph.Platform(
297303
architecture: nil,
298304
vendor: "OpenAPI",

Sources/Integration/OpenAPIDocCConverter.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ import SymbolKit
55

66
/// A converter that converts OpenAPI documents to DocC symbol graphs
77
public struct OpenAPIDocCConverter {
8+
/// The name to use for the module
9+
private let moduleName: String?
10+
811
/// Creates a new OpenAPI to DocC converter
9-
public init() {}
12+
public init(moduleName: String? = nil) {
13+
self.moduleName = moduleName
14+
}
1015

1116
/// Converts an OpenAPI document to a DocC symbol graph
1217
/// - Parameter document: The OpenAPI document to convert
1318
/// - Returns: The DocC symbol graph
1419
public func convert(_ document: Document) -> SymbolKit.SymbolGraph {
15-
let generator = SymbolGraphGenerator()
20+
let generator = SymbolGraphGenerator(moduleName: moduleName)
1621
return generator.generate(from: document)
1722
}
1823
}

scripts/build-docs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mkdir -p docs
66

77
# Convert OpenAPI specification to symbol graph
88
echo "Converting OpenAPI spec to SymbolGraph..."
9-
swift run openapi-to-symbolgraph registry.openapi.yaml --output-path registry.symbolgraph.json
9+
swift run openapi-to-symbolgraph registry.openapi.yaml --output-path registry.symbolgraph.json --module-name "RegistryAPI"
1010

1111
# Generate DocC documentation
1212
echo "Generating DocC documentation..."

0 commit comments

Comments
 (0)