From 551561944175d25b9b0cf4487b227354a66fc6fa Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Fri, 13 Oct 2023 13:04:30 -0400 Subject: [PATCH 1/3] Relax dependency on SwiftFormat. --- Package.swift | 4 ++-- .../Extensions/SwiftFormat.swift | 7 ++++++- .../FileBasedReferenceTests.swift | 6 +++++- .../ReferenceSources/Petstore/Client.swift | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 10 deletions(-) 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..00077540 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift @@ -45,7 +45,11 @@ class FileBasedReferenceTests: XCTestCase { } func testPetstore() throws { - try _test(referenceProject: .init(name: .petstore)) + #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) From 389e421bfa4e3ffa861ca0ad127030905d0b313e Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Sat, 14 Oct 2023 18:04:05 -0400 Subject: [PATCH 2/3] Fix indentation. --- .../FileBasedReferenceTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift index 00077540..060e7c5b 100644 --- a/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift +++ b/Tests/OpenAPIGeneratorReferenceTests/FileBasedReferenceTests.swift @@ -46,9 +46,9 @@ class FileBasedReferenceTests: XCTestCase { func testPetstore() throws { #if canImport(SwiftSyntax509) - try _test(referenceProject: .init(name: .petstore)) + try _test(referenceProject: .init(name: .petstore)) #else - XCTFail("Update SwiftFormat to at least 509 to run this test.") + XCTFail("Update SwiftFormat to at least 509 to run this test.") #endif } From 71834295a3b6fc84e8838d2a634cce258bfa2b8f Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Mon, 16 Oct 2023 08:43:15 -0400 Subject: [PATCH 3/3] Disable explicit-target-dependency-import-check --- docker/docker-compose.2204.510.yaml | 4 +++- docker/docker-compose.2204.58.yaml | 6 +++++- docker/docker-compose.2204.59.yaml | 4 +++- docker/docker-compose.2204.main.yaml | 6 +++++- 4 files changed, 16 insertions(+), 4 deletions(-) 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: