@@ -18,7 +18,6 @@ import (
18
18
19
19
type { {classname} } interface {
20
20
{{#operation} }
21
-
22
21
/*
23
22
{ {operationId} } { {{summary} }}{ {^summary} }Method for { {operationId} }{ {/summary} }
24
23
{ {#notes} }
@@ -34,27 +33,44 @@ type {{classname}} interface {
34
33
35
34
/*
36
35
{ {nickname} }Execute executes the request{ {#returnType} }
36
+ @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().{ {#pathParams} }
37
+ @param { {paramName} }{ {#description} } { {{.} }}{ {/description} }{ {/pathParams} }
37
38
@return { {{.} }}{ {/returnType} }
38
39
39
40
{ {#isDeprecated} }
40
41
Deprecated: { {{unescapedNotes} }}
41
42
{ {/isDeprecated} }
42
43
*/
43
- { {nickname} }Execute(r { {#structPrefix } } { {&classname } } { {/structPrefix } } { {^structPrefix } }Api { {/structPrefix } } { {operationId } }Request ) ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} }*http.Response, error)
44
+ { {nickname} }Execute(ctx context.Context { {#pathParams } }, { {paramName } } { {{dataType } }} { {/pathParams } } ) ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} } error)
44
45
{ {/operation} }
45
46
}
47
+
48
+ { {#operation} }
49
+ type { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request interface {
50
+ {{#allParams} }
51
+ { {^isPathParam} }
52
+ { {#description} }
53
+ // { {.} }
54
+ { {/description} }
55
+ { {#isDeprecated} }
56
+ // Deprecated
57
+ { {/isDeprecated} }
58
+ { {vendorExtensions.x-export-param-name} }({ {paramName} } { {{dataType} }}) { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request
59
+ { {/isPathParam} }
60
+ { {/allParams} }
61
+ Execute() ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} } error)
62
+ }
63
+
64
+ { {/operation} }
46
65
{ {/generateInterfaces} }
47
66
48
67
// { {classname} }Service { {classname} } service
49
68
type { {classname} }Service service
50
69
{ {#operation} }
51
70
52
- type { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request struct {
53
- ctx context.Context{{#generateInterfaces} }
54
- apiService { {classname} }
55
- { {/generateInterfaces} }{ {^generateInterfaces} }
71
+ type { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {operationId} }Request struct {
72
+ ctx context.Context
56
73
apiService *{{classname} }Service
57
- { {/generateInterfaces} }
58
74
{ {#allParams} }
59
75
{ {paramName} } { {^isPathParam} }{ {^isFile} }*{ {/isFile} }{ {/isPathParam} }{ {{dataType} }}
60
76
{ {/allParams} }
@@ -69,15 +85,15 @@ type {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/stru
69
85
// Deprecated
70
86
{ {/isDeprecated} }
71
87
72
- func (r { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix } }Api { {/structPrefix } } { { operationId} }Request) { {vendorExtensions.x-export-param-name} }({ {paramName} } { {{dataType} }}) { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request {
88
+ func (r { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {operationId} }Request) { {vendorExtensions.x-export-param-name} }({ {paramName} } { {{dataType} }}) { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request {
73
89
r.{{paramName} } = { {^isFile} }& { {/isFile} }{ {paramName} }
74
90
return r
75
91
}
76
92
77
93
{ {/isPathParam} }
78
94
{ {/allParams} }
79
95
80
- func (r { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix } }Api { {/structPrefix } } { { operationId} }Request) Execute() ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} } error) {
96
+ func (r { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {operationId} }Request) Execute() ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} } error) {
81
97
var (
82
98
localVarHTTPMethod = http.Method{{httpMethod} }
83
99
localVarPostBody interface{ }
@@ -87,7 +103,11 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
87
103
{ {/returnType} }
88
104
)
89
105
a := r.apiService
90
- localBasePath, err := a.client.cfg.ServerURLWithContext(r.ctx, "{ {{classname} }}Service.{ {{nickname} }}")
106
+ client, ok := a.client.(*APIClient)
107
+ if !ok {
108
+ return {{#returnType} }nil, { {/returnType} } fmt.Errorf("could not parse client to type APIClient")
109
+ }
110
+ localBasePath, err := client.cfg.ServerURLWithContext(r.ctx, "{ {{classname} }}Service.{ {{nickname} }}")
91
111
if err != nil {
92
112
return {{#returnType} }localVarReturnValue, { {/returnType} } &oapierror.GenericOpenAPIError{ ErrorMessage: err.Error()}
93
113
}
@@ -301,7 +321,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
301
321
{ {/isKeyInCookie} }
302
322
{ {/isApiKey} }
303
323
{ {/authMethods} }
304
- req, err := a. client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
324
+ req, err := client.prepareRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, formFiles)
305
325
if err != nil {
306
326
return {{#returnType} }localVarReturnValue, { {/returnType} } err
307
327
}
@@ -311,7 +331,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
311
331
*contextHTTPRequest = req
312
332
}
313
333
314
- localVarHTTPResponse, err := a. client.callAPI(req)
334
+ localVarHTTPResponse, err := client.callAPI(req)
315
335
contextHTTPResponse, ok := r.ctx.Value(config.ContextHTTPResponse).(**http.Response)
316
336
if ok {
317
337
*contextHTTPResponse = localVarHTTPResponse
@@ -354,7 +374,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
354
374
{{/wildcard} }
355
375
{ {/range} }
356
376
var v { {{dataType} }}
357
- err = a. client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
377
+ err = client.decode(&v, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
358
378
if err != nil {
359
379
newErr.ErrorMessage = err.Error()
360
380
return {{#returnType} }localVarReturnValue, { {/returnType} } newErr
@@ -375,7 +395,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
375
395
}
376
396
377
397
{ {#returnType} }
378
- err = a. client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
398
+ err = client.decode(&localVarReturnValue, localVarBody, localVarHTTPResponse.Header.Get("Content-Type"))
379
399
if err != nil {
380
400
newErr := &oapierror.GenericOpenAPIError{
381
401
StatusCode: localVarHTTPResponse.StatusCode,
@@ -401,7 +421,7 @@ func (r {{#structPrefix}}{{&classname}}{{/structPrefix}}{{^structPrefix}}Api{{/s
401
421
@return { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request
402
422
*/
403
423
func (a *APIClient) { {{nickname} }}(ctx context.Context{ {#pathParams} }, { {paramName} } { {{dataType} }}{ {/pathParams} }) { {#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix} }Api{ {/structPrefix} }{ {operationId} }Request {
404
- return {{#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix } }Api { {/structPrefix } } { { operationId} }Request{
424
+ return {{#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {operationId} }Request{
405
425
apiService: a.defaultApi,
406
426
ctx: ctx,
407
427
{{#pathParams} }
@@ -416,7 +436,7 @@ Deprecated: {{{unescapedNotes}}}
416
436
*/
417
437
{ {/isDeprecated} }
418
438
func (a *APIClient) { {{nickname} }}Execute(ctx context.Context{ {#pathParams} }, { {paramName} } { {{dataType} }}{ {/pathParams} }) ({ {#returnType} }{ {^isArray} }{ {^returnTypeIsPrimitive} }{ {^isResponseFile} }*{ {/isResponseFile} }{ {/returnTypeIsPrimitive} }{ {/isArray} }{ {{.} }}, { {/returnType} } error){
419
- r := {{#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {^structPrefix } }Api { {/structPrefix } } { { operationId} }Request{
439
+ r := {{#structPrefix} }{ {&classname} }{ {/structPrefix} }{ {operationId} }Request{
420
440
apiService: a.defaultApi,
421
441
ctx: ctx,
422
442
{{#pathParams} }
0 commit comments