1
1
package swagger
2
2
3
-
4
3
import (
5
4
"strings"
6
5
"fmt"
7
6
"encoding/json"
8
7
"errors"
9
8
"github.com/dghubble/sling"
10
-
9
+ "os"
11
10
)
12
11
13
12
type PetApi struct {
@@ -30,7 +29,6 @@ func NewPetApiWithBasePath(basePath string) *PetApi{
30
29
}
31
30
}
32
31
33
-
34
32
/**
35
33
* Add a new pet to the store
36
34
*
@@ -43,20 +41,17 @@ func (a PetApi) AddPet (body Pet) (error) {
43
41
_sling := sling .New ().Post (a .Configuration .BasePath )
44
42
45
43
// create path and map variables
46
- path := "/v2/pets"
47
-
44
+ path := "/v2/pet"
48
45
49
46
_sling = _sling .Path (path )
50
47
51
-
52
48
// accept header
53
- accepts := []string { "application/json " , "application/xml " }
49
+ accepts := []string { "application/xml " , "application/json " }
54
50
for key := range accepts {
55
51
_sling = _sling .Set ("Accept" , accepts [key ])
56
52
break // only use the first Accept
57
53
}
58
54
59
-
60
55
// body params
61
56
_sling = _sling .BodyJSON (body )
62
57
@@ -94,29 +89,26 @@ func (a PetApi) AddPet (body Pet) (error) {
94
89
95
90
return err
96
91
}
97
-
98
92
/**
99
93
* Deletes a pet
100
94
*
101
- * @param apiKey
102
95
* @param petId Pet id to delete
96
+ * @param apiKey
103
97
* @return void
104
98
*/
105
- //func (a PetApi) DeletePet (apiKey string, petId int64 ) (error) {
106
- func (a PetApi ) DeletePet (apiKey string , petId int64 ) (error ) {
99
+ //func (a PetApi) DeletePet (petId int64, apiKey string ) (error) {
100
+ func (a PetApi ) DeletePet (petId int64 , apiKey string ) (error ) {
107
101
108
102
_sling := sling .New ().Delete (a .Configuration .BasePath )
109
103
110
104
// create path and map variables
111
- path := "/v2/pets /{petId}"
105
+ path := "/v2/pet /{petId}"
112
106
path = strings .Replace (path , "{" + "petId" + "}" , fmt .Sprintf ("%v" , petId ), - 1 )
113
107
114
-
115
108
_sling = _sling .Path (path )
116
109
117
-
118
110
// accept header
119
- accepts := []string { "application/json " , "application/xml " }
111
+ accepts := []string { "application/xml " , "application/json " }
120
112
for key := range accepts {
121
113
_sling = _sling .Set ("Accept" , accepts [key ])
122
114
break // only use the first Accept
@@ -127,7 +119,6 @@ func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
127
119
128
120
129
121
130
-
131
122
// We use this map (below) so that any arbitrary error JSON can be handled.
132
123
// FIXME: This is in the absence of this Go generator honoring the non-2xx
133
124
// response (error) models, which needs to be implemented at some point.
@@ -160,10 +151,9 @@ func (a PetApi) DeletePet (apiKey string, petId int64) (error) {
160
151
161
152
return err
162
153
}
163
-
164
154
/**
165
155
* Finds Pets by status
166
- * Multiple status values can be provided with comma seperated strings
156
+ * Multiple status values can be provided with comma separated strings
167
157
* @param status Status values that need to be considered for filter
168
158
* @return []Pet
169
159
*/
@@ -173,26 +163,22 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
173
163
_sling := sling .New ().Get (a .Configuration .BasePath )
174
164
175
165
// create path and map variables
176
- path := "/v2/pets/findByStatus"
177
-
166
+ path := "/v2/pet/findByStatus"
178
167
179
168
_sling = _sling .Path (path )
180
169
181
170
type QueryParams struct {
182
171
status []string `url:"status,omitempty"`
183
-
184
172
}
185
173
_sling = _sling .QueryStruct (& QueryParams { status : status })
186
-
187
174
// accept header
188
- accepts := []string { "application/json " , "application/xml " }
175
+ accepts := []string { "application/xml " , "application/json " }
189
176
for key := range accepts {
190
177
_sling = _sling .Set ("Accept" , accepts [key ])
191
178
break // only use the first Accept
192
179
}
193
180
194
181
195
-
196
182
var successPayload = new ([]Pet )
197
183
198
184
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -227,10 +213,9 @@ func (a PetApi) FindPetsByStatus (status []string) ([]Pet, error) {
227
213
228
214
return * successPayload , err
229
215
}
230
-
231
216
/**
232
217
* Finds Pets by tags
233
- * Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing.
218
+ * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
234
219
* @param tags Tags to filter by
235
220
* @return []Pet
236
221
*/
@@ -240,26 +225,22 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
240
225
_sling := sling .New ().Get (a .Configuration .BasePath )
241
226
242
227
// create path and map variables
243
- path := "/v2/pets/findByTags"
244
-
228
+ path := "/v2/pet/findByTags"
245
229
246
230
_sling = _sling .Path (path )
247
231
248
232
type QueryParams struct {
249
233
tags []string `url:"tags,omitempty"`
250
-
251
234
}
252
235
_sling = _sling .QueryStruct (& QueryParams { tags : tags })
253
-
254
236
// accept header
255
- accepts := []string { "application/json " , "application/xml " }
237
+ accepts := []string { "application/xml " , "application/json " }
256
238
for key := range accepts {
257
239
_sling = _sling .Set ("Accept" , accepts [key ])
258
240
break // only use the first Accept
259
241
}
260
242
261
243
262
-
263
244
var successPayload = new ([]Pet )
264
245
265
246
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -294,11 +275,10 @@ func (a PetApi) FindPetsByTags (tags []string) ([]Pet, error) {
294
275
295
276
return * successPayload , err
296
277
}
297
-
298
278
/**
299
279
* Find pet by ID
300
- * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
301
- * @param petId ID of pet that needs to be fetched
280
+ * Returns a single pet
281
+ * @param petId ID of pet to return
302
282
* @return Pet
303
283
*/
304
284
//func (a PetApi) GetPetById (petId int64) (Pet, error) {
@@ -307,22 +287,19 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
307
287
_sling := sling .New ().Get (a .Configuration .BasePath )
308
288
309
289
// create path and map variables
310
- path := "/v2/pets /{petId}"
290
+ path := "/v2/pet /{petId}"
311
291
path = strings .Replace (path , "{" + "petId" + "}" , fmt .Sprintf ("%v" , petId ), - 1 )
312
292
313
-
314
293
_sling = _sling .Path (path )
315
294
316
-
317
295
// accept header
318
- accepts := []string { "application/json " , "application/xml " }
296
+ accepts := []string { "application/xml " , "application/json " }
319
297
for key := range accepts {
320
298
_sling = _sling .Set ("Accept" , accepts [key ])
321
299
break // only use the first Accept
322
300
}
323
301
324
302
325
-
326
303
var successPayload = new (Pet )
327
304
328
305
// We use this map (below) so that any arbitrary error JSON can be handled.
@@ -357,7 +334,6 @@ func (a PetApi) GetPetById (petId int64) (Pet, error) {
357
334
358
335
return * successPayload , err
359
336
}
360
-
361
337
/**
362
338
* Update an existing pet
363
339
*
@@ -370,20 +346,17 @@ func (a PetApi) UpdatePet (body Pet) (error) {
370
346
_sling := sling .New ().Put (a .Configuration .BasePath )
371
347
372
348
// create path and map variables
373
- path := "/v2/pets"
374
-
349
+ path := "/v2/pet"
375
350
376
351
_sling = _sling .Path (path )
377
352
378
-
379
353
// accept header
380
- accepts := []string { "application/json " , "application/xml " }
354
+ accepts := []string { "application/xml " , "application/json " }
381
355
for key := range accepts {
382
356
_sling = _sling .Set ("Accept" , accepts [key ])
383
357
break // only use the first Accept
384
358
}
385
359
386
-
387
360
// body params
388
361
_sling = _sling .BodyJSON (body )
389
362
@@ -421,7 +394,6 @@ func (a PetApi) UpdatePet (body Pet) (error) {
421
394
422
395
return err
423
396
}
424
-
425
397
/**
426
398
* Updates a pet in the store with form data
427
399
*
@@ -430,21 +402,19 @@ func (a PetApi) UpdatePet (body Pet) (error) {
430
402
* @param status Updated status of the pet
431
403
* @return void
432
404
*/
433
- //func (a PetApi) UpdatePetWithForm (petId string , name string, status string) (error) {
434
- func (a PetApi ) UpdatePetWithForm (petId string , name string , status string ) (error ) {
405
+ //func (a PetApi) UpdatePetWithForm (petId int64 , name string, status string) (error) {
406
+ func (a PetApi ) UpdatePetWithForm (petId int64 , name string , status string ) (error ) {
435
407
436
408
_sling := sling .New ().Post (a .Configuration .BasePath )
437
409
438
410
// create path and map variables
439
- path := "/v2/pets /{petId}"
411
+ path := "/v2/pet /{petId}"
440
412
path = strings .Replace (path , "{" + "petId" + "}" , fmt .Sprintf ("%v" , petId ), - 1 )
441
413
442
-
443
414
_sling = _sling .Path (path )
444
415
445
-
446
416
// accept header
447
- accepts := []string { "application/json " , "application/xml " }
417
+ accepts := []string { "application/xml " , "application/json " }
448
418
for key := range accepts {
449
419
_sling = _sling .Set ("Accept" , accepts [key ])
450
420
break // only use the first Accept
@@ -453,13 +423,11 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
453
423
type FormParams struct {
454
424
name string `url:"name,omitempty"`
455
425
status string `url:"status,omitempty"`
456
-
457
426
}
458
427
_sling = _sling .BodyForm (& FormParams { name : name ,status : status })
459
428
460
429
461
430
462
-
463
431
// We use this map (below) so that any arbitrary error JSON can be handled.
464
432
// FIXME: This is in the absence of this Go generator honoring the non-2xx
465
433
// response (error) models, which needs to be implemented at some point.
@@ -492,5 +460,69 @@ func (a PetApi) UpdatePetWithForm (petId string, name string, status string) (er
492
460
493
461
return err
494
462
}
463
+ /**
464
+ * uploads an image
465
+ *
466
+ * @param petId ID of pet to update
467
+ * @param additionalMetadata Additional data to pass to server
468
+ * @param file file to upload
469
+ * @return ApiResponse
470
+ */
471
+ //func (a PetApi) UploadFile (petId int64, additionalMetadata string, file *os.File) (ApiResponse, error) {
472
+ func (a PetApi ) UploadFile (petId int64 , additionalMetadata string , file * os.File ) (ApiResponse , error ) {
473
+
474
+ _sling := sling .New ().Post (a .Configuration .BasePath )
475
+
476
+ // create path and map variables
477
+ path := "/v2/pet/{petId}/uploadImage"
478
+ path = strings .Replace (path , "{" + "petId" + "}" , fmt .Sprintf ("%v" , petId ), - 1 )
479
+
480
+ _sling = _sling .Path (path )
481
+
482
+ // accept header
483
+ accepts := []string { "application/json" }
484
+ for key := range accepts {
485
+ _sling = _sling .Set ("Accept" , accepts [key ])
486
+ break // only use the first Accept
487
+ }
488
+
489
+ type FormParams struct {
490
+ additionalMetadata string `url:"additionalMetadata,omitempty"`
491
+ file * os.File `url:"file,omitempty"`
492
+ }
493
+ _sling = _sling .BodyForm (& FormParams { additionalMetadata : additionalMetadata ,file : file })
494
+
495
+ var successPayload = new (ApiResponse )
495
496
497
+ // We use this map (below) so that any arbitrary error JSON can be handled.
498
+ // FIXME: This is in the absence of this Go generator honoring the non-2xx
499
+ // response (error) models, which needs to be implemented at some point.
500
+ var failurePayload map [string ]interface {}
501
+
502
+ httpResponse , err := _sling .Receive (successPayload , & failurePayload )
503
+
504
+ if err == nil {
505
+ // err == nil only means that there wasn't a sub-application-layer error (e.g. no network error)
506
+ if failurePayload != nil {
507
+ // If the failurePayload is present, there likely was some kind of non-2xx status
508
+ // returned (and a JSON payload error present)
509
+ var str []byte
510
+ str , err = json .Marshal (failurePayload )
511
+ if err == nil { // For safety, check for an error marshalling... probably superfluous
512
+ // This will return the JSON error body as a string
513
+ err = errors .New (string (str ))
514
+ }
515
+ } else {
516
+ // So, there was no network-type error, and nothing in the failure payload,
517
+ // but we should still check the status code
518
+ if httpResponse == nil {
519
+ // This should never happen...
520
+ err = errors .New ("No HTTP Response received." )
521
+ } else if code := httpResponse .StatusCode ; 200 > code || code > 299 {
522
+ err = errors .New ("HTTP Error: " + string (httpResponse .StatusCode ))
523
+ }
524
+ }
525
+ }
496
526
527
+ return * successPayload , err
528
+ }
0 commit comments