Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3412
Closed
Open
Issue created Jul 22, 2019 by Administrator@rootContributor

[REQ][Golang][Client] Add `*http.Client` Accessor

Created by: 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.

Assignee
Assign to
Time tracking