OpenAPITools / OpenAPITools/openapi-generator

[BUG][swift5] Missing minimum xcode supported version

Open
#15,058 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Hi,

I ran into an issue with the swift generator, which generated code did not compile.
In the end, it got solved by a simple xcode upgrade (so, to be clear, every thing works fine on the last xcode).

As I did not saw anything about a minimum supported swift version (did I missed it ?) and the errors were very obscure, I thought I would post an issue as it could eventually help others.

Could it be possible to document the minimum versions somewhere ? Or even add it as a requirement of the swift package (I think I saw it was possible but I must admit that I am still a swift newcomer) ?

I actually got 2 errors.
The first one was about a type that could not be used with `any` (something allowed in recent versions of swift)
The second one was about `URLSession` not implementing all functions of `URLSessionProtocol`

That second one is pretty interesting, as it turns out it is due to the `@Sendable`.
At some point in swift's life, the `@Sendable` decorator has been added to the `dataTask` method of `URLSession`.
The `URLSessionProtocol` did not had this decorator, but xcode compiler was able to figure out that the functions were the same and just issued a warning about the missing `@Sendable`.
The warning has been solved by this commit (https://github.com/OpenAPITools/openapi-generator/pull/13906/commits/a9f29a08b9314a7a8fb0534ad554c056b374d412).
But it turns out that, if the new code is used with an older version of xcode/the lib, the compiler considers the `dataTask` function to be different from the one with the `@Sendable` decorator and therefore, ask for the missing implementation of the function without it.

Strangely, the apple's documentation says nothing about a change in this function.

openapi-generator version

6.0.1

Not exactly a regression

OpenAPI declaration file content or url

Not linked to the input file.

Generation Details

Simple generation in swift5
openapi-generator generate -i agent/doc/api.json -g swift5 -o generated

Steps to reproduce

Just try to compile the swift5 code using an "old" xcode.
I forgot the exact version of xcode I was using, but digging through the changelog, I would say any version prior to xcode 14.0 (12/09/2022)

Related issues/PRs

Did not found any similar issues

Suggest a fix

Maybe just a bit of documentation, or eventually some settings within the swift package to inform the compiler of the minimum required versions if that exists.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the swift5 generator and the generated package produced by openapi-generator generate -i agent/doc/api.json -g swift5 -o generated; inspect how its Swift package requirements are declared. Compare compilation on the pre-Xcode 14 versions described in the issue, then document the minimum supported Xcode/Swift versions or add the appropriate package requirement, with a reproducible verification.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
documentation, mobile-dev
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.