-
Notifications
You must be signed in to change notification settings - Fork 125
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
Create a different OpenAPI Handler for each "tag" #691
Comments
Hi @MahdiBM, can you elaborate on why "using multiple targets and filtering a shared openapi file based on tag in each controller" isn't a viable option here? Tags, paths, operationIds are all reasonable ways to group operations, and filtering gives you great flexibility to use them all and even combine them. Using Swift modules here allows you to have full control over the fully qualified protocol name Are there specific issues with using filtering + modules? And if there are issues with Swift modules, should we instead work on addressing those in SwiftPM/the compiler? |
o hmm sorry for 3 different issues. That was network problem and likely GitHub reattempting the creation 3 times.
It is an option, It's just cumbersome.
I guess that could be a theoretical problem, but I think we can just make it work in that case? e.g. add numbers to the names.
I mean, not really, aside from being a bit cumbersome to set up, and requiring a fine amount of knowledge to know how to make it work properly (e.g. I don't presume most newbies know what "symlinks" are, so this will look even more insane to them). |
This should also help for the namings: #683 We could have a "group by" option in the config file and users will be able to declare how to group their routes? |
having multiple modules can also make it a bit weird for the "types". All possible, but ... harder than it should be? |
Is it? I'm not sure that doing this in the generator would result in a significantly better workflow, and we'd be reimplementing features present in the language and package manager. Can you list some of the concrete issues that exist when using the existing language features to achieve the decomposition today? Might make it easier to figure out what we're trying to solve here. |
for 1- it requires someone good at things to figure this out. I don't think any of my colleagues at work could come up with the idea, and 2- figure out how to do it (symlinks, Even if the language already provides the tools and all for this, OpenAPI generator should at the minimum have some docs about it, and optimally have some kind of commands (command plugin?) to trivially to this. (To be clear, OpenAPI Generator has pretty good docs already, and I appreciate that 🙂) |
Right, that makes sense - I'm happy for us to document this workflow better. Would you want to open a PR? Or at least describe the workflow you're using in more detail, so that we could write a how-to? |
To be clear I have not done this yet anywhere. What I'm thinking about the process, is that it would be something like:
The problem here is that I'd like this to be automated. Perhaps with a command plugin.
Long story short, I can see this turning out to be its own thing in its own package. In the end, I still think having a config option in the yaml file like As someone who has tried selling OpenAPI to multiple people, as I believe in its value specially for bigger projects and in the longer term, the worst parts OpenAPIGenerator is how harder it is to use compared to just creating the routes right away in the Vapor / Hummingbird app. This will make things even more complicated and harder to use, as you'd need to learn yet another thing, as opposed to just getting everything for free after using the group-by field. |
Thanks for the thoughtful description of the workflow. I'm even more convinced now that it should be its own separate tool, as it builds purely on top of Swift OpenAPI Generator, it doesn't use any of its internals. So it should be at least a separate module/plugin, but arguably a separate package. It also sounds like package generation, I wonder if the Vapor CLI wouldn't be a good place for this? As a flavor of a generated package, one that integrates OpenAPI and splits per-tag into separate modules? I think one advantage of splitting your service into subcomponents, like controllers, is that you could iterate on them separately, test them separately, and they should be allowed to have distinct dependencies. That's why I think separate modules for each tag is the right way to scale a service, and you're right that configuring a package this way could use some automation. Unclear for now whether this must be in this project, or could be done separately. What do you think, would this fit into Vapor's CLI? |
For 1, the Vapor CLI is pretty much deprecated. It used to have some usecases but Swift itself has grown to support those. Also this doesn't really seem like Vapor related anyway ... Like Hummingbird users might also want to do this? Another thing is that we'd want to have some kind of support for adding plugins to packages through Swift CLI (e.g. Also Swift's current situation for working with sub-processes is a little bit suboptimal until those new So ... I guess doable although it'll take a lot of work? |
Motivation
The generator currently only creates one big OpenAPI Handler protocol.
This makes it hard to organize the routes.
Proposed solution
Create a different OpenAPI Handler for each "tag" so we have something close to Vapor "controllers".
These are quite useful for decluttering the code.
The generator could also generate each tag's "controller protocol" in it's own file. There are known issues in the Swift compiler where it struggles to handle one big file, or makes builds potentially extremely slower.
Alternatives considered
Manually handling this by different methods, including manually creating controllers and redirecting the routes in the main openapi handler to those controllers, or using multiple targets and filtering a shared openapi file based on tag in each controller.
Additional information
No response
The text was updated successfully, but these errors were encountered: