You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you may be aware, it is a documented best practice in Go for context.Context to be passed as a first argument to a function, rather than a field in a struct.
The current implementation does not follow this practice, as shown below.
I appreciate that the project may have a long history which predates this practice and maybe even wider context adoption where the current implementation was a way of making context optional - which is all totally fair! I don't think that in most "modern" libraries context is optional anymore. If the library is making a request to an API, the consumer needs to have a way of cancelling it because it rarely makes sense to wait forever or for some internal default timeout.
I also understand that there is cost of making such a change now as it implies breaking stuff for existing users. However, I wonder if this could possibly be gated behind a feature (CLI) flag of some kind and/or rolled out eventually as default in v1 in the future, where users would more likely expect breaking changes?
To add to this, Context is a perfectly legal parameter name (as are Timeout and HTTPClient). Putting anything in the parameter struct other than the actual parameters to the operation can result in name conflicts with both parameters and their accessor functions, and in fact I just ran into that problem: I have client code that won't compile because the API defines a context param, and thus Context, WithContext, and SetContext are all defined twice.
Problem statement
As you may be aware, it is a documented best practice in Go for
context.Context
to be passed as a first argument to a function, rather than a field in a struct.The current implementation does not follow this practice, as shown below.
I appreciate that the project may have a long history which predates this practice and maybe even wider context adoption where the current implementation was a way of making context optional - which is all totally fair! I don't think that in most "modern" libraries context is optional anymore. If the library is making a request to an API, the consumer needs to have a way of cancelling it because it rarely makes sense to wait forever or for some internal default timeout.
I also understand that there is cost of making such a change now as it implies breaking stuff for existing users. However, I wonder if this could possibly be gated behind a feature (CLI) flag of some kind and/or rolled out eventually as default in v1 in the future, where users would more likely expect breaking changes?
Swagger specification
Steps to reproduce
Generate client code
Open
./client/operations/operations_client.go
Open
./client/operations/list_products_parameters.go
Environment
swagger version: v0.30.5
go version: go1.21.5
OS: darwin/arm64
The text was updated successfully, but these errors were encountered: