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

Multiple OpenAPI spec files #132

Closed
daliad007 opened this issue Jul 19, 2023 · 9 comments
Closed

Multiple OpenAPI spec files #132

daliad007 opened this issue Jul 19, 2023 · 9 comments
Labels
status/triage Collecting information required to triage the issue.

Comments

@daliad007
Copy link

Hello,

Would like to know if it's currently possible to use the package with more than one specification file. This is needed in our project as we'd look at consuming multiple services.

Thank you!

@czechboy0
Copy link
Collaborator

Hi @daliad007, yes you can put one OpenAPI document into each target, so it's best to follow this strategy, and then import the targets with generated code into your target that uses the generated code.

@czechboy0 czechboy0 added kind/proposal Proposals for review. status/triage Collecting information required to triage the issue. and removed kind/proposal Proposals for review. labels Jul 19, 2023
@daliad007
Copy link
Author

daliad007 commented Jul 20, 2023

That makes sense @czechboy0 Looking at the doc, it seems it's also possible to generate the client in your own Swift package. So, in this case there could be multiple packages consuming each its own service. The packages would then be imported into our target.

@czechboy0
Copy link
Collaborator

Exactly. You don't need a whole package for each, you can have a separate target for each document, all within the same package. But the point stands, you should be able to talk to any number of services from your client using the generated code.

@czechboy0 czechboy0 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2023
@sureshjoshi
Copy link

Is there anything that prevents multiple OpenAPI specs from running in a single target? Like, let's say we generate them in separate targets - but then have some sort of copy command to have them run in a single target. I believe they're namespaced out, other than a handful of common files?

I'm wondering because I've been having a bit of a nightmare of a time creating a binary framework package since Xcode 14.3 when I have multiple targets, but it appears to work fine with a single target.

Trying to workaround this problem in the short term until I can figure out the long term solution.

@czechboy0
Copy link
Collaborator

Are you using the generated types in the public API of the binary framework? If you avoid that, and use @_implementationOnly import when importing the modules with the generated code, it should all work well even with many modules imported from the module of the framework.

@sureshjoshi
Copy link

@czechboy0 Thanks! That was very helpful information - there appeared to be something else wrong in 14.3.1 that magically disappeared in 15.0 (didn't even change my code/scripts 🤷🏽 ).

For anyone checking this out later, you'll probably want to @_implementationOnly the OpenAPI libs, as well as your generated target (if not used in the public interface).

@_implementationOnly import MyGeneratedAPI
import Foundation
@_implementationOnly import OpenAPIRuntime
@_implementationOnly import OpenAPIURLSession

@czechboy0
Copy link
Collaborator

@sureshjoshi, yes, but only if you're building with library evolution mode enabled.

@hrabkin
Copy link

hrabkin commented Apr 18, 2024

@czechboy0 I used the approach and created a separate package but now in my product's target I face an issue with internal access of generated Components.Schema from the library. What the reason to generate internal accessible model if I can't use it inside my product? Is there way I can get at least raw format and decode it into a product's model?

@hrabkin
Copy link

hrabkin commented Apr 18, 2024

Nevermind, I found his thread which resolved my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/triage Collecting information required to triage the issue.
Projects
None yet
Development

No branches or pull requests

4 participants