Skip to content

Commit 3074113

Browse files
authored
Remove swift-syntax/swift-format as generator dependencies (#343)
Remove swift-syntax/swift-format as generator dependencies ### Motivation The swift-syntax/swift-format dependencies were only used to reformat the code before writing to disk, and significantly increased build and execution times, as well as leading to more dependency graph conflicts for our adopters. Turns out we can relatively easily remove the dependency, so doing that in this PR. ### Modifications Removed swift-format/swift-syntax as dependencies and replaced them with an improved version of `TextBasedRenderer`, which now adds some basic indentation, surprisingly getting us pretty close to the previous formatting. ### Result No more swift-syntax/swift-format dependency, but the generated code still looks very reasonable, and build/execution times should get noticably faster. ### Test Plan Adapted unit tests, integration tests: snippet and file-based tests. All passing now. Reviewed by: glbrntt Builds: ✔︎ pull request validation (5.10) - Build finished. ✔︎ pull request validation (5.8) - Build finished. ✔︎ pull request validation (5.9) - Build finished. ✔︎ pull request validation (compatibility test) - Build finished. ✔︎ pull request validation (docc test) - Build finished. ✔︎ pull request validation (integration test) - Build finished. ✔︎ pull request validation (nightly) - Build finished. ✔︎ pull request validation (soundness) - Build finished. #343
1 parent 193989e commit 3074113

File tree

15 files changed

+2345
-1283
lines changed

15 files changed

+2345
-1283
lines changed

Package.swift

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,6 @@ let package = Package(
5252
],
5353
dependencies: [
5454

55-
// Generate Swift code
56-
.package(
57-
url: "https://github.com/apple/swift-syntax.git",
58-
"508.0.1"..<"510.0.0"
59-
),
60-
61-
// Format Swift code
62-
.package(
63-
url: "https://github.com/apple/swift-format.git",
64-
"508.0.1"..<"510.0.0"
65-
),
66-
6755
// General algorithms
6856
.package(
6957
url: "https://github.com/apple/swift-algorithms",
@@ -105,10 +93,6 @@ let package = Package(
10593
.product(name: "OpenAPIKitCompat", package: "OpenAPIKit"),
10694
.product(name: "Algorithms", package: "swift-algorithms"),
10795
.product(name: "Yams", package: "Yams"),
108-
.product(name: "SwiftSyntax", package: "swift-syntax"),
109-
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
110-
.product(name: "SwiftFormat", package: "swift-format"),
111-
.product(name: "SwiftFormatConfiguration", package: "swift-format"),
11296
],
11397
swiftSettings: swiftSettings
11498
),
@@ -126,9 +110,7 @@ let package = Package(
126110
.testTarget(
127111
name: "OpenAPIGeneratorReferenceTests",
128112
dependencies: [
129-
"_OpenAPIGeneratorCore",
130-
.product(name: "SwiftFormat", package: "swift-format"),
131-
.product(name: "SwiftFormatConfiguration", package: "swift-format"),
113+
"_OpenAPIGeneratorCore"
132114
],
133115
resources: [
134116
.copy("Resources")

Sources/_OpenAPIGeneratorCore/Extensions/Foundation.swift

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@
1313
//===----------------------------------------------------------------------===//
1414
import Foundation
1515

16-
extension Data {
17-
/// A copy of the data formatted using swift-format.
18-
///
19-
/// Data is assumed to contain Swift code encoded using UTF-8.
20-
///
21-
/// - Throws: When data is not valid UTF-8.
22-
var swiftFormatted: Data {
23-
get throws {
24-
let string = String(decoding: self, as: UTF8.self)
25-
return try Self(string.swiftFormatted.utf8)
26-
}
27-
}
28-
}
29-
3016
extension InMemoryInputFile {
3117
/// Creates a new in-memory file by reading the contents at the specified path.
3218
/// - Parameter url: The path to the file to read.
@@ -36,17 +22,6 @@ extension InMemoryInputFile {
3622
}
3723
}
3824

39-
extension InMemoryOutputFile {
40-
/// A copy of the file formatted using swift-format.
41-
public var swiftFormatted: InMemoryOutputFile {
42-
get throws {
43-
var new = self
44-
new.contents = try contents.swiftFormatted
45-
return new
46-
}
47-
}
48-
}
49-
5025
/// File handle to stderr.
5126
let stdErrHandle = FileHandle.standardError
5227

Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift

Lines changed: 0 additions & 63 deletions
This file was deleted.

Sources/_OpenAPIGeneratorCore/GeneratorPipeline.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public func runGenerator(
101101
/// - validator: A validator for parsed OpenAPI documents.
102102
/// - translator: A translator from OpenAPI to Swift.
103103
/// - renderer: A Swift code renderer.
104-
/// - formatter: A Swift code formatter.
105104
/// - config: A set of configuration values for the generator.
106105
/// - diagnostics: A collector to which the generator emits diagnostics.
107106
/// - Returns: A configured generator pipeline that can be executed with
@@ -110,8 +109,7 @@ func makeGeneratorPipeline(
110109
parser: any ParserProtocol = YamsParser(),
111110
validator: @escaping (ParsedOpenAPIRepresentation, Config) throws -> [Diagnostic] = validateDoc,
112111
translator: any TranslatorProtocol = MultiplexTranslator(),
113-
renderer: any RendererProtocol = TextBasedRenderer(),
114-
formatter: @escaping (InMemoryOutputFile) throws -> InMemoryOutputFile = { try $0.swiftFormatted },
112+
renderer: any RendererProtocol = TextBasedRenderer.default,
115113
config: Config,
116114
diagnostics: any DiagnosticCollector
117115
) -> GeneratorPipeline {
@@ -161,9 +159,7 @@ func makeGeneratorPipeline(
161159
diagnostics: diagnostics
162160
)
163161
},
164-
postTransitionHooks: [
165-
formatter
166-
]
162+
postTransitionHooks: []
167163
)
168164
)
169165
}

0 commit comments

Comments
 (0)