swift-openapi-generator icon indicating copy to clipboard operation
swift-openapi-generator copied to clipboard

Divide the yaml generation into several controllers

Open gulivero1773 opened this issue 7 months ago • 7 comments

Question

I have one opeanapi file, in this file I have many tags, and one of tags have admin tag (access only for admin), but when xcode generate it in one file I don't know how use divide for this controller

gulivero1773 avatar Jun 12 '25 08:06 gulivero1773

Hi @gulivero1773,

you have two options here:

  1. Split the implementation across multiple files, each having an extension MyHandler that adds a few more operations.
  2. Split the implementation across multiple Swift modules, by using filtering and only generating a subset of the API in each module, and then registering the multiple API handlers onto the same server. More complicated setup, but allows for better modularization.

czechboy0 avatar Jun 12 '25 10:06 czechboy0

Maybe example you know for 2?

gulivero1773 avatar Jun 12 '25 12:06 gulivero1773

Not an exact example, but this one shows having multiple modules, all using OpenAPI, and a symlink to a single copy in the repo, each with a different config file: https://github.com/apple/swift-openapi-generator/tree/main/Examples/shared-types-client-server-example

And in each config file you'd filter to a different subset of the operations/tags that you want to include there.

czechboy0 avatar Jun 12 '25 13:06 czechboy0

Maybe example you know for 2?

I have an example that uses filtering. Might not be the best but it works. https://github.com/Altered-Tech/swift-petstore-oas

Has the openapi spec in Sources/ then different targets for each operationId. I was experimenting with creating an aws lambda for each operation.

alteredtech avatar Jun 13 '25 05:06 alteredtech

Thanks @alteredtech - yes that's exactly the setup I had in mind.

czechboy0 avatar Jun 13 '25 06:06 czechboy0

Thank you, this - https://github.com/Altered-Tech/swift-petstore-oas help me, but if my package (AddPet and GetPetById) have shared service or repository, for me It's hard to understand how to do it better.

gulivero1773 avatar Jun 13 '25 15:06 gulivero1773

https://github.com/Altered-Tech/swift-petstore-oas show example for code if it not use shared code

gulivero1773 avatar Jun 13 '25 15:06 gulivero1773