From 5c7e53ae8020678ca7a27a5b8a73f50cd84a6bc7 Mon Sep 17 00:00:00 2001 From: Arvind Thirunarayanan Date: Fri, 27 Sep 2019 18:24:11 -0500 Subject: [PATCH 1/3] Allow retrieving the underlying configuration for APIClient - Needed for dynamically changing the underlying implementations and for testing - Fixes #1321 and #3412 --- .../openapi-generator/src/main/resources/go/client.mustache | 5 +++++ samples/client/petstore/go/go-petstore/client.go | 5 +++++ samples/openapi3/client/petstore/go/go-petstore/client.go | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index c3af45341201..19fc15f75394 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -169,6 +169,11 @@ func (c *APIClient) ChangeBasePath(path string) { c.cfg.BasePath = path } +// Allow modification of underlying config for alternate implementations and testing +func (c *APIClient) GetConfig() *Configuration { + return c.cfg +} + // prepareRequest build the request func (c *APIClient) prepareRequest( ctx context.Context, diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index 30377bdac64c..9869b70575ca 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -180,6 +180,11 @@ func (c *APIClient) ChangeBasePath(path string) { c.cfg.BasePath = path } +// Allow modification of underlying config for alternate implementations and testing +func (c *APIClient) GetConfig() *Configuration { + return c.cfg +} + // prepareRequest build the request func (c *APIClient) prepareRequest( ctx context.Context, diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index a7ec7b01c64e..5015bdf20bbb 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -183,6 +183,11 @@ func (c *APIClient) ChangeBasePath(path string) { c.cfg.BasePath = path } +// Allow modification of underlying config for alternate implementations and testing +func (c *APIClient) GetConfig() *Configuration { + return c.cfg +} + // prepareRequest build the request func (c *APIClient) prepareRequest( ctx context.Context, From 2169e1c056593410b1cfb033c6e91170df845615 Mon Sep 17 00:00:00 2001 From: Arvind Thirunarayanan Date: Sat, 28 Sep 2019 15:02:50 -0500 Subject: [PATCH 2/3] Added go-petstore-withXml changes suggested by circleci --- samples/client/petstore/go/go-petstore-withXml/client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/samples/client/petstore/go/go-petstore-withXml/client.go b/samples/client/petstore/go/go-petstore-withXml/client.go index 7791762a544f..a34f8bcdf8d5 100644 --- a/samples/client/petstore/go/go-petstore-withXml/client.go +++ b/samples/client/petstore/go/go-petstore-withXml/client.go @@ -181,6 +181,11 @@ func (c *APIClient) ChangeBasePath(path string) { c.cfg.BasePath = path } +// Allow modification of underlying config for alternate implementations and testing +func (c *APIClient) GetConfig() *Configuration { + return c.cfg +} + // prepareRequest build the request func (c *APIClient) prepareRequest( ctx context.Context, From a0b9a4abe4c669f858fb7622df09ee84a4bd6cf6 Mon Sep 17 00:00:00 2001 From: Arvind Thirunarayanan Date: Thu, 3 Oct 2019 21:32:46 -0500 Subject: [PATCH 3/3] Add caution note about modifying configuration while live --- modules/openapi-generator/src/main/resources/go/client.mustache | 1 + samples/client/petstore/go/go-petstore-withXml/client.go | 1 + samples/client/petstore/go/go-petstore/client.go | 1 + samples/openapi3/client/petstore/go/go-petstore/client.go | 1 + 4 files changed, 4 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/go/client.mustache b/modules/openapi-generator/src/main/resources/go/client.mustache index 19fc15f75394..ec129d3d4323 100644 --- a/modules/openapi-generator/src/main/resources/go/client.mustache +++ b/modules/openapi-generator/src/main/resources/go/client.mustache @@ -170,6 +170,7 @@ func (c *APIClient) ChangeBasePath(path string) { } // Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior func (c *APIClient) GetConfig() *Configuration { return c.cfg } diff --git a/samples/client/petstore/go/go-petstore-withXml/client.go b/samples/client/petstore/go/go-petstore-withXml/client.go index a34f8bcdf8d5..73bf022c8886 100644 --- a/samples/client/petstore/go/go-petstore-withXml/client.go +++ b/samples/client/petstore/go/go-petstore-withXml/client.go @@ -182,6 +182,7 @@ func (c *APIClient) ChangeBasePath(path string) { } // Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior func (c *APIClient) GetConfig() *Configuration { return c.cfg } diff --git a/samples/client/petstore/go/go-petstore/client.go b/samples/client/petstore/go/go-petstore/client.go index 9869b70575ca..c73a8db8d093 100644 --- a/samples/client/petstore/go/go-petstore/client.go +++ b/samples/client/petstore/go/go-petstore/client.go @@ -181,6 +181,7 @@ func (c *APIClient) ChangeBasePath(path string) { } // Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior func (c *APIClient) GetConfig() *Configuration { return c.cfg } diff --git a/samples/openapi3/client/petstore/go/go-petstore/client.go b/samples/openapi3/client/petstore/go/go-petstore/client.go index 5015bdf20bbb..afb29fb8c43c 100644 --- a/samples/openapi3/client/petstore/go/go-petstore/client.go +++ b/samples/openapi3/client/petstore/go/go-petstore/client.go @@ -184,6 +184,7 @@ func (c *APIClient) ChangeBasePath(path string) { } // Allow modification of underlying config for alternate implementations and testing +// Caution: modifying the configuration while live can cause data races and potentially unwanted behavior func (c *APIClient) GetConfig() *Configuration { return c.cfg }