-
-
Notifications
You must be signed in to change notification settings - Fork 232
Add support for grouping nested operations as class by operation id #2450
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
base: main
Are you sure you want to change the base?
Add support for grouping nested operations as class by operation id #2450
Conversation
|
|
@flow96 is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
@flow96 yes please. I changed those files a lot, you might want to just apply your changes anew |
0f64a10
to
1f4f2bf
Compare
@flow96 Why didn't you use this pattern? #2435 (comment) |
d4f1f27
to
ec7cb7a
Compare
commit: |
@mrlubos I was thinking about that too, but you also mentioned that people currently rely on the current behavior, so I thought it might be better to first introduce it as an optional configuration value with default In my opinion the new output (based on the operationIds) should be the default but I am with you, that there are probably people that rely on the old/current behavior, so changing the default might not be a good choice. But that's just my thoughts, in the end you have to decide :) If you prefer to change the default behavior, I can change it like that and call the config property something like |
No I want this to be the default, it's a question of semantics and providing clear configuration options. You talk about operation IDs, but those are optional keywords in OpenAPI. What happens if there's no operation ID value? I didn't look at the code yet. Just want your thoughts, maybe it'll help with naming. |
Ok, thanks for the input. With tags we have the same issue as before: Endpoints would be consolidated/overwritten if they share the same method name. E.g. the following two endpoints:
The sdk would end up with a single class Providers {
public list() {...}
} Creating nested classes with tags is not easy, because we also cannot rely on the order of the tags to create nested classes. Ordering them ourself might create incorrect nestings. So my suggestion would be to rather try to create a nesting based on the path instead of the tags. Maybe I am wrong here but these were my thoughts during the implementation - that's why I thought it makes more sense to go this way. Sorry for the long text |
Not long at all! I'm going to be obtuse because I didn't fully follow the previous issues, but how do we end up with a single method in your example? We're able to uniquely identify an operation by its path + method, why is that ever an issue?
I believe this is the way. You can't rely on tags alone, and they're also optional.
This will never be acceptable. If I define 10 operations in my spec, I expect 10 (or more) methods in my SDK, no matter what. If I'm getting fewer than that, and it sounds like that's what you're saying, that's not acceptable. Speaking of...
There must be a fallback. This configuration is too brittle otherwise and will be confusing. Imagine you successfully use this feature, and then your API team adds an endpoint without operation ID. Now your client is blocked because it crashes. This issue is the biggest one to resolve imo |
Solves #2435 and #2437
A new sdk config has been added:
groupByOperationId
.When
groupByOperationId: true
andasClass: true
is set on the sdk plugin then the class generation will be based on the operation Id and endpoints won't be overridden by incorrect class re-usage.Example config:
Example schema:
Result
Usage:
When setting
instance: "MySdk"
the result will look like this