Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][Swift6] Numerous compilation issues with Swift 6 generator + Alamofire 5.10.x #20398

Open
3 of 5 tasks
lilidotshi opened this issue Jan 3, 2025 · 4 comments
Open
3 of 5 tasks

Comments

@lilidotshi
Copy link
Contributor

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Updating to Alamofire 5.10.x causes multiple compilation issues around Sendable.

In particular, the following classes have issues:

Class Error
extension JSONDataEncoding Conformance to 'Sendable' must occur in the same source file as struct 'JSONDataEncoding'; use '@unchecked Sendable' for retroactive conformance
AnyResponseSerializer Type 'AnyResponseSerializer.SerializedObject' (aka 'T') does not conform to the 'Sendable' protocol
openapi-generator version

7.10.0

Generation Details

This is one of the Infrastructure files generated along with any scheme.

Steps to reproduce

use the Swift 6 generator with the latest alamofire 5.10.x and observe that it does not compile due to a bunch of swift 6 errors

@lilidotshi lilidotshi changed the title [BUG] Numerous compilation issues with Swift 6 generator + Alamofire 5.10.x [BUG][Swift6] Numerous compilation issues with Swift 6 generator + Alamofire 5.10.x Jan 3, 2025
@x-sheep
Copy link
Contributor

x-sheep commented Jan 6, 2025

I looked into this for a bit.

Alamofire 5.10 enforces that all objects used in the request conform to Sendable. The core of the problem is this protocol in Models.swift:

protocol JSONEncodable {
    func encodeToJSON(codableHelper: CodableHelper) -> Any
}

If this protocol gained the requirement that all conforming types also conform to Sendable, this can be fixed by returning any Sendable instead (a new Swift 6 construct). The problem is that the following conditional conformance is impossible:

extension Array: JSONEncodable where Element: Sendable

Sendable is a marker protocol and JSONEncodable is not. So all types that may be used in a request should conform to JSONEncodable instead.

@4brunu
Copy link
Contributor

4brunu commented Jan 8, 2025

Hi, this is a know issue.

// TODO: Alamofire versions 5.10.0 and above are not currently supported. If you need a newer version, please consider submitting a Pull Request with the required changes.
.package(url: "https://github.com/Alamofire/Alamofire", exact: "5.9.1"),

Unfortunately, currently I don't have time to fix this issue, but if anyone can create a PR, I can help with the review and merge.
Thanks.

@x-sheep
Copy link
Contributor

x-sheep commented Jan 8, 2025

@4brunu A question about the current client: Could the JSONEncodable protocol and the encodeToJSON function be removed entirely? I don't know if it's a protocol that should ever be implemented by users, and the client code already compares types directly for different behavior (e.g. using URL for file uploads).

@4brunu
Copy link
Contributor

4brunu commented Jan 8, 2025

That's a good question.
I think we could remove it, and I don't see a reason for the users to implement this protocol.
If it's the only solution, let's try do it, but this is a big change that I would prefer to avoid, because this simplifies the json encoding of each parameter, and I think there is also some default implementation applied to this protocol.
Removing it might not be easy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants