-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
[go] Fixes problems with conflicting parameters #5963
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
Conversation
|
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
0fa7430 to
0b5bac1
Compare
d17aad5 to
f21e61d
Compare
|
Rebased to current master. Any changes needed here? |
e42ca5b to
d70a36d
Compare
6ee5ceb to
2474f9f
Compare
|
Rebased. Bump? |
|
@thiagoarrais thanks for the PR and sorry for taking so long to review it. I'll try to review later this week and let you know if I've any question/feedback. Btw, is there a minimal spec to more easily reproduce the issue? |
|
Yup. There is one in |
2474f9f to
57b4d82
Compare
|
As I understand |
|
By the way, this is a breaking change for some cases considering the old |
|
Thanks for the additional information. I'll try to review tomorrow or later this week. |
57b4d82 to
5ecf705
Compare
5ecf705 to
96aefaf
Compare
|
Rebased |
96aefaf to
53a64da
Compare
|
Rebased to current master |
53a64da to
487f6a3
Compare
|
Rebased to current master. Don't know if the circleci failure is related. Friendly ping, @wing328: do you think this is mergeable? |
487f6a3 to
3e98d08
Compare
|
Rebased to current master. Just noticed that this is now partially solved in master. Somewhere between 8afb067 and 79395de a disambiguating suffix was added to parameter names. It makes the resulting client compilable for most cases. "Most" because it seems to assume that disambiguation only needs to happen for path parameters. But the same parameter name can happen in form, query, cookie or headers parameters. Even though it is compilable for most cases, I think it can be yet a little more friendly (and this PR provides some of that). Here is the difference on the output from before and after this PR. Before (master): type ApiCreateRequest struct {
id int32
id2 *int32
id2 *int32
id2 *int32
id2 *int32
/* ... */
}
func (r ApiCreateRequest) Id2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) Id2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) Id2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) Id2(id2 int32) ApiCreateRequest { /* ... */ }After (this PR as is): type ApiCreateRequest struct {
pathid int32
headerid2 *int32
cookieid2 *int32
queryid2 *int32
formid2 *int32
/* ... */
}
func (r ApiCreateRequest) HeaderId2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) CookieId2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) QueryId2(id2 int32) ApiCreateRequest { /* ... */ }
func (r ApiCreateRequest) Id2(id2 int32) ApiCreateRequest { /* ... */ }The version currently on master detects that parameter names conflict with the path parameter name and adds a disambiguating numerical suffix. This PR adds an easier to locate namespace preffix to the parameters (except for the form parameter, which I've assumed is the most common one and chosen to award with the no-preffix namespace). We can make the resulting API even more clear by removing the suffix. I can add that to this PR if there is interest. |
3e98d08 to
fb6aa0d
Compare
OpenAPI allows parameters to bear the same name if they appear in different settings inside the same operation. The code generated by the go-experimental generator, though, could sometimes fail to compile due to parameters with the same name. Both the field in the api*Request struct and the setter method names can clash if there are multiple parameteres with the same name. This change fixes that by namespacing all the param names in the generated code with their origin.
fb6aa0d to
90acaca
Compare
|
As discussed in #8762 |
OpenAPI allows parameters to bear the same name if they appear in different settings inside the same operation.
The code generated by the
go-experimentalgo generator, though, can sometimes fail to compile due to parameters with the same name. Both the field in theapi*Requeststruct and the setter method names can clash if there are multiple parameteres with the same name.This change fixes that by namespacing all the param names in the generated code with their origin.
This may also affect the stable Go generator because it messes with setExportParameterName, even though I've tried to limit my changes to the internal parts of the generated code. Please review accordingly.Update: this PR was written before
go-experimentalgraduated to become the main go client and was edited accordingly.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.shif 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 @bvwells @grokify @kemokemo @bkabrda