Skip to content

Update swift-format version to 5.9 #175

Closed
@takeshi-1000

Description

@takeshi-1000

It seems that the following source code of Petstore was not properly formatted.

deserializer: { request, metadata in let path: Operations.listPets.Input.Path = .init()

The source code inside swift-openapi-generator seems fine and I've confirmed that if I raise the swift-format version to the current commit revision, it's formatted properly. There seems to be no release version currently available on the swift-format side, so I open this issue.

If you want to check, change the code as below,

--- a/Package.swift
+++ b/Package.swift
@@ -52,7 +52,7 @@ let package = Package(
         // Format Swift code
         .package(
             url: "https://github.com/apple/swift-format.git",
-            from: "508.0.1"
+            revision: "8337523533bbd153cdac74c8fff4a1ac79a0b805"
         ),
 
         // General algorithms

and when you build it, an error will occur due to the change in the swift-format interface. (around here)

/path/to/swift-openapi-generator/Sources/_OpenAPIGeneratorCore/Extensions/SwiftFormat.swift:44:100: error: value of type 'SourceLocation' has no member 'debugDescription'
                    Formatting the following code produced diagnostic at location \(sourceLocation.debugDescription) (see end):

If you change the above code appropriately so that the build passes, and run the test, the output will be as follows.

diff --git a/ReferenceSources/Petstore/Server.swift b/var/folders/nn/80g9wmmd37lc63c9wqtnspj40000gp/T/5705E10F-715B-4E33-8295-2090E9E2FA85/Server.swift
index cd60e0c..fc5d004 100644
--- a/ReferenceSources/Petstore/Server.swift
+++ b/var/folders/nn/80g9wmmd37lc63c9wqtnspj40000gp/T/5705E10F-715B-4E33-8295-2090E9E2FA85/Server.swift
@@ -81,11 +81,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.listPets.id,
             using: { APIHandler.listPets($0) },
-            deserializer: { request, metadata in let path: Operations.listPets.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.listPets.Input.Path = .init()
                 let query: Operations.listPets.Input.Query = .init(
                     limit: try converter.getOptionalQueryItemAsText(
                         in: metadata.queryParameters,
                         name: "limit",
                         as: Swift.Int32.self
@@ -180,11 +181,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.createPet.id,
             using: { APIHandler.createPet($0) },
-            deserializer: { request, metadata in let path: Operations.createPet.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.createPet.Input.Path = .init()
                 let query: Operations.createPet.Input.Query = .init()
                 let headers: Operations.createPet.Input.Headers = .init(
                     X_Extra_Arguments: try converter.getOptionalHeaderFieldAsJSON(
                         in: request.headerFields,
                         name: "X-Extra-Arguments",
@@ -273,11 +275,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.getStats.id,
             using: { APIHandler.getStats($0) },
-            deserializer: { request, metadata in let path: Operations.getStats.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.getStats.Input.Path = .init()
                 let query: Operations.getStats.Input.Query = .init()
                 let headers: Operations.getStats.Input.Headers = .init()
                 let cookies: Operations.getStats.Input.Cookies = .init()
                 return Operations.getStats.Input(
                     path: path,
@@ -317,11 +320,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.postStats.id,
             using: { APIHandler.postStats($0) },
-            deserializer: { request, metadata in let path: Operations.postStats.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.postStats.Input.Path = .init()
                 let query: Operations.postStats.Input.Query = .init()
                 let headers: Operations.postStats.Input.Headers = .init()
                 let cookies: Operations.postStats.Input.Cookies = .init()
                 let contentType = converter.extractContentTypeIfPresent(in: request.headerFields)
                 let body: Operations.postStats.Input.Body
@@ -367,11 +371,12 @@ fileprivate exte
nsion UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.probe.id,
             using: { APIHandler.probe($0) },
-            deserializer: { request, metadata in let path: Operations.probe.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.probe.Input.Path = .init()
                 let query: Operations.probe.Input.Query = .init()
                 let headers: Operations.probe.Input.Headers = .init()
                 let cookies: Operations.probe.Input.Cookies = .init()
                 return Operations.probe.Input(
                     path: path,
diff --git a/ReferenceSources/Petstore_FF_MultipleContentTypes/Server.swift b/var/folders/nn/80g9wmmd37lc63c9wqtnspj40000gp/T/38A9C041-0D2B-4E2C-B842-F2A186367B2F/Server.swift
index 1a3753f..ffc0365 100644
--- a/ReferenceSources/Petstore_FF_MultipleContentTypes/Server.swift
+++ b/var/folders/nn/80g9wmmd37lc63c9wqtnspj40000gp/T/38A9C041-0D2B-4E2C-B842-F2A186367B2F/Server.swift
@@ -81,11 +81,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.listPets.id,
             using: { APIHandler.listPets($0) },
-            deserializer: { request, metadata in let path: Operations.listPets.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.listPets.Input.Path = .init()
                 let query: Operations.listPets.Input.Query = .init(
                     limit: try converter.getOptionalQueryItemAsText(
                         in: metadata.queryParameters,
                         name: "limit",
                         as: Swift.Int32.self
@@ -180,11 +181,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.createPet.id,
             using: { APIHandler.createPet($0) },
-            deserializer: { request, metadata in let path: Operations.createPet.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.createPet.Input.Path = .init()
                 let query: Operations.createPet.Input.Query = .init()
                 let headers: Operations.createPet.Input.Headers = .init(
                     X_Extra_Arguments: try converter.getOptionalHeaderFieldAsJSON(
                         in: request.headerFields,
                         name: "X-Extra-Arguments",
@@ -273,11 +275,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.getStats.id,
             using: { APIHandler.getStats($0) },
-            deserializer: { request, metadata in let path: Operations.getStats.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.getStats.Input.Path = .init()
                 let query: Operations.getStats.Input.Query = .init()
                 let headers: Operations.getStats.Input.Headers = .init()
                 let cookies: Operations.getStats.Input.Cookies = .init()
                 return Operations.getStats.Input(
                     path: path,
@@ -337,11 +340,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.postStats.id,
             using: { APIHandler.postStats($0) },
-            deserializer: { request, metadata in let path: Operations.postStats.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.postStats.Input.Path = .init()
                 let query: Operations.postStats.Input.Query = .init()
                 let headers: Operations.postStats.Input.Headers = .init()
                 let cookies: Operations.postStats.Input.Cookies = .init()
                 let contentType = converter.extractContentTypeIfPresent(in: request.headerFields)
let body: Operations.postStats.Input.Body
@@ -405,11 +409,12 @@ fileprivate extension UniversalServer where APIHandler: APIProtocol {
         try await handle(
             request: request,
             with: metadata,
             forOperation: Operations.probe.id,
             using: { APIHandler.probe($0) },
-            deserializer: { request, metadata in let path: Operations.probe.Input.Path = .init()
+            deserializer: { request, metadata in
+                let path: Operations.probe.Input.Path = .init()
                 let query: Operations.probe.Input.Query = .init()
                 let headers: Operations.probe.Input.Headers = .init()
                 let cookies: Operations.probe.Input.Cookies = .init()
                 return Operations.probe.Input(
                     path: path,

Please note that the above behavior is the behavior of the current main branch of swift-format and is subject to change.

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/generatorAffects: plugin, CLI, config file.kind/enhancementImprovements to existing feature.size/SSmall task. (A couple of hours of work.)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions