Skip to content

Commit d9d5daa

Browse files
authored
Relax dependency on SwiftSyntax and SwiftFormat to 508..<510 (#331)
1 parent 4c8ed5c commit d9d5daa

File tree

8 files changed

+40
-13
lines changed

8 files changed

+40
-13
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ let package = Package(
5555
// Generate Swift code
5656
.package(
5757
url: "https://github.com/apple/swift-syntax.git",
58-
from: "508.0.1"
58+
"508.0.1"..<"510.0.0"
5959
),
6060

6161
// Format Swift code
6262
.package(
6363
url: "https://github.com/apple/swift-format.git",
64-
from: "508.0.1"
64+
"508.0.1"..<"510.0.0"
6565
),
6666

6767
// General algorithms

Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,15 @@ extension String {
3939
assumingFileURL: nil,
4040
to: &formattedString
4141
) { diagnostic, sourceLocation in
42+
#if canImport(SwiftSyntax509)
43+
let location = "\(sourceLocation.line):\(sourceLocation.column)"
44+
#else
45+
let location = "\(sourceLocation.debugDescription)"
46+
#endif
4247
print(
4348
"""
4449
===
45-
Formatting the following code produced diagnostic at location \(sourceLocation.debugDescription) (see end):
50+
Formatting the following code produced diagnostic at location \(location) (see end):
4651
---
4752
\(self.withLineNumberPrefixes)
4853
---

Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ class FileBasedReferenceTests: XCTestCase {
4545
}
4646

4747
func testPetstore() throws {
48+
#if canImport(SwiftSyntax509)
4849
try _test(referenceProject: .init(name: .petstore))
50+
#else
51+
XCTFail("Update SwiftFormat to at least 509 to run this test.")
52+
#endif
4953
}
5054

5155
// MARK: - Private

Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public struct Client: APIProtocol {
4949
try await client.send(
5050
input: input,
5151
forOperation: Operations.listPets.id,
52-
serializer: { input in let path = try converter.renderedPath(template: "/pets", parameters: [])
52+
serializer: { input in
53+
let path = try converter.renderedPath(template: "/pets", parameters: [])
5354
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get)
5455
suppressMutabilityWarning(&request)
5556
try converter.setQueryItemAsURI(
@@ -144,7 +145,8 @@ public struct Client: APIProtocol {
144145
try await client.send(
145146
input: input,
146147
forOperation: Operations.createPet.id,
147-
serializer: { input in let path = try converter.renderedPath(template: "/pets", parameters: [])
148+
serializer: { input in
149+
let path = try converter.renderedPath(template: "/pets", parameters: [])
148150
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post)
149151
suppressMutabilityWarning(&request)
150152
try converter.setHeaderFieldAsJSON(
@@ -225,7 +227,8 @@ public struct Client: APIProtocol {
225227
try await client.send(
226228
input: input,
227229
forOperation: Operations.createPetWithForm.id,
228-
serializer: { input in let path = try converter.renderedPath(template: "/pets/create", parameters: [])
230+
serializer: { input in
231+
let path = try converter.renderedPath(template: "/pets/create", parameters: [])
229232
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post)
230233
suppressMutabilityWarning(&request)
231234
let body: OpenAPIRuntime.HTTPBody?
@@ -253,7 +256,8 @@ public struct Client: APIProtocol {
253256
try await client.send(
254257
input: input,
255258
forOperation: Operations.getStats.id,
256-
serializer: { input in let path = try converter.renderedPath(template: "/pets/stats", parameters: [])
259+
serializer: { input in
260+
let path = try converter.renderedPath(template: "/pets/stats", parameters: [])
257261
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get)
258262
suppressMutabilityWarning(&request)
259263
converter.setAcceptHeader(in: &request.headerFields, contentTypes: input.headers.accept)
@@ -302,7 +306,8 @@ public struct Client: APIProtocol {
302306
try await client.send(
303307
input: input,
304308
forOperation: Operations.postStats.id,
305-
serializer: { input in let path = try converter.renderedPath(template: "/pets/stats", parameters: [])
309+
serializer: { input in
310+
let path = try converter.renderedPath(template: "/pets/stats", parameters: [])
306311
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post)
307312
suppressMutabilityWarning(&request)
308313
let body: OpenAPIRuntime.HTTPBody?
@@ -342,7 +347,8 @@ public struct Client: APIProtocol {
342347
try await client.send(
343348
input: input,
344349
forOperation: Operations.probe.id,
345-
serializer: { input in let path = try converter.renderedPath(template: "/probe/", parameters: [])
350+
serializer: { input in
351+
let path = try converter.renderedPath(template: "/probe/", parameters: [])
346352
var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post)
347353
suppressMutabilityWarning(&request)
348354
return (request, nil)

docker/docker-compose.2204.510.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ services:
1111
image: *image
1212
environment:
1313
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
14-
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
14+
# SwiftSyntax currently imports a module it does not explicitly depend
15+
# on and so we must disable this for the time being.
16+
# - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
1517
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
1618

1719
shell:

docker/docker-compose.2204.58.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ services:
1919
# pipeline.
2020
#
2121
# - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
22-
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
22+
23+
# SwiftSyntax currently imports a module it does not explicitly depend
24+
# on and so we must disable this for the time being.
25+
# - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
26+
2327
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
2428

2529
shell:

docker/docker-compose.2204.59.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ services:
1212
image: *image
1313
environment:
1414
- WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
15-
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
15+
# SwiftSyntax currently imports a module it does not explicitly depend
16+
# on and so we must disable this for the time being.
17+
# - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
1618
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
1719

1820
shell:

docker/docker-compose.2204.main.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ services:
1919
# pipeline.
2020
#
2121
# - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors
22-
- IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
22+
23+
# SwiftSyntax currently imports a module it does not explicitly depend
24+
# on and so we must disable this for the time being.
25+
# - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error
26+
2327
- STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete
2428

2529
shell:

0 commit comments

Comments
 (0)