apple / swift-openapi-generator

Generate Swift client and server code from an OpenAPI document.
https://swiftpackageindex.com/apple/swift-openapi-generator/documentation
Apache License 2.0
1.21k stars 87 forks source link

OpenAPI shared components #564

Open hrabkin opened 2 weeks ago

hrabkin commented 2 weeks ago

Question

How to union generated shared components from two different openapi sepcifications?

czechboy0 commented 2 weeks ago

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 accessModifier: package (or public), you can then have a third Swift module that imports the first two, and uses types from both.

Are you writing a client or a server? Can you add more details on what you're trying to do?

czechboy0 commented 2 weeks ago

I'm trying to understand whether this is essentially a duplicate of https://github.com/apple/swift-openapi-generator/issues/132 or if that doesn't work for you for some reason.

hrabkin commented 2 weeks ago

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.

simonjbeaumont commented 2 weeks ago

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 #/components/schemas, then these will use the same type. Or are you saying you two independent services in the one YAML file?

Would you be able to provide a minimal example to help us understand better?