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
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,27 @@ 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 err != nil {
return resp, err
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
}

resp, err := c.cfg.HTTPClient.Do(request)
if err != nil {
return resp, err
}

if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
Expand Down
24 changes: 23 additions & 1 deletion samples/client/petstore/go-experimental/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,27 @@ 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 err != nil {
return resp, err
}

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 @@ -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
3 changes: 3 additions & 0 deletions 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.

3 changes: 3 additions & 0 deletions samples/client/petstore/go/go-petstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
}

resp, err := c.cfg.HTTPClient.Do(request)
if err != nil {
return resp, err
}

if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.0-SNAPSHOT
4.2.2-SNAPSHOT
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 @@ -175,7 +177,27 @@ 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 err != nil {
return resp, err
}

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 Expand Up @@ -353,6 +375,9 @@ func (c *APIClient) prepareRequest(
}

func (c *APIClient) decode(v interface{}, b []byte, contentType string) (err error) {
if len(b) == 0 {
return nil
}
if s, ok := v.(*string); ok {
*s = string(b)
return nil
Expand Down
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
3 changes: 3 additions & 0 deletions samples/openapi3/client/petstore/go/go-petstore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func (c *APIClient) callAPI(request *http.Request) (*http.Response, error) {
}

resp, err := c.cfg.HTTPClient.Do(request)
if err != nil {
return resp, err
}

if c.cfg.Debug {
dump, err := httputil.DumpResponse(resp, true)
Expand Down