Skip to content

[REQ][Golang][Client] Add *http.Client Accessor #3412

@grokify

Description

@grokify

Is your feature request related to a problem? Please describe.

It can be useful to access the *http.Client directly when certain APIs cannot be currently supported by OpenAPI Generator.

This is currently inaccessible in *APIClient.cfg.HTTPClient

Describe the solution you'd like

An accessor to retrieve the *http.Client for usage.

Describe alternatives you've considered

Option 1

I currently add the following to client.go in all my generated clients:

// HTTPClient returns the HTTP client for direct use.
func (apiClient *APIClient) HTTPClient() *http.Client {
	return apiClient.cfg.HTTPClient
}

Option 2

Add a HTTPClient accessor to APIClient so it does not have to be first retrieved.

For example:

type APIClient struct {
	cfg        *Configuration
        HTTPClient *http.Client // proposed
...

func NewAPIClient(cfg *Configuration) *APIClient {
	if cfg.HTTPClient == nil {
		cfg.HTTPClient = http.DefaultClient
	}

	c := &APIClient{}
	c.cfg = cfg
        c.HTTPClient = cfg.HTTPClient // proposed
...

Additional context

None.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions