Skip to content

Commit ffa138f

Browse files
authored
openapi: fix js package.json and go client url (#187)
For Go client this fixes URLs for external clients.
1 parent 5145193 commit ffa138f

17 files changed

+12
-5
lines changed

assets/openapi/client-template/go/configuration.mustache

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ type StaticConfig interface {
1717
MustGetPtr(cfg interface{}) interface{}
1818
}
1919

20-
type ClientConf struct {
20+
type {{packageName}}ClientConf struct {
2121
ServiceUrl string `envconfig:"{{clientEndpointEnv}}" default:"{{serviceEndpoint}}"`
2222
}
2323

24-
func getClientConf(conf StaticConfig) *ClientConf {
25-
return conf.MustGetPtr((*ClientConf)(nil)).(*ClientConf)
24+
func getClientConf(conf StaticConfig) *{{packageName}}ClientConf {
25+
return conf.MustGetPtr((*{{packageName}}ClientConf)(nil)).(*{{packageName}}ClientConf)
2626
}
2727

2828
type contextKey string
@@ -127,6 +127,13 @@ type Configuration struct {
127127
{{/withCustomMiddlewareFunction}}
128128
}
129129

130+
func normalizeServiceUrl(url string) string {
131+
if strings.HasPrefix(url, "http://") {
132+
return url
133+
}
134+
return "http://"+url
135+
}
136+
130137
// NewConfiguration returns a new Configuration object
131138
func NewConfiguration(conf StaticConfig) *Configuration {
132139
cfg := getClientConf(conf)
@@ -140,7 +147,7 @@ func NewConfiguration(conf StaticConfig) *Configuration {
140147
Servers: ServerConfigurations{
141148
{{/-first}}
142149
{
143-
URL: "http://"+cfg.ServiceUrl,
150+
URL: normalizeServiceUrl(cfg.ServiceUrl),
144151
Description: "{{{description}}}{{^description}}No description provided{{/description}}",
145152
{{#variables}}
146153
{{#-first}}

assets/openapi/server-template/js/package.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "index.js",
66
"scripts": {
77
"prestart": "npm install",
8-
"start": "node index.js"
8+
"start": "node index.js",
99
"dev": "node index.js"
1010
},
1111
"keywords": [
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)