OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.39k stars 6.47k forks source link

[BUG][Swift] Generated code won't compile in Swift 6 #19366

Open r3econ opened 1 month ago

r3econ commented 1 month ago
Description

The swift5 generator generates code that won't compile under Swift 6. All static variables generate. This can be already seen as a warning when Strict Concurrency mode is activated in the project:

Reference to class property 'basePath' is not concurrency-safe because it involves shared
mutable state; this is an error in Swift 6
  1. Is there a generator that generates Swift 6 code. If not, are there any plans to implement it?
  2. Where can we find the source code of the Swift 5 generator? I can't find it in this repo nor in the docs. I am asking since potentially we could help develop the Swift 6 version of it
Generated code
SCR-20240816-kmzx
Usage showing the warning
SCR-20240816-knol
openapi-generator version

7.7.0

4brunu commented 5 hours ago

Hi, https://github.com/OpenAPITools/openapi-generator/pull/19621 was just merged, and it should fix this. The new swift6 generator it's experimental, because we are open to receive feedback com the community on how to improve it. So if you have any feedback, it's welcome. All the static classes we moved to singletons to make the compiler happy. Also we have a lot of @unchecked sendable. I'm not super happy with those, and I hope that we receive improvements from the community on how to fix thoses, because I'm not sure yet on what's the best way to manage those.