Skip to content

Commit 600a81f

Browse files
authored
[golang] Regenerate all go samples (#3988)
* Regenerate all go samples * Update API Key usage * Add go-experimental script
1 parent 7dbda04 commit 600a81f

18 files changed

Lines changed: 240 additions & 161 deletions

File tree

bin/utils/ensure-up-to-date

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ declare -a scripts=(
5555
"./bin/csharp-netcore-petstore-all.sh"
5656
"./bin/elixir-petstore.sh"
5757
"./bin/openapi3/go-petstore.sh"
58+
"./bin/go-experimental-petstore.sh"
5859
"./bin/go-petstore.sh"
5960
"./bin/go-petstore-withxml.sh"
6061
"./bin/go-gin-petstore-server.sh"

samples/client/petstore/go-experimental/auth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func TestAccessToken(t *testing.T) {
130130
}
131131

132132
func TestAPIKeyNoPrefix(t *testing.T) {
133-
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{Key: "TEST123"})
133+
auth := context.WithValue(context.Background(), sw.ContextAPIKeys, map[string]sw.APIKey{"api_key": sw.APIKey{Key: "TEST123"}})
134134

135135
newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: sw.PtrString("gopher"),
136136
PhotoUrls: &[]string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"),
@@ -165,7 +165,7 @@ func TestAPIKeyNoPrefix(t *testing.T) {
165165
}
166166

167167
func TestAPIKeyWithPrefix(t *testing.T) {
168-
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{Key: "TEST123", Prefix: "Bearer"})
168+
auth := context.WithValue(context.Background(), sw.ContextAPIKeys, map[string]sw.APIKey{"api_key": sw.APIKey{Key: "TEST123", Prefix: "Bearer"}})
169169

170170
newPet := (sw.Pet{Id: sw.PtrInt64(12992), Name: sw.PtrString("gopher"),
171171
PhotoUrls: &[]string{"http://1.com", "http://2.com"}, Status: sw.PtrString("pending"),
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.2-SNAPSHOT
1+
4.1.3-SNAPSHOT

samples/client/petstore/go-experimental/go-petstore/README.md

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ go get github.com/antihax/optional
2323
Put the package under your project folder and add the following in import:
2424

2525
```golang
26-
import "./petstore"
26+
import sw "./petstore"
2727
```
2828

2929
## Documentation for API Endpoints
@@ -125,37 +125,25 @@ Class | Method | HTTP request | Description
125125

126126

127127

128-
## api_key
128+
### api_key
129129

130130
- **Type**: API key
131+
- **API key parameter name**: api_key
132+
- **Location**: HTTP header
131133

132-
Example
133-
134-
```golang
135-
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
136-
Key: "APIKEY",
137-
Prefix: "Bearer", // Omit if not necessary.
138-
})
139-
r, err := client.Service.Operation(auth, args)
140-
```
134+
Note, each API key must be added to a map of `map[string]APIKey` where the key is: api_key and passed in as the auth context for each request.
141135

142136

143-
## api_key_query
137+
### api_key_query
144138

145139
- **Type**: API key
140+
- **API key parameter name**: api_key_query
141+
- **Location**: URL query string
146142

147-
Example
148-
149-
```golang
150-
auth := context.WithValue(context.Background(), sw.ContextAPIKey, sw.APIKey{
151-
Key: "APIKEY",
152-
Prefix: "Bearer", // Omit if not necessary.
153-
})
154-
r, err := client.Service.Operation(auth, args)
155-
```
143+
Note, each API key must be added to a map of `map[string]APIKey` where the key is: api_key_query and passed in as the auth context for each request.
156144

157145

158-
## http_basic_test
146+
### http_basic_test
159147

160148
- **Type**: HTTP basic authentication
161149

@@ -170,7 +158,7 @@ r, err := client.Service.Operation(auth, args)
170158
```
171159

172160

173-
## petstore_auth
161+
### petstore_auth
174162

175163

176164
- **Type**: OAuth

samples/client/petstore/go-experimental/go-petstore/api/openapi.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,6 +1869,10 @@ components:
18691869
number_item:
18701870
example: 1.234
18711871
type: number
1872+
float_item:
1873+
example: 1.234
1874+
format: float
1875+
type: number
18721876
integer_item:
18731877
example: -2
18741878
type: integer
@@ -1887,6 +1891,7 @@ components:
18871891
required:
18881892
- array_item
18891893
- bool_item
1894+
- float_item
18901895
- integer_item
18911896
- number_item
18921897
- string_item

samples/client/petstore/go-experimental/go-petstore/api_fake.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,7 @@ func (a *FakeApiService) TestEndpointParameters(ctx _context.Context, number flo
834834
localVarFormParams.Add("date", parameterToString(localVarOptionals.Date.Value(), ""))
835835
}
836836
if localVarOptionals != nil && localVarOptionals.DateTime.IsSet() {
837-
paramJson, err := parameterToJson(localVarOptionals.DateTime.Value())
838-
if err != nil {
839-
return nil, err
840-
}
841-
localVarFormParams.Add("dateTime", paramJson)
837+
localVarFormParams.Add("dateTime", parameterToString(localVarOptionals.DateTime.Value(), ""))
842838
}
843839
if localVarOptionals != nil && localVarOptionals.Password.IsSet() {
844840
localVarFormParams.Add("password", parameterToString(localVarOptionals.Password.Value(), ""))

samples/client/petstore/go-experimental/go-petstore/api_fake_classname_tags123.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ func (a *FakeClassnameTags123ApiService) TestClassname(ctx _context.Context, bod
6969
localVarPostBody = &body
7070
if ctx != nil {
7171
// API Key Authentication
72-
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
73-
var key string
74-
if auth.Prefix != "" {
75-
key = auth.Prefix + " " + auth.Key
76-
} else {
77-
key = auth.Key
72+
if auth, ok := ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
73+
if auth, ok := auth["api_key_query"]; ok {
74+
var key string
75+
if auth.Prefix != "" {
76+
key = auth.Prefix + " " + auth.Key
77+
} else {
78+
key = auth.Key
79+
}
80+
localVarQueryParams.Add("api_key_query", key)
7881
}
79-
localVarQueryParams.Add("api_key_query", key)
8082
}
8183
}
8284
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)

samples/client/petstore/go-experimental/go-petstore/api_pet.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,16 @@ func (a *PetApiService) GetPetById(ctx _context.Context, petId int64) (Pet, *_ne
391391
}
392392
if ctx != nil {
393393
// API Key Authentication
394-
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
395-
var key string
396-
if auth.Prefix != "" {
397-
key = auth.Prefix + " " + auth.Key
398-
} else {
399-
key = auth.Key
394+
if auth, ok := ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
395+
if auth, ok := auth["api_key"]; ok {
396+
var key string
397+
if auth.Prefix != "" {
398+
key = auth.Prefix + " " + auth.Key
399+
} else {
400+
key = auth.Key
401+
}
402+
localVarHeaderParams["api_key"] = key
400403
}
401-
localVarHeaderParams["api_key"] = key
402404
}
403405
}
404406
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)

samples/client/petstore/go-experimental/go-petstore/api_store.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,16 @@ func (a *StoreApiService) GetInventory(ctx _context.Context) (map[string]int32,
135135
}
136136
if ctx != nil {
137137
// API Key Authentication
138-
if auth, ok := ctx.Value(ContextAPIKey).(APIKey); ok {
139-
var key string
140-
if auth.Prefix != "" {
141-
key = auth.Prefix + " " + auth.Key
142-
} else {
143-
key = auth.Key
138+
if auth, ok := ctx.Value(ContextAPIKeys).(map[string]APIKey); ok {
139+
if auth, ok := auth["api_key"]; ok {
140+
var key string
141+
if auth.Prefix != "" {
142+
key = auth.Prefix + " " + auth.Key
143+
} else {
144+
key = auth.Key
145+
}
146+
localVarHeaderParams["api_key"] = key
144147
}
145-
localVarHeaderParams["api_key"] = key
146148
}
147149
}
148150
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFormFileName, localVarFileName, localVarFileBytes)

samples/client/petstore/go-experimental/go-petstore/configuration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ var (
3333
// ContextAccessToken takes a string oauth2 access token as authentication for the request.
3434
ContextAccessToken = contextKey("accesstoken")
3535

36-
// ContextAPIKey takes an APIKey as authentication for the request
37-
ContextAPIKey = contextKey("apikey")
36+
// ContextAPIKeys takes a string apikey as authentication for the request
37+
ContextAPIKeys = contextKey("apiKeys")
3838
)
3939

4040
// BasicAuth provides basic http authentication to a request passed via context using ContextBasicAuth

0 commit comments

Comments
 (0)