diff --git a/Package.swift b/Package.swift index 22c4173f..937b3c92 100644 --- a/Package.swift +++ b/Package.swift @@ -55,13 +55,13 @@ let package = Package( // Generate Swift code .package( url: "https://github.com/apple/swift-syntax.git", - from: "508.0.1" + "508.0.1"..<"510.0.0" ), // Format Swift code .package( url: "https://github.com/apple/swift-format.git", - from: "508.0.1" + "508.0.1"..<"510.0.0" ), // General algorithms diff --git a/Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift b/Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift index e2672c0f..49d8c317 100644 --- a/Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift +++ b/Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift @@ -39,10 +39,15 @@ extension String { assumingFileURL: nil, to: &formattedString ) { diagnostic, sourceLocation in + #if canImport(SwiftSyntax509) + let location = "\(sourceLocation.line):\(sourceLocation.column)" + #else + let location = "\(sourceLocation.debugDescription)" + #endif print( """ === - Formatting the following code produced diagnostic at location \(sourceLocation.debugDescription) (see end): + Formatting the following code produced diagnostic at location \(location) (see end): --- \(self.withLineNumberPrefixes) --- diff --git a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift index 604b33f2..060e7c5b 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift @@ -45,7 +45,11 @@ class FileBasedReferenceTests: XCTestCase { } func testPetstore() throws { + #if canImport(SwiftSyntax509) try _test(referenceProject: .init(name: .petstore)) + #else + XCTFail("Update SwiftFormat to at least 509 to run this test.") + #endif } // MARK: - Private diff --git a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift index 46b60606..c908f54a 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/Resources/ReferenceSources/Petstore/Client.swift @@ -49,7 +49,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.listPets.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/pets", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get) suppressMutabilityWarning(&request) try converter.setQueryItemAsURI( @@ -144,7 +145,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.createPet.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/pets", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post) suppressMutabilityWarning(&request) try converter.setHeaderFieldAsJSON( @@ -225,7 +227,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.createPetWithForm.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets/create", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/pets/create", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post) suppressMutabilityWarning(&request) let body: OpenAPIRuntime.HTTPBody? @@ -253,7 +256,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.getStats.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets/stats", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/pets/stats", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .get) suppressMutabilityWarning(&request) converter.setAcceptHeader(in: &request.headerFields, contentTypes: input.headers.accept) @@ -302,7 +306,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.postStats.id, - serializer: { input in let path = try converter.renderedPath(template: "/pets/stats", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/pets/stats", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post) suppressMutabilityWarning(&request) let body: OpenAPIRuntime.HTTPBody? @@ -342,7 +347,8 @@ public struct Client: APIProtocol { try await client.send( input: input, forOperation: Operations.probe.id, - serializer: { input in let path = try converter.renderedPath(template: "/probe/", parameters: []) + serializer: { input in + let path = try converter.renderedPath(template: "/probe/", parameters: []) var request: HTTPTypes.HTTPRequest = .init(soar_path: path, method: .post) suppressMutabilityWarning(&request) return (request, nil) diff --git a/docker/docker-compose.2204.510.yaml b/docker/docker-compose.2204.510.yaml index 11d11b45..c6defa41 100644 --- a/docker/docker-compose.2204.510.yaml +++ b/docker/docker-compose.2204.510.yaml @@ -11,7 +11,9 @@ services: image: *image environment: - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + # SwiftSyntax currently imports a module it does not explicitly depend + # on and so we must disable this for the time being. + # - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: diff --git a/docker/docker-compose.2204.58.yaml b/docker/docker-compose.2204.58.yaml index 46e65062..8e6f7ef9 100644 --- a/docker/docker-compose.2204.58.yaml +++ b/docker/docker-compose.2204.58.yaml @@ -19,7 +19,11 @@ services: # pipeline. # # - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + + # SwiftSyntax currently imports a module it does not explicitly depend + # on and so we must disable this for the time being. + # - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: diff --git a/docker/docker-compose.2204.59.yaml b/docker/docker-compose.2204.59.yaml index e4dd21a1..b26c61fb 100644 --- a/docker/docker-compose.2204.59.yaml +++ b/docker/docker-compose.2204.59.yaml @@ -12,7 +12,9 @@ services: image: *image environment: - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + # SwiftSyntax currently imports a module it does not explicitly depend + # on and so we must disable this for the time being. + # - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: diff --git a/docker/docker-compose.2204.main.yaml b/docker/docker-compose.2204.main.yaml index d9a4c067..9b940b98 100644 --- a/docker/docker-compose.2204.main.yaml +++ b/docker/docker-compose.2204.main.yaml @@ -19,7 +19,11 @@ services: # pipeline. # # - WARN_AS_ERROR_ARG=-Xswiftc -warnings-as-errors - - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + + # SwiftSyntax currently imports a module it does not explicitly depend + # on and so we must disable this for the time being. + # - IMPORT_CHECK_ARG=--explicit-target-dependency-import-check error + - STRICT_CONCURRENCY_ARG=-Xswiftc -strict-concurrency=complete shell: