I am working on generating an http client library from an API specification which is in open api format.
The command I am using to generate this is similar to this
openapi-generator generate -g go -i spec.yaml -o code-gen-go -p packageName=mypackage
This creates a struct like the one below in the generated code
type Configuration struct {
Host string `json:"host,omitempty"`
Scheme string `json:"scheme,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Debug bool `json:"debug,omitempty"`
Servers ServerConfigurations
OperationServers map[string]ServerConfigurations
HTTPClient *http.Client
}
where HTTPClient
field here will be used to make requests. Ideally, one should import this package, assign a client to the HTTPClient
field and they should be able to make http requests via this.
But in my case, I have to use a custom library to make requests. Let's say my library is customHttp
. I have to use this library to create a client of the type *customHttp.Client
( which is simply a client of type *http.Client
but with some additional plugins ). How can I do this? Is it possible to do this without manually updating the auto-generated code?
I figure if I can get it to generate code that the type of HTTPClient
is an interface that implements Do
method, I will be able to assign my client with it? but I could not figure out how to do that either.