-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[go-experimental] Use builder pattern for requests #4787
Conversation
2fd585b
to
c1b2958
Compare
I recall there was a situation where we may need to specify path, qs, or body parameters as you could have a query or path parameter with the same name as a body parameter, etc: "A unique parameter is defined by a combination of a name and location." The other projects using a builder pattern (Peal notably iirc) would specify this. @wing328 is this something to consider in this new design? I will see if i can find the example. Update: Actually looks like everything has been refactored away from this, so maybe just ignore it. |
Hmm that seems fair. I actually remember having encountered this in our own specs, we had a path parameter that was name I'd be happy to hear about suggestions on how to workaround that though, and implement them in here. |
It does, but so do many of the other clients in other languages. The solution i had seen (i thought was the perl version, but not anymore) was to use something like:
|
The problem with this one is that it still has the problem of generating client that cannot be backward compatible when for example a form parameter is added in the API. This is the main problem I am trying to solve with the approach in this PR. |
c16e669
to
1445adf
Compare
After giving more thought to this, I think the name clashing issue is not too big a problem anyway. It's easily fixable in the specification itself by changing the names of your path parameters for example, and there even is a Also @wing328 or @jimschubert, I'm not too sure what's going on with the circleCI tests, can you advise here ? Thanks all ! |
I've pushed a fix to the master. Please merge the latest master into this branch to resolve the build error. Sorry for the inconvenience caused. |
1445adf
to
8c298cd
Compare
AppVeyor looks like an unrelated issue with sockets closing in the C# client test. |
Bumping, @antihax do you have any other feedback regarding this ? |
I've skimmed this quickly (I'm by no means a Go expert), and I think it looks good. I wonder if we should target the 4.3.x branch because it'll break existing client code (see diff on tests). |
Yeah it will definitely break existing code. I felt like I could given this is the experimental template, but happy to target 4.3.x then. |
@zippolyte for go-experimental (but not other generators), it's ok to have breaking changes in the master. |
Awesome. Then yeah we can merge if there are no other concerns. |
8c298cd
to
0d82b73
Compare
0d82b73
to
4ad0ea6
Compare
@jimschubert OK to merge then ? |
Yeah, since it's been almost a week with no other concerns from contributors I think it's good to go. |
Thanks for merging ! 🙇 |
Implement builder pattern to construct requests and pass all parameters. Similar construct as #4666
The motivation for this is to keep a client that will stay backward compatible in case some required parameters become optional which is not a breaking change in itself, but with the current implementation, it would change the method signature, thus introducing a breaking change in the client upon new generation.
Only path parameters are always required and any change would break the API itself, which is why I left them in the function signature.
cf https://swagger.io/specification/#parameterObject:
Additionally, this removes the use of the
antihax/optional
module for query parameters, as we don't need the explicit null functionality here.cf #522 (comment)
Any feedback/suggestion would be much appreciated.
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.cc @antihax (2017/11) @bvwells (2017/12) @grokify (2018/07) @kemokemo (2018/09) @bkabrda (2019/07)