Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion modules/openapi-generator/src/main/resources/go/client.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"errors"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"net/http/httputil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -161,7 +163,25 @@ func parameterToJson(obj interface{}) (string, error) {

// callAPI do the request.
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
return c.cfg.HTTPClient.Do(request)
if c.cfg.Debug {
dump, err := httputil.DumpRequestOut(request, true)
if err != nil {
return nil, err
}
log.Printf("\n%s\n", string(dump))
}

resp, err := c.cfg.HTTPClient.Do(request)

if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
return resp, err
}
log.Printf("\n%s\n", string(dump))
}

return resp, err
}

// ChangeBasePath changes base path to allow switching to mocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Configuration struct {
Scheme string `json:"scheme,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Debug bool `json:"debug,omitempty"`
HTTPClient *http.Client
}

Expand All @@ -57,6 +58,7 @@ func NewConfiguration() *Configuration {
BasePath: "{{{basePath}}}",
DefaultHeader: make(map[string]string),
UserAgent: "{{#httpUserAgent}}{{{.}}}{{/httpUserAgent}}{{^httpUserAgent}}OpenAPI-Generator/{{{packageVersion}}}/go{{/httpUserAgent}}",
Debug: false,
}
return cfg
}
Expand Down
22 changes: 21 additions & 1 deletion samples/client/petstore/go/go-petstore-withXml/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 21 additions & 1 deletion samples/client/petstore/go/go-petstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import (
"errors"
"fmt"
"io"
"log"
"mime/multipart"
"net/http"
"net/http/httputil"
"net/url"
"os"
"path/filepath"
Expand Down Expand Up @@ -172,7 +174,25 @@ func parameterToJson(obj interface{}) (string, error) {

// callAPI do the request.
func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
return c.cfg.HTTPClient.Do(request)
if c.cfg.Debug {
dump, err := httputil.DumpRequestOut(request, true)
if err != nil {
return nil, err
}
log.Printf("\n%s\n", string(dump))
}

resp, err := c.cfg.HTTPClient.Do(request)

if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
return resp, err
}
log.Printf("\n%s\n", string(dump))
}

return resp, err
}

// ChangeBasePath changes base path to allow switching to mocks
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/go/go-petstore/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Configuration struct {
Scheme string `json:"scheme,omitempty"`
DefaultHeader map[string]string `json:"defaultHeader,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
Debug bool `json:"debug,omitempty"`
HTTPClient *http.Client
}

Expand All @@ -65,6 +66,7 @@ func NewConfiguration() *Configuration {
BasePath: "http://petstore.swagger.io:80/v2",
DefaultHeader: make(map[string]string),
UserAgent: "OpenAPI-Generator/1.0.0/go",
Debug: false,
}
return cfg
}
Expand Down