apple / apple/swift-openapi-generator

Importing a framework with a generated client

Open
#767 7 comments 0 reactions 0 assignees View on GitHub
kind/support status/triage
Dominant language
Swift
Stars
2k
Forks
182
Avg merge
13h 28m
Merged PRs (30d)
5

Description

### Question

Great project, thanks for working on it!

I have a fairly large openapi spec (22k+ lines) that I use to generate a client with. The resulting `Client.swift` is 21k lines and `Types.swift` is 90k lines. Takes a good while to compile, like drink my coffee long. To avoid slowing down the compilation of projects that use the generated client, I created a framework (F) with the generated client that I distribute as a binary framework. I can import (F) into my app project (A).

The issue I am running into is that both generated swift files import OpenAPIRuntime on the very first line:

@_spi(Generated) import OpenAPIRuntime

Hence, I have to add OpenAPIRuntime as a dependency to my framework (F) project. So far so good, I will not add OpenAPIRuntime as a dependency to (A) to avoid the issue described below. However, I do have to add OpenAPIURLSession as a dependency to (A). That also depends on OpenAPIRuntime, so it pulls it in as a transitive dependency.

Net-net, when I run the app I see log messages:

objc[1426]: Class _TtC17OpenAPIURLSession40BidirectionalStreamingURLSessionDelegate is implemented in both
/private/var/containers/Bundle/Application/02BB3430-E963-422B-9938-F07FFAB45EC4/A.app/Frameworks/F.framework/F (0x1032ed228) and
/private/var/containers/Bundle/Application/02BB3430-E963-422B-9938-F07FFAB45EC4/A.app/A.debug.dylib (0x1039116d0).
One of the two will be used. Which one is undefined.

The client and the app still works, it's mostly cosmetic that every time the app starts up, the console is flooded with tons of these messages. I have exhausted all my options to remedy this. Do you have any ideas how to resolve this? Thx

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the setup with the generated Client.swift and Types.swift files, framework F, app A, OpenAPIRuntime, and OpenAPIURLSession. Inspect how the runtime is included in both the binary framework and app dependencies; done means the client still works without duplicate-class messages at app startup.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
developer-experience, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.