-
Notifications
You must be signed in to change notification settings - Fork 124
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
Shared components between multiple OpenAPI documents #564
Comments
Hi @hrabkin, can you clarify what you mean by "union"? You can generate content from two OpenAPI documents into two Swift modules, and if you add Are you writing a client or a server? Can you add more details on what you're trying to do? |
I'm trying to understand whether this is essentially a duplicate of #132 or if that doesn't work for you for some reason. |
No its not a duplicate. Its a different issue, that one not related. So I have two apis described in openapi yaml: A -> which have some shared components S, and B which uses the same shared components S. I generate two libraries from the yamls and of course there are two duplicate types now AS and BS. |
I'm not sure I understand. If by "two apis" you mean you have two operations in the OpenAPI document that make use of the same type in Would you be able to provide a minimal example to help us understand better? |
I’m facing a similar issue and would appreciate some guidance. We have two separate JSON files, each defining the same "User" component. These components are currently in different modules but represent the same entity. I'm looking for a way to unify them, so I can use just one. For example: - Module Address: - Module Car: However, in my code, I can’t do the following: |
@Inshaki the types generated in different modules are distinct, and there's no way to unify them. Can you confirm if these are separated into separate files because they are separate services or just because you want to spread the definition of your single API service across multiple files. If it's the former, you'll need to restructure to separate the shared types into their own OpenAPI doc, generate in their own shared target, and use If it's the latter, then Swift OpenAPI Generator only supports a single
I can't really tell which of these it is from this example. Do you have a CarAPI and an AddressAPI (probably not), or do you have a single API that makes use of cars and addresses, that both have users? (Just a logistical note here that I'm about to head out for a long weekend so you might not hear from me until Tuesday). |
The CarModule and AddressModule are indeed separate modules (within the same backend though), each with its own set of APIs. However, they share some common models like User. While creating a shared OpenAPI document seems like a solid approach, we prefer not to modify the existing JSON files directly. Given this, would it be possible to set up the shared components without altering the original JSON files? If so, how would you recommend structuring this? Any further guidance would be greatly appreciated. |
If the set of OpenAPI document JSON files you have to hand constitute the API definition of a single backend, then you will need to preprocess them as input to Swift OpenAPI Generator since it only supports a single OpenAPI document as input, named either You will likely need to use another tool for this as part of your build pipeline, e.g. |
I suspect this would also be helped by #25, as it'd allow actually generating a single copy of the shared types, and they'd be referenced from both modules. |
Question
How to union generated shared components from two different openapi specifications?
The text was updated successfully, but these errors were encountered: