@azure-tools/typespec-go 0.10.7 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codegen.go/src/core/clientFactory.d.ts.map +1 -1
- package/dist/codegen.go/src/core/clientFactory.js +18 -15
- package/dist/codegen.go/src/core/clientFactory.js.map +1 -1
- package/dist/codegen.go/src/core/cloudConfig.d.ts.map +1 -1
- package/dist/codegen.go/src/core/cloudConfig.js +4 -3
- package/dist/codegen.go/src/core/cloudConfig.js.map +1 -1
- package/dist/codegen.go/src/core/constants.d.ts.map +1 -1
- package/dist/codegen.go/src/core/constants.js +6 -4
- package/dist/codegen.go/src/core/constants.js.map +1 -1
- package/dist/codegen.go/src/core/example.js +51 -52
- package/dist/codegen.go/src/core/example.js.map +1 -1
- package/dist/codegen.go/src/core/helpers.d.ts +27 -11
- package/dist/codegen.go/src/core/helpers.d.ts.map +1 -1
- package/dist/codegen.go/src/core/helpers.js +39 -15
- package/dist/codegen.go/src/core/helpers.js.map +1 -1
- package/dist/codegen.go/src/core/interfaces.d.ts.map +1 -1
- package/dist/codegen.go/src/core/interfaces.js +4 -3
- package/dist/codegen.go/src/core/interfaces.js.map +1 -1
- package/dist/codegen.go/src/core/models.d.ts.map +1 -1
- package/dist/codegen.go/src/core/models.js +289 -230
- package/dist/codegen.go/src/core/models.js.map +1 -1
- package/dist/codegen.go/src/core/operations.d.ts.map +1 -1
- package/dist/codegen.go/src/core/operations.js +585 -382
- package/dist/codegen.go/src/core/operations.js.map +1 -1
- package/dist/codegen.go/src/core/options.js +3 -2
- package/dist/codegen.go/src/core/options.js.map +1 -1
- package/dist/codegen.go/src/core/polymorphics.d.ts.map +1 -1
- package/dist/codegen.go/src/core/polymorphics.js +55 -48
- package/dist/codegen.go/src/core/polymorphics.js.map +1 -1
- package/dist/codegen.go/src/core/responses.d.ts.map +1 -1
- package/dist/codegen.go/src/core/responses.js +28 -19
- package/dist/codegen.go/src/core/responses.js.map +1 -1
- package/dist/codegen.go/src/core/version.d.ts.map +1 -1
- package/dist/codegen.go/src/core/version.js +3 -2
- package/dist/codegen.go/src/core/version.js.map +1 -1
- package/dist/codegen.go/src/fake/factory.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/factory.js +2 -2
- package/dist/codegen.go/src/fake/factory.js.map +1 -1
- package/dist/codegen.go/src/fake/servers.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/servers.js +311 -256
- package/dist/codegen.go/src/fake/servers.js.map +1 -1
- package/dist/codemodel.go/src/client.d.ts +37 -2
- package/dist/codemodel.go/src/client.d.ts.map +1 -1
- package/dist/codemodel.go/src/client.js +13 -0
- package/dist/codemodel.go/src/client.js.map +1 -1
- package/dist/codemodel.go/src/type.d.ts +2 -0
- package/dist/codemodel.go/src/type.d.ts.map +1 -1
- package/dist/codemodel.go/src/type.js +1 -0
- package/dist/codemodel.go/src/type.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.js +1 -2
- package/dist/typespec-go/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts +8 -0
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.js +130 -50
- package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/helpers.d.ts +15 -0
- package/dist/typespec-go/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/helpers.js +34 -0
- package/dist/typespec-go/src/tcgcadapter/helpers.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.d.ts +1 -0
- package/dist/typespec-go/src/tcgcadapter/types.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.js +43 -0
- package/dist/typespec-go/src/tcgcadapter/types.js.map +1 -1
- package/package.json +4 -4
|
@@ -58,6 +58,7 @@ export function generateServers(pkg, target) {
|
|
|
58
58
|
let content;
|
|
59
59
|
content = `// ${serverName} is a fake server for instances of the ${go.getTypeDeclaration(client, pkg)} type.\n`;
|
|
60
60
|
content += `type ${serverName} struct{\n`;
|
|
61
|
+
const indent = new helpers.Indentation();
|
|
61
62
|
// we might remove some operations from the list
|
|
62
63
|
const finalMethods = new Array();
|
|
63
64
|
let countLROs = 0;
|
|
@@ -71,8 +72,8 @@ export function generateServers(pkg, target) {
|
|
|
71
72
|
continue;
|
|
72
73
|
}
|
|
73
74
|
const serverName = getServerName(clientAccessor.returns);
|
|
74
|
-
content +=
|
|
75
|
-
content +=
|
|
75
|
+
content += `${indent.get()}// ${serverName} contains the fakes for client ${clientAccessor.returns.name}\n`;
|
|
76
|
+
content += `${indent.get()}${serverName} ${serverName}\n\n`;
|
|
76
77
|
finalSubClients.push(clientAccessor.returns);
|
|
77
78
|
}
|
|
78
79
|
for (const method of client.methods) {
|
|
@@ -98,7 +99,7 @@ export function generateServers(pkg, target) {
|
|
|
98
99
|
break;
|
|
99
100
|
}
|
|
100
101
|
const operationName = fixUpMethodName(method);
|
|
101
|
-
content +=
|
|
102
|
+
content += `${indent.get()}// ${operationName} is the fake for method ${client.name}.${operationName}\n`;
|
|
102
103
|
const successCodes = new Array();
|
|
103
104
|
if (method.returns.result?.kind === 'anyResult') {
|
|
104
105
|
for (const httpStatus of getMethodStatusCodes(method)) {
|
|
@@ -110,18 +111,18 @@ export function generateServers(pkg, target) {
|
|
|
110
111
|
}
|
|
111
112
|
successCodes.push(`${helpers.formatStatusCode(httpStatus)} (returns ${go.getTypeDeclaration(result, pkg)})`);
|
|
112
113
|
}
|
|
113
|
-
content +=
|
|
114
|
+
content += `${indent.get()}// HTTP status codes to indicate success:\n`;
|
|
114
115
|
for (const successCode of successCodes) {
|
|
115
|
-
content +=
|
|
116
|
+
content += `${indent.get()}// - ${successCode}\n`;
|
|
116
117
|
}
|
|
117
118
|
}
|
|
118
119
|
else {
|
|
119
120
|
for (const statusCode of getMethodStatusCodes(method)) {
|
|
120
121
|
successCodes.push(`${helpers.formatStatusCode(statusCode)}`);
|
|
121
122
|
}
|
|
122
|
-
content +=
|
|
123
|
+
content += `${indent.get()}// HTTP status codes to indicate success: ${successCodes.join(', ')}\n`;
|
|
123
124
|
}
|
|
124
|
-
content +=
|
|
125
|
+
content += `${indent.get()}${operationName} func(${getAPIParametersSig(pkg, method, imports)}) (${serverResponse})\n\n`;
|
|
125
126
|
finalMethods.push(method);
|
|
126
127
|
switch (method.kind) {
|
|
127
128
|
case 'lroMethod':
|
|
@@ -141,10 +142,12 @@ export function generateServers(pkg, target) {
|
|
|
141
142
|
content += "// azcore.ClientOptions.Transporter field in the client's constructor parameters.\n";
|
|
142
143
|
content += `func New${serverTransport}(srv *${serverName}) *${serverTransport} {\n`;
|
|
143
144
|
if (countLROs === 0 && countPagers === 0) {
|
|
144
|
-
content +=
|
|
145
|
+
content += `${indent.get()}return &${serverTransport}{srv: srv}\n}\n\n`;
|
|
145
146
|
}
|
|
146
147
|
else {
|
|
147
|
-
content +=
|
|
148
|
+
content += `${indent.get()}return &${serverTransport}{\n`;
|
|
149
|
+
indent.push();
|
|
150
|
+
content += `${indent.get()}srv: srv,\n`;
|
|
148
151
|
for (const method of finalMethods) {
|
|
149
152
|
let respType = go.getTypeDeclaration(method.returns, pkg);
|
|
150
153
|
switch (method.kind) {
|
|
@@ -154,28 +157,29 @@ export function generateServers(pkg, target) {
|
|
|
154
157
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
155
158
|
}
|
|
156
159
|
requiredHelpers.tracker = true;
|
|
157
|
-
content +=
|
|
160
|
+
content += `${indent.get()}${naming.uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PollerResponder[${respType}]](),\n`;
|
|
158
161
|
break;
|
|
159
162
|
case 'pageableMethod':
|
|
160
163
|
requiredHelpers.tracker = true;
|
|
161
|
-
content +=
|
|
164
|
+
content += `${indent.get()}${naming.uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PagerResponder[${respType}]](),\n`;
|
|
162
165
|
break;
|
|
163
166
|
}
|
|
164
167
|
}
|
|
165
|
-
|
|
168
|
+
indent.pop();
|
|
169
|
+
content += `${indent.get()}}\n}\n\n`;
|
|
166
170
|
}
|
|
167
171
|
content += `// ${serverTransport} connects instances of ${go.getTypeDeclaration(client, pkg)} to instances of ${serverName}.\n`;
|
|
168
172
|
content += `// Don't use this type directly, use New${serverTransport} instead.\n`;
|
|
169
173
|
content += `type ${serverTransport} struct {\n`;
|
|
170
|
-
content +=
|
|
174
|
+
content += `${indent.get()}srv *${serverName}\n`;
|
|
171
175
|
// add server transports for client accessors
|
|
172
176
|
if (finalSubClients.length > 0) {
|
|
173
177
|
requiredHelpers.initServer = true;
|
|
174
178
|
imports.add('sync');
|
|
175
|
-
content +=
|
|
179
|
+
content += `${indent.get()}trMu sync.Mutex\n`;
|
|
176
180
|
for (const subClient of finalSubClients) {
|
|
177
181
|
const serverName = getServerName(subClient);
|
|
178
|
-
content +=
|
|
182
|
+
content += `${indent.get()}tr${serverName} *${serverName}Transport\n`;
|
|
179
183
|
}
|
|
180
184
|
}
|
|
181
185
|
for (const method of finalMethods) {
|
|
@@ -188,23 +192,23 @@ export function generateServers(pkg, target) {
|
|
|
188
192
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
189
193
|
}
|
|
190
194
|
requiredHelpers.tracker = true;
|
|
191
|
-
content +=
|
|
195
|
+
content += `${indent.get()}${naming.uncapitalize(fixUpMethodName(method))} *tracker[azfake.PollerResponder[${respType}]]\n`;
|
|
192
196
|
break;
|
|
193
197
|
case 'pageableMethod':
|
|
194
198
|
requiredHelpers.tracker = true;
|
|
195
|
-
content +=
|
|
199
|
+
content += `${indent.get()}${naming.uncapitalize(fixUpMethodName(method))} *tracker[azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]]\n`;
|
|
196
200
|
break;
|
|
197
201
|
}
|
|
198
202
|
}
|
|
199
203
|
content += '}\n\n';
|
|
200
|
-
content += generateServerTransportDo(serverTransport, client, finalSubClients, finalMethods);
|
|
201
|
-
content += generateServerTransportClientDispatch(serverTransport, finalSubClients, imports);
|
|
202
|
-
content += generateServerTransportMethodDispatch(serverTransport, client, finalMethods);
|
|
203
|
-
content += generateServerTransportMethods(pkg, serverTransport, finalMethods, imports);
|
|
204
|
+
content += generateServerTransportDo(serverTransport, client, finalSubClients, finalMethods, indent);
|
|
205
|
+
content += generateServerTransportClientDispatch(serverTransport, finalSubClients, imports, indent);
|
|
206
|
+
content += generateServerTransportMethodDispatch(serverTransport, client, finalMethods, indent);
|
|
207
|
+
content += generateServerTransportMethods(pkg, serverTransport, finalMethods, imports, indent);
|
|
204
208
|
content += `// set this to conditionally intercept incoming requests to ${serverTransport}\n`;
|
|
205
209
|
content += `var ${getTransportInterceptorVarName(client)} interface {\n`;
|
|
206
|
-
content +=
|
|
207
|
-
content +=
|
|
210
|
+
content += `${indent.get()}// Do returns true if the server transport should use the returned response/error\n`;
|
|
211
|
+
content += `${indent.get()}Do(*http.Request) (*http.Response, error, bool)\n}\n`;
|
|
208
212
|
///////////////////////////////////////////////////////////////////////////
|
|
209
213
|
// stitch everything together
|
|
210
214
|
let text = helpers.contentPreamble(pkg);
|
|
@@ -224,79 +228,93 @@ function getTransportInterceptorVarName(client) {
|
|
|
224
228
|
// method names for fakes dispatching
|
|
225
229
|
const dispatchMethodFake = 'dispatchToMethodFake';
|
|
226
230
|
const dispatchToClientFake = 'dispatchToClientFake';
|
|
227
|
-
function generateServerTransportDo(serverTransport, client, finalSubClients, finalMethods) {
|
|
231
|
+
function generateServerTransportDo(serverTransport, client, finalSubClients, finalMethods, indent) {
|
|
228
232
|
const receiverName = serverTransport[0].toLowerCase();
|
|
229
233
|
let content = `// Do implements the policy.Transporter interface for ${serverTransport}.\n`;
|
|
230
234
|
content += `func (${receiverName} *${serverTransport}) Do(req *http.Request) (*http.Response, error) {\n`;
|
|
231
|
-
content +=
|
|
232
|
-
content +=
|
|
233
|
-
content +=
|
|
235
|
+
content += `${indent.get()}rawMethod := req.Context().Value(runtime.CtxAPINameKey{})\n`;
|
|
236
|
+
content += `${indent.get()}method, ok := rawMethod.(string)\n`;
|
|
237
|
+
content += `${indent.get()}if !ok {\n`;
|
|
238
|
+
content += `${indent.push().get()}return nil, nonRetriableError{errors.New("unable to dispatch request, missing value for CtxAPINameKey")}\n`;
|
|
239
|
+
content += `${indent.pop().get()}}\n\n`;
|
|
234
240
|
if (finalSubClients.length > 0 && finalMethods.length > 0) {
|
|
235
241
|
// client contains client accessors and methods.
|
|
236
242
|
// if the method isn't for this client, dispatch to the correct client
|
|
237
|
-
content +=
|
|
238
|
-
content +=
|
|
243
|
+
content += `${indent.get()}if client := method[:strings.Index(method, ".")]; client != "${client.name}" {\n`;
|
|
244
|
+
content += `${indent.push().get()}return ${receiverName}.${dispatchToClientFake}(req, client)\n`;
|
|
245
|
+
content += `${indent.pop().get()}}\n`;
|
|
239
246
|
// else dispatch to our method fakes
|
|
240
|
-
content +=
|
|
247
|
+
content += `${indent.get()}return ${receiverName}.${dispatchMethodFake}(req, method)\n`;
|
|
241
248
|
}
|
|
242
249
|
else if (finalSubClients.length > 0) {
|
|
243
|
-
content +=
|
|
250
|
+
content += `${indent.get()}return ${receiverName}.${dispatchToClientFake}(req, method[:strings.Index(method, ".")])\n`;
|
|
244
251
|
}
|
|
245
252
|
else {
|
|
246
|
-
content +=
|
|
253
|
+
content += `${indent.get()}return ${receiverName}.${dispatchMethodFake}(req, method)\n`;
|
|
247
254
|
}
|
|
248
255
|
content += '}\n\n'; // end Do
|
|
249
256
|
return content;
|
|
250
257
|
}
|
|
251
|
-
function generateServerTransportClientDispatch(serverTransport, subClients, imports) {
|
|
258
|
+
function generateServerTransportClientDispatch(serverTransport, subClients, imports, indent) {
|
|
252
259
|
if (subClients.length === 0) {
|
|
253
260
|
return '';
|
|
254
261
|
}
|
|
255
262
|
const receiverName = serverTransport[0].toLowerCase();
|
|
256
263
|
imports.add('strings');
|
|
257
264
|
let content = `func (${receiverName} *${serverTransport}) ${dispatchToClientFake}(req *http.Request, client string) (*http.Response, error) {\n`;
|
|
258
|
-
content +=
|
|
259
|
-
content +=
|
|
265
|
+
content += `${indent.get()}var resp *http.Response\n${indent.get()}var err error\n\n`;
|
|
266
|
+
content += `${indent.get()}switch client {\n`;
|
|
260
267
|
for (const subClient of subClients) {
|
|
261
|
-
content +=
|
|
268
|
+
content += `${indent.get()}case "${subClient.name}":\n`;
|
|
262
269
|
const serverName = getServerName(subClient);
|
|
263
|
-
|
|
264
|
-
content +=
|
|
270
|
+
indent.push();
|
|
271
|
+
content += `${indent.get()}initServer(&${receiverName}.trMu, &${receiverName}.tr${serverName}, func() *${serverName}Transport {\n`;
|
|
272
|
+
content += `${indent.get()}return New${serverName}Transport(&${receiverName}.srv.${serverName}) })\n`;
|
|
273
|
+
content += `${indent.get()}resp, err = ${receiverName}.tr${serverName}.Do(req)\n`;
|
|
274
|
+
indent.pop();
|
|
265
275
|
}
|
|
266
|
-
content +=
|
|
267
|
-
content +=
|
|
268
|
-
|
|
276
|
+
content += `${indent.get()}default:\n`;
|
|
277
|
+
content += `${indent.push().get()}err = fmt.Errorf("unhandled client %s", client)\n`;
|
|
278
|
+
indent.pop();
|
|
279
|
+
content += `${indent.get()}}\n\n`; // end switch
|
|
280
|
+
content += `${indent.get()}return resp, err\n}\n\n`;
|
|
269
281
|
return content;
|
|
270
282
|
}
|
|
271
|
-
function generateServerTransportMethodDispatch(serverTransport, client, finalMethods) {
|
|
283
|
+
function generateServerTransportMethodDispatch(serverTransport, client, finalMethods, indent) {
|
|
272
284
|
if (finalMethods.length === 0) {
|
|
273
285
|
return '';
|
|
274
286
|
}
|
|
275
287
|
const receiverName = serverTransport[0].toLowerCase();
|
|
276
288
|
let content = `func (${receiverName} *${serverTransport}) ${dispatchMethodFake}(req *http.Request, method string) (*http.Response, error) {\n`;
|
|
277
|
-
content +=
|
|
278
|
-
content +=
|
|
289
|
+
content += `${indent.get()}resultChan := make(chan result, 1)\n`;
|
|
290
|
+
content += `${indent.get()}go func() {\n`;
|
|
291
|
+
indent.push();
|
|
292
|
+
content += `${indent.get()}var intercepted bool\n${indent.get()}var res result\n`;
|
|
279
293
|
const interceptorVarName = getTransportInterceptorVarName(client);
|
|
280
|
-
content +=
|
|
281
|
-
content +=
|
|
282
|
-
content +=
|
|
283
|
-
content +=
|
|
294
|
+
content += `${indent.get()} if ${interceptorVarName} != nil {\n`;
|
|
295
|
+
content += `${indent.push().get()} res.resp, res.err, intercepted = ${interceptorVarName}.Do(req)\n`;
|
|
296
|
+
content += `${indent.pop().get()}}\n`;
|
|
297
|
+
content += `${indent.get()}if !intercepted {\n`;
|
|
298
|
+
indent.push();
|
|
299
|
+
content += `${indent.get()}switch method {\n`;
|
|
284
300
|
for (const method of finalMethods) {
|
|
285
301
|
const operationName = fixUpMethodName(method);
|
|
286
|
-
content +=
|
|
287
|
-
content +=
|
|
302
|
+
content += `${indent.get()}case "${client.name}.${operationName}":\n`;
|
|
303
|
+
content += `${indent.push().get()}res.resp, res.err = ${receiverName}.dispatch${operationName}(req)\n`;
|
|
304
|
+
indent.pop();
|
|
288
305
|
}
|
|
289
|
-
content +=
|
|
290
|
-
content +=
|
|
291
|
-
content +=
|
|
292
|
-
content +=
|
|
293
|
-
content +=
|
|
294
|
-
content +=
|
|
295
|
-
content +=
|
|
296
|
-
content +=
|
|
297
|
-
content +=
|
|
298
|
-
content +=
|
|
299
|
-
content +=
|
|
306
|
+
content += `${indent.push().get()}default:\n`;
|
|
307
|
+
content += `${indent.get()}res.err = fmt.Errorf("unhandled API %s", method)\n`;
|
|
308
|
+
content += `${indent.pop().get()}}\n\n`; // end switch
|
|
309
|
+
content += `${indent.pop().get()}}\n`; // end if !intercepted
|
|
310
|
+
content += `${indent.get()}resultChan <- res\n`;
|
|
311
|
+
content += `${indent.pop().get()}}()\n\n`; // end goroutine
|
|
312
|
+
content += `${indent.get()}select {\n`;
|
|
313
|
+
content += `${indent.get()}case <-req.Context().Done():\n`;
|
|
314
|
+
content += `${indent.push().get()}return nil, req.Context().Err()\n`;
|
|
315
|
+
content += `${indent.pop().get()}case res := <-resultChan:\n`;
|
|
316
|
+
content += `${indent.push().get()}return res.resp, res.err\n`;
|
|
317
|
+
content += `${indent.pop().get()}}\n}\n\n`;
|
|
300
318
|
return content;
|
|
301
319
|
}
|
|
302
320
|
/**
|
|
@@ -306,9 +324,10 @@ function generateServerTransportMethodDispatch(serverTransport, client, finalMet
|
|
|
306
324
|
* @param serverTransport the name of the server transport type
|
|
307
325
|
* @param finalMethods the array of methods for which to generate the fake transports
|
|
308
326
|
* @param imports the import manager currently in scope
|
|
327
|
+
* @param indent the indentation helper currently in scope
|
|
309
328
|
* @returns the text for the server transport methods
|
|
310
329
|
*/
|
|
311
|
-
function generateServerTransportMethods(pkg, serverTransport, finalMethods, imports) {
|
|
330
|
+
function generateServerTransportMethods(pkg, serverTransport, finalMethods, imports, indent) {
|
|
312
331
|
if (finalMethods.length === 0) {
|
|
313
332
|
return '';
|
|
314
333
|
}
|
|
@@ -320,48 +339,52 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
320
339
|
let content = '';
|
|
321
340
|
for (const method of finalMethods) {
|
|
322
341
|
content += `func (${receiverName} *${serverTransport}) dispatch${fixUpMethodName(method)}(req *http.Request) (*http.Response, error) {\n`;
|
|
323
|
-
content +=
|
|
324
|
-
content +=
|
|
342
|
+
content += `${indent.get()}if ${receiverName}.srv.${fixUpMethodName(method)} == nil {\n`;
|
|
343
|
+
content += `${indent.push().get()}return nil, &nonRetriableError{errors.New("fake for method ${fixUpMethodName(method)} not implemented")}\n`;
|
|
344
|
+
content += `${indent.pop().get()}}\n`;
|
|
325
345
|
switch (method.kind) {
|
|
326
346
|
case 'lroMethod':
|
|
327
347
|
case 'lroPageableMethod':
|
|
328
348
|
// must check LRO before pager as you can have paged LROs
|
|
329
|
-
content += dispatchForLROBody(pkg, receiverName, method, imports);
|
|
349
|
+
content += dispatchForLROBody(pkg, receiverName, method, imports, indent);
|
|
330
350
|
break;
|
|
331
351
|
case 'method': {
|
|
332
|
-
content += dispatchForOperationBody(pkg, receiverName, method, imports);
|
|
333
|
-
content +=
|
|
352
|
+
content += dispatchForOperationBody(pkg, receiverName, method, imports, indent);
|
|
353
|
+
content += `${indent.get()}respContent := server.GetResponseContent(respr)\n`;
|
|
334
354
|
const formattedStatusCodes = helpers.formatStatusCodes(method.httpStatusCodes);
|
|
335
|
-
content +=
|
|
336
|
-
content +=
|
|
355
|
+
content += `${indent.get()}if !slices.Contains([]int{${formattedStatusCodes}}, respContent.HTTPStatus) {\n`;
|
|
356
|
+
content += `${indent.push().get()}return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are ${formattedStatusCodes}", respContent.HTTPStatus)}\n`;
|
|
357
|
+
content += `${indent.pop().get()}}\n`;
|
|
337
358
|
if (!method.returns.result || method.returns.result.kind === 'headAsBooleanResult') {
|
|
338
|
-
content +=
|
|
359
|
+
content += `${indent.get()}resp, err := server.NewResponse(respContent, req, nil)\n`;
|
|
339
360
|
}
|
|
340
361
|
else if (method.returns.result.kind === 'anyResult') {
|
|
341
|
-
content +=
|
|
362
|
+
content += `${indent.get()}resp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, server.GetResponse(respr).${getResultFieldName(method.returns.result)}, req)\n`;
|
|
342
363
|
}
|
|
343
364
|
else if (method.returns.result.kind === 'binaryResult') {
|
|
344
|
-
content +=
|
|
345
|
-
|
|
346
|
-
content +=
|
|
347
|
-
content +=
|
|
365
|
+
content += `${indent.get()}resp, err := server.NewResponse(respContent, req, &server.ResponseOptions{\n`;
|
|
366
|
+
indent.push();
|
|
367
|
+
content += `${indent.get()}Body: server.GetResponse(respr).${getResultFieldName(method.returns.result)},\n`;
|
|
368
|
+
content += `${indent.get()}ContentType: req.Header.Get("Content-Type"),\n`;
|
|
369
|
+
content += `${indent.pop().get()}})\n`;
|
|
348
370
|
}
|
|
349
371
|
else if (method.returns.result.kind === 'monomorphicResult') {
|
|
350
372
|
if (method.returns.result.monomorphicType.kind === 'encodedBytes') {
|
|
351
373
|
const encoding = method.returns.result.monomorphicType.encoding;
|
|
352
|
-
content +=
|
|
374
|
+
content += `${indent.get()}resp, err := server.MarshalResponseAsByteArray(respContent, server.GetResponse(respr).${getResultFieldName(method.returns.result)}, runtime.Base64${encoding}Format, req)\n`;
|
|
353
375
|
}
|
|
354
376
|
else if (method.returns.result.monomorphicType.kind === 'rawJSON') {
|
|
355
377
|
imports.add('bytes');
|
|
356
378
|
imports.add('io');
|
|
357
|
-
content +=
|
|
358
|
-
|
|
359
|
-
content +=
|
|
379
|
+
content += `${indent.get()}resp, err := server.NewResponse(respContent, req, &server.ResponseOptions{\n`;
|
|
380
|
+
indent.push();
|
|
381
|
+
content += `${indent.get()}Body: io.NopCloser(bytes.NewReader(server.GetResponse(respr).RawJSON)),\n`;
|
|
382
|
+
content += `${indent.get()}ContentType: "application/json",\n`;
|
|
383
|
+
content += `${indent.pop().get()}})\n`;
|
|
360
384
|
}
|
|
361
385
|
else {
|
|
362
386
|
let respField = `.${getResultFieldName(method.returns.result)}`;
|
|
363
387
|
if (method.returns.result.format === 'XML' && method.returns.result.monomorphicType.kind === 'slice') {
|
|
364
|
-
// for XML array responses we use the response type directly as it has the necessary XML tag for proper marshalling
|
|
365
388
|
respField = '';
|
|
366
389
|
}
|
|
367
390
|
let responseField = `server.GetResponse(respr)${respField}`;
|
|
@@ -369,34 +392,37 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
369
392
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
370
393
|
responseField = `(*datetime.${method.returns.result.monomorphicType.format})(${responseField})`;
|
|
371
394
|
}
|
|
372
|
-
content +=
|
|
395
|
+
content += `${indent.get()}resp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, ${responseField}, req)\n`;
|
|
373
396
|
}
|
|
374
397
|
}
|
|
375
398
|
else if (method.returns.result.kind === 'modelResult' || method.returns.result.kind === 'polymorphicResult') {
|
|
376
399
|
const respField = `.${getResultFieldName(method.returns.result)}`;
|
|
377
400
|
const responseField = `server.GetResponse(respr)${respField}`;
|
|
378
|
-
content +=
|
|
401
|
+
content += `${indent.get()}resp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, ${responseField}, req)\n`;
|
|
379
402
|
}
|
|
380
|
-
content +=
|
|
403
|
+
content += `${indent.get()}if err != nil {\n`;
|
|
404
|
+
content += `${indent.push().get()}return nil, err\n`;
|
|
405
|
+
content += `${indent.pop().get()}}\n`;
|
|
381
406
|
// propagate any header response values into the *http.Response
|
|
382
407
|
for (const header of method.returns.headers) {
|
|
383
408
|
if (header.kind === 'headerMapResponse') {
|
|
384
|
-
content +=
|
|
385
|
-
content +=
|
|
386
|
-
content +=
|
|
387
|
-
content +=
|
|
388
|
-
content +=
|
|
409
|
+
content += `${indent.get()}for k, v := range server.GetResponse(respr).${header.fieldName} {\n`;
|
|
410
|
+
content += `${indent.push().get()}if v != nil {\n`;
|
|
411
|
+
content += `${indent.push().get()}resp.Header.Set("${header.headerName}"+k, *v)\n`;
|
|
412
|
+
content += `${indent.pop().get()}}\n`;
|
|
413
|
+
content += `${indent.pop().get()}}\n`;
|
|
389
414
|
}
|
|
390
415
|
else {
|
|
391
|
-
content +=
|
|
392
|
-
content +=
|
|
416
|
+
content += `${indent.get()}if val := server.GetResponse(respr).${header.fieldName}; val != nil {\n`;
|
|
417
|
+
content += `${indent.push().get()}resp.Header.Set("${header.headerName}", ${helpers.formatValue('val', header.type, imports, true)})\n`;
|
|
418
|
+
content += `${indent.pop().get()}}\n`;
|
|
393
419
|
}
|
|
394
420
|
}
|
|
395
|
-
content +=
|
|
421
|
+
content += `${indent.get()}return resp, nil\n`;
|
|
396
422
|
break;
|
|
397
423
|
}
|
|
398
424
|
case 'pageableMethod':
|
|
399
|
-
content += dispatchForPagerBody(pkg, receiverName, method, imports);
|
|
425
|
+
content += dispatchForPagerBody(pkg, receiverName, method, imports, indent);
|
|
400
426
|
break;
|
|
401
427
|
default:
|
|
402
428
|
method;
|
|
@@ -413,25 +439,26 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
413
439
|
* @param receiverName the name of the receiver for the dispatch method
|
|
414
440
|
* @param method the method for which to emit dispatching logic
|
|
415
441
|
* @param imports the import manager currently in scope
|
|
442
|
+
* @param indent the indentation helper currently in scope
|
|
416
443
|
* @returns the text for dispatching logic
|
|
417
444
|
*/
|
|
418
|
-
function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
445
|
+
function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
419
446
|
const methodParamGroups = helpers.getMethodParamGroups(method);
|
|
420
447
|
const numPathParams = methodParamGroups.pathParams.filter((each) => !go.isLiteralParameter(each.style)).length;
|
|
421
448
|
let content = '';
|
|
422
449
|
if (numPathParams > 0) {
|
|
423
450
|
imports.add('regexp');
|
|
424
|
-
content +=
|
|
425
|
-
content +=
|
|
426
|
-
content +=
|
|
451
|
+
content += `${indent.get()}const regexStr = \`${createPathParamsRegex(method, methodParamGroups.pathParams)}\`\n`;
|
|
452
|
+
content += `${indent.get()}regex := regexp.MustCompile(regexStr)\n`;
|
|
453
|
+
content += `${indent.get()}matches := regex.FindStringSubmatch(req.URL.EscapedPath())\n`;
|
|
427
454
|
// the total number of matches is the number of capture groups
|
|
428
455
|
// plus the full match. so we add + 1 to include the full match.
|
|
429
|
-
content +=
|
|
430
|
-
content +=
|
|
456
|
+
content += `${indent.get()}if len(matches) < ${numPathParams + 1} {\n`;
|
|
457
|
+
content += `${indent.push().get()}return nil, fmt.Errorf("failed to parse path %s", req.URL.Path)\n${indent.pop().get()}}\n`;
|
|
431
458
|
}
|
|
432
459
|
const allQueryParams = methodParamGroups.encodedQueryParams.concat(methodParamGroups.unencodedQueryParams);
|
|
433
460
|
if (allQueryParams.find((each) => each.location === 'method' && !go.isLiteralParameter(each.style))) {
|
|
434
|
-
content +=
|
|
461
|
+
content += `${indent.get()}qp := req.URL.Query()\n`;
|
|
435
462
|
}
|
|
436
463
|
// note that these are mutually exclusive
|
|
437
464
|
const bodyParam = methodParamGroups.bodyParam;
|
|
@@ -446,21 +473,21 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
446
473
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
|
|
447
474
|
switch (bodyParam.type.kind) {
|
|
448
475
|
case 'encodedBytes':
|
|
449
|
-
content +=
|
|
450
|
-
content +=
|
|
476
|
+
content += `${indent.get()}body, err := server.UnmarshalRequestAsByteArray(req, runtime.Base64${bodyParam.type.encoding}Format)\n`;
|
|
477
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
451
478
|
break;
|
|
452
479
|
case 'interface':
|
|
453
480
|
requiredHelpers.readRequestBody = true;
|
|
454
|
-
content +=
|
|
455
|
-
content +=
|
|
456
|
-
content +=
|
|
457
|
-
content +=
|
|
481
|
+
content += `${indent.get()}raw, err := readRequestBody(req)\n`;
|
|
482
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
483
|
+
content += `${indent.get()}body, err := unmarshal${bodyParam.type.name}(raw)\n`;
|
|
484
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
458
485
|
break;
|
|
459
486
|
case 'rawJSON':
|
|
460
487
|
imports.add('io');
|
|
461
|
-
content +=
|
|
462
|
-
content +=
|
|
463
|
-
content +=
|
|
488
|
+
content += `${indent.get()}body, err := io.ReadAll(req.Body)\n`;
|
|
489
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
490
|
+
content += `${indent.get()}req.Body.Close()\n`;
|
|
464
491
|
break;
|
|
465
492
|
default: {
|
|
466
493
|
let bodyTypeName = go.getTypeDeclaration(bodyParam.type, pkg);
|
|
@@ -468,8 +495,8 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
468
495
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
469
496
|
bodyTypeName = `datetime.${bodyParam.type.format}`;
|
|
470
497
|
}
|
|
471
|
-
content +=
|
|
472
|
-
content +=
|
|
498
|
+
content += `${indent.get()}body, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
|
|
499
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
473
500
|
}
|
|
474
501
|
}
|
|
475
502
|
}
|
|
@@ -477,8 +504,8 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
477
504
|
case 'Text':
|
|
478
505
|
if (bodyParam && !go.isLiteralParameter(bodyParam.style)) {
|
|
479
506
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
|
|
480
|
-
content +=
|
|
481
|
-
content +=
|
|
507
|
+
content += `${indent.get()}body, err := server.UnmarshalRequestAsText(req)\n`;
|
|
508
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
482
509
|
}
|
|
483
510
|
break;
|
|
484
511
|
}
|
|
@@ -488,19 +515,20 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
488
515
|
imports.add('io');
|
|
489
516
|
imports.add('mime');
|
|
490
517
|
imports.add('mime/multipart');
|
|
491
|
-
content +=
|
|
492
|
-
content +=
|
|
493
|
-
content +=
|
|
518
|
+
content += `${indent.get()}_, params, err := mime.ParseMediaType(req.Header.Get("Content-Type"))\n`;
|
|
519
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
520
|
+
content += `${indent.get()}reader := multipart.NewReader(req.Body, params["boundary"])\n`;
|
|
494
521
|
for (const param of multipartBodyParams) {
|
|
495
|
-
content +=
|
|
522
|
+
content += `${indent.get()}var ${param.name} ${go.getTypeDeclaration(param.type, pkg)}\n`;
|
|
496
523
|
}
|
|
497
|
-
content +=
|
|
498
|
-
|
|
499
|
-
content +=
|
|
500
|
-
content +=
|
|
501
|
-
content +=
|
|
502
|
-
content +=
|
|
503
|
-
content +=
|
|
524
|
+
content += `${indent.get()}for {\n`;
|
|
525
|
+
indent.push();
|
|
526
|
+
content += `${indent.get()}var part *multipart.Part\n`;
|
|
527
|
+
content += `${indent.get()}part, err = reader.NextPart()\n`;
|
|
528
|
+
content += `${indent.get()}if errors.Is(err, io.EOF) {\n${indent.push().get()}break\n`;
|
|
529
|
+
content += `${indent.pop().get()}} else if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
530
|
+
content += `${indent.get()}var content []byte\n`;
|
|
531
|
+
content += `${indent.get()}switch fn := part.FormName(); fn {\n`;
|
|
504
532
|
// specify boolTarget if parsing bools happens in place.
|
|
505
533
|
// i.e. the result from the parsing doesn't require further conversion (e.g. casting)
|
|
506
534
|
// otherwise the parsed value is in a local var named parsed.
|
|
@@ -513,40 +541,41 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
513
541
|
case 'bool':
|
|
514
542
|
if (boolTarget) {
|
|
515
543
|
// we reuse the err var declared earlier when calling reader.NextPart()
|
|
516
|
-
parsingCode =
|
|
544
|
+
parsingCode = `${indent.get()}${boolTarget}, err = strconv.ParseBool(string(content))\n`;
|
|
517
545
|
parseErr = 'err';
|
|
518
546
|
}
|
|
519
547
|
else {
|
|
520
|
-
parsingCode =
|
|
548
|
+
parsingCode = `${indent.get()}${parseResults} := strconv.ParseBool(string(content))\n`;
|
|
521
549
|
}
|
|
522
550
|
break;
|
|
523
551
|
case 'float32':
|
|
524
552
|
case 'float64':
|
|
525
|
-
parsingCode =
|
|
553
|
+
parsingCode = `${indent.get()}${parseResults} := strconv.ParseFloat(string(content), ${helpers.getBitSizeForNumber(typeName)})\n`;
|
|
526
554
|
break;
|
|
527
555
|
case 'int8':
|
|
528
556
|
case 'int16':
|
|
529
557
|
case 'int32':
|
|
530
558
|
case 'int64':
|
|
531
|
-
parsingCode =
|
|
559
|
+
parsingCode = `${indent.get()}${parseResults} := strconv.ParseInt(string(content), 10, ${helpers.getBitSizeForNumber(typeName)})\n`;
|
|
532
560
|
break;
|
|
533
561
|
default:
|
|
534
562
|
throw new CodegenError('InternalError', `unhandled multipart parameter primitive type ${typeName}`);
|
|
535
563
|
}
|
|
536
|
-
parsingCode +=
|
|
564
|
+
parsingCode += `${indent.get()}if ${parseErr} != nil {\n${indent.push().get()}return nil, ${parseErr}\n${indent.pop().get()}}\n`;
|
|
537
565
|
return parsingCode;
|
|
538
566
|
};
|
|
539
567
|
const isModelType = function (type) {
|
|
540
568
|
return type.kind === 'model' || type.kind === 'polymorphicModel';
|
|
541
569
|
};
|
|
542
570
|
const emitCase = function (caseValue, paramVar, type) {
|
|
543
|
-
let caseContent =
|
|
544
|
-
|
|
545
|
-
caseContent +=
|
|
571
|
+
let caseContent = `${indent.get()}case "${caseValue}":\n`;
|
|
572
|
+
indent.push();
|
|
573
|
+
caseContent += `${indent.get()}content, err = io.ReadAll(part)\n`;
|
|
574
|
+
caseContent += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
546
575
|
let assignedValue;
|
|
547
576
|
if (isModelType(helpers.recursiveUnwrapMapSlice(type))) {
|
|
548
577
|
imports.add('encoding/json');
|
|
549
|
-
caseContent +=
|
|
578
|
+
caseContent += `${indent.get()}if err = json.Unmarshal(content, &${paramVar}); err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
550
579
|
}
|
|
551
580
|
else if (type.kind === 'readSeekCloser') {
|
|
552
581
|
imports.add('bytes');
|
|
@@ -600,16 +629,17 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
600
629
|
const contentType = 'part.Header.Get("Content-Type")';
|
|
601
630
|
const filename = 'part.FileName()';
|
|
602
631
|
if (type.kind === 'slice') {
|
|
603
|
-
caseContent +=
|
|
604
|
-
|
|
605
|
-
caseContent +=
|
|
606
|
-
caseContent +=
|
|
607
|
-
caseContent +=
|
|
632
|
+
caseContent += `${indent.get()}${paramVar} = append(${paramVar}, streaming.MultipartContent{\n`;
|
|
633
|
+
indent.push();
|
|
634
|
+
caseContent += `${indent.get()}Body: ${bodyContent},\n`;
|
|
635
|
+
caseContent += `${indent.get()}ContentType: ${contentType},\n`;
|
|
636
|
+
caseContent += `${indent.get()}Filename: ${filename},\n`;
|
|
637
|
+
caseContent += `${indent.pop().get()}})\n`;
|
|
608
638
|
}
|
|
609
639
|
else {
|
|
610
|
-
caseContent +=
|
|
611
|
-
caseContent +=
|
|
612
|
-
caseContent +=
|
|
640
|
+
caseContent += `${indent.get()}${paramVar}.Body = ${bodyContent}\n`;
|
|
641
|
+
caseContent += `${indent.get()}${paramVar}.ContentType = ${contentType}\n`;
|
|
642
|
+
caseContent += `${indent.get()}${paramVar}.Filename = ${filename}\n`;
|
|
613
643
|
}
|
|
614
644
|
}
|
|
615
645
|
else if (type.kind === 'slice') {
|
|
@@ -626,8 +656,9 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
626
656
|
throw new CodegenError('InternalError', `uhandled multipart parameter kind ${type.kind}`);
|
|
627
657
|
}
|
|
628
658
|
if (assignedValue) {
|
|
629
|
-
caseContent +=
|
|
659
|
+
caseContent += `${indent.get()}${paramVar} = ${assignedValue}\n`;
|
|
630
660
|
}
|
|
661
|
+
indent.pop();
|
|
631
662
|
return caseContent;
|
|
632
663
|
};
|
|
633
664
|
for (const param of multipartBodyParams) {
|
|
@@ -640,19 +671,20 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
640
671
|
content += emitCase(param.name, param.name, param.type);
|
|
641
672
|
}
|
|
642
673
|
}
|
|
643
|
-
content +=
|
|
644
|
-
content +=
|
|
645
|
-
content +=
|
|
674
|
+
content += `${indent.get()}default:\n`;
|
|
675
|
+
content += `${indent.push().get()}return nil, fmt.Errorf("unexpected part %s", fn)\n`;
|
|
676
|
+
content += `${indent.pop().get()}}\n`; // end switch
|
|
677
|
+
content += `${indent.pop().get()}}\n`; // end for
|
|
646
678
|
}
|
|
647
679
|
else if (formBodyParams.length > 0) {
|
|
648
680
|
for (const param of formBodyParams) {
|
|
649
|
-
content +=
|
|
681
|
+
content += `${indent.get()}var ${param.name} ${go.getTypeDeclaration(param.type, pkg)}\n`;
|
|
650
682
|
}
|
|
651
|
-
content +=
|
|
652
|
-
content +=
|
|
653
|
-
content +=
|
|
683
|
+
content += `${indent.get()}if err := req.ParseForm(); err != nil {\n${indent.push().get()}return nil, &nonRetriableError{fmt.Errorf("failed parsing form data: %v", err)}\n${indent.pop().get()}}\n`;
|
|
684
|
+
content += `${indent.get()}for key := range req.Form {\n`;
|
|
685
|
+
content += `${indent.push().get()}switch key {\n`;
|
|
654
686
|
for (const param of formBodyParams) {
|
|
655
|
-
content +=
|
|
687
|
+
content += `${indent.get()}case "${param.formDataName}":\n`;
|
|
656
688
|
let assignedValue;
|
|
657
689
|
switch (param.type.kind) {
|
|
658
690
|
case 'constant':
|
|
@@ -664,22 +696,24 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
664
696
|
default:
|
|
665
697
|
throw new CodegenError('InternalError', `uhandled form parameter kind ${param.type.kind}`);
|
|
666
698
|
}
|
|
667
|
-
content +=
|
|
699
|
+
content += `${indent.push().get()}${param.name} = ${assignedValue}\n`;
|
|
700
|
+
indent.pop();
|
|
668
701
|
}
|
|
669
|
-
content +=
|
|
670
|
-
content +=
|
|
702
|
+
content += `${indent.pop().get()}}\n`; // end switch
|
|
703
|
+
content += `${indent.get()}}\n`; // end for
|
|
671
704
|
}
|
|
672
705
|
else if (partialBodyParams.length > 0) {
|
|
673
706
|
// construct the partial body params type and unmarshal it
|
|
674
|
-
content +=
|
|
707
|
+
content += `${indent.get()}type partialBodyParams struct {\n`;
|
|
708
|
+
indent.push();
|
|
675
709
|
for (const partialBodyParam of partialBodyParams) {
|
|
676
|
-
content +=
|
|
710
|
+
content += `${indent.get()}${naming.capitalize(partialBodyParam.name)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
|
|
677
711
|
}
|
|
678
|
-
content +=
|
|
679
|
-
content +=
|
|
680
|
-
content +=
|
|
712
|
+
content += `${indent.pop().get()}}\n`;
|
|
713
|
+
content += `${indent.get()}body, err := server.UnmarshalRequestAs${partialBodyParams[0].format}[partialBodyParams](req)\n`;
|
|
714
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
681
715
|
}
|
|
682
|
-
const result = parseHeaderPathQueryParams(pkg, method, imports);
|
|
716
|
+
const result = parseHeaderPathQueryParams(pkg, method, imports, indent);
|
|
683
717
|
content += result.content;
|
|
684
718
|
// translate each partial body param to its field within the unmarshalled body
|
|
685
719
|
for (const partialBodyParam of partialBodyParams) {
|
|
@@ -690,9 +724,9 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
690
724
|
content += `resp ${apiCall}\n`;
|
|
691
725
|
return content;
|
|
692
726
|
}
|
|
693
|
-
content +=
|
|
694
|
-
content +=
|
|
695
|
-
content +=
|
|
727
|
+
content += `${indent.get()}respr, errRespr ${apiCall}\n`;
|
|
728
|
+
content += `${indent.get()}if respErr := server.GetError(errRespr, req); respErr != nil {\n`;
|
|
729
|
+
content += `${indent.push().get()}return nil, respErr\n${indent.pop().get()}}\n`;
|
|
696
730
|
return content;
|
|
697
731
|
}
|
|
698
732
|
function getMethodStatusCodes(method) {
|
|
@@ -720,27 +754,34 @@ function getMethodStatusCodes(method) {
|
|
|
720
754
|
* @param receiverName the name of the receiver for the dispatch method
|
|
721
755
|
* @param method the LRO method for which to emit the dispatch logic
|
|
722
756
|
* @param imports the import manager currently in scope
|
|
757
|
+
* @param indent the indentation helper currently in scope
|
|
723
758
|
* @returns the text for the LRO dispatch logic
|
|
724
759
|
*/
|
|
725
|
-
function dispatchForLROBody(pkg, receiverName, method, imports) {
|
|
760
|
+
function dispatchForLROBody(pkg, receiverName, method, imports, indent) {
|
|
726
761
|
const operationName = fixUpMethodName(method);
|
|
727
762
|
const localVarName = naming.uncapitalize(operationName);
|
|
728
763
|
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
729
|
-
let content =
|
|
730
|
-
content +=
|
|
731
|
-
content += dispatchForOperationBody(pkg, receiverName, method, imports);
|
|
732
|
-
|
|
733
|
-
content +=
|
|
734
|
-
content +=
|
|
735
|
-
content +=
|
|
736
|
-
content +=
|
|
764
|
+
let content = `${indent.get()}${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
765
|
+
content += `${indent.get()}if ${localVarName} == nil {\n`;
|
|
766
|
+
content += dispatchForOperationBody(pkg, receiverName, method, imports, indent);
|
|
767
|
+
indent.push();
|
|
768
|
+
content += `${indent.get()}${localVarName} = &respr\n`;
|
|
769
|
+
content += `${indent.get()}${operationStateMachine}.add(req, ${localVarName})\n`;
|
|
770
|
+
content += `${indent.pop().get()}}\n\n`;
|
|
771
|
+
content += `${indent.get()}resp, err := server.PollerResponderNext(${localVarName}, req)\n`;
|
|
772
|
+
content += `${indent.get()}if err != nil {\n`;
|
|
773
|
+
content += `${indent.push().get()}return nil, err\n`;
|
|
774
|
+
content += `${indent.pop().get()}}\n\n`;
|
|
737
775
|
const formattedStatusCodes = helpers.formatStatusCodes(getMethodStatusCodes(method));
|
|
738
|
-
content +=
|
|
739
|
-
|
|
740
|
-
content +=
|
|
741
|
-
content +=
|
|
742
|
-
content +=
|
|
743
|
-
content +=
|
|
776
|
+
content += `${indent.get()}if !slices.Contains([]int{${formattedStatusCodes}}, resp.StatusCode) {\n`;
|
|
777
|
+
indent.push();
|
|
778
|
+
content += `${indent.get()}${operationStateMachine}.remove(req)\n`;
|
|
779
|
+
content += `${indent.get()}return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are ${formattedStatusCodes}", resp.StatusCode)}\n`;
|
|
780
|
+
content += `${indent.pop().get()}}\n`;
|
|
781
|
+
content += `${indent.get()}if !server.PollerResponderMore(${localVarName}) {\n`;
|
|
782
|
+
content += `${indent.push().get()}${operationStateMachine}.remove(req)\n`;
|
|
783
|
+
content += `${indent.pop().get()}}\n\n`;
|
|
784
|
+
content += `${indent.get()}return resp, nil\n`;
|
|
744
785
|
return content;
|
|
745
786
|
}
|
|
746
787
|
/**
|
|
@@ -750,33 +791,41 @@ function dispatchForLROBody(pkg, receiverName, method, imports) {
|
|
|
750
791
|
* @param receiverName the name of the receiver for the dispatch method
|
|
751
792
|
* @param method the pageable method for which to emit the dispatch logic
|
|
752
793
|
* @param imports the import manager currently in scope
|
|
794
|
+
* @param indent the indentation helper currently in scope
|
|
753
795
|
* @returns the text for the pageable dispatch logic
|
|
754
796
|
*/
|
|
755
|
-
function dispatchForPagerBody(pkg, receiverName, method, imports) {
|
|
797
|
+
function dispatchForPagerBody(pkg, receiverName, method, imports, indent) {
|
|
756
798
|
const operationName = fixUpMethodName(method);
|
|
757
799
|
const localVarName = naming.uncapitalize(operationName);
|
|
758
800
|
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
759
|
-
let content =
|
|
760
|
-
content +=
|
|
761
|
-
content += dispatchForOperationBody(pkg, receiverName, method, imports);
|
|
762
|
-
|
|
763
|
-
content +=
|
|
764
|
-
|
|
801
|
+
let content = `${indent.get()}${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
802
|
+
content += `${indent.get()}if ${localVarName} == nil {\n`;
|
|
803
|
+
content += dispatchForOperationBody(pkg, receiverName, method, imports, indent);
|
|
804
|
+
indent.push();
|
|
805
|
+
content += `${indent.get()}${localVarName} = &resp\n`;
|
|
806
|
+
content += `${indent.get()}${operationStateMachine}.add(req, ${localVarName})\n`;
|
|
807
|
+
if (method.strategy?.kind === 'nextLink') {
|
|
765
808
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/to');
|
|
766
|
-
content +=
|
|
767
|
-
content +=
|
|
768
|
-
content +=
|
|
809
|
+
content += `${indent.get()}server.PagerResponderInjectNextLinks(${localVarName}, req, func(page *${go.getTypeDeclaration(method.returns, pkg)}, createLink func() string) {\n`;
|
|
810
|
+
content += `${indent.push().get()}page.${helpers.buildNextLinkPath(method.strategy)} = to.Ptr(createLink())\n`;
|
|
811
|
+
content += `${indent.pop().get()}})\n`;
|
|
769
812
|
}
|
|
770
|
-
|
|
771
|
-
content +=
|
|
772
|
-
content +=
|
|
813
|
+
indent.pop();
|
|
814
|
+
content += `${indent.get()}}\n`; // end if
|
|
815
|
+
content += `${indent.get()}resp, err := server.PagerResponderNext(${localVarName}, req)\n`;
|
|
816
|
+
content += `${indent.get()}if err != nil {\n`;
|
|
817
|
+
content += `${indent.push().get()}return nil, err\n`;
|
|
818
|
+
content += `${indent.pop().get()}}\n`;
|
|
773
819
|
const formattedStatusCodes = helpers.formatStatusCodes(method.httpStatusCodes);
|
|
774
|
-
content +=
|
|
775
|
-
|
|
776
|
-
content +=
|
|
777
|
-
content +=
|
|
778
|
-
content +=
|
|
779
|
-
content +=
|
|
820
|
+
content += `${indent.get()}if !slices.Contains([]int{${formattedStatusCodes}}, resp.StatusCode) {\n`;
|
|
821
|
+
indent.push();
|
|
822
|
+
content += `${indent.get()}${operationStateMachine}.remove(req)\n`;
|
|
823
|
+
content += `${indent.get()}return nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are ${formattedStatusCodes}", resp.StatusCode)}\n`;
|
|
824
|
+
content += `${indent.pop().get()}}\n`;
|
|
825
|
+
content += `${indent.get()}if !server.PagerResponderMore(${localVarName}) {\n`;
|
|
826
|
+
content += `${indent.push().get()}${operationStateMachine}.remove(req)\n`;
|
|
827
|
+
content += `${indent.pop().get()}}\n`;
|
|
828
|
+
content += `${indent.get()}return resp, nil\n`;
|
|
780
829
|
return content;
|
|
781
830
|
}
|
|
782
831
|
function sanitizeRegexpCaptureGroupName(name) {
|
|
@@ -808,9 +857,10 @@ function createPathParamsRegex(method, pathParams) {
|
|
|
808
857
|
* @param pkg contains the package contents
|
|
809
858
|
* @param method the method for which to emit parameter parsing logic
|
|
810
859
|
* @param imports the import manager currently in scope
|
|
860
|
+
* @param indent the indentation helper currently in scope
|
|
811
861
|
* @returns the parsing code and the params that contain the parsed values
|
|
812
862
|
*/
|
|
813
|
-
function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
863
|
+
function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
814
864
|
let content = '';
|
|
815
865
|
const paramValues = new Map();
|
|
816
866
|
const createLocalVariableName = function (param, suffix) {
|
|
@@ -877,10 +927,10 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
877
927
|
// for string-based enums, we perform the conversion as part of unescaping
|
|
878
928
|
requiredHelpers.parseWithCast = true;
|
|
879
929
|
paramVar = createLocalVariableName(param, 'Param');
|
|
880
|
-
content +=
|
|
881
|
-
content +=
|
|
882
|
-
content +=
|
|
883
|
-
content +=
|
|
930
|
+
content += `${indent.get()}${paramVar}, err := parseWithCast(${paramValue}, func (v string) (${go.getTypeDeclaration(param.type, pkg)}, error) {\n`;
|
|
931
|
+
content += `${indent.push().get()}p, unescapeErr := url.PathUnescape(v)\n`;
|
|
932
|
+
content += `${indent.get()}if unescapeErr != nil {\n${indent.push().get()}return "", unescapeErr\n${indent.pop().get()}}\n`;
|
|
933
|
+
content += `${indent.get()}return ${go.getTypeDeclaration(param.type, pkg)}(p), nil\n${indent.pop().get()}})\n`;
|
|
884
934
|
}
|
|
885
935
|
else {
|
|
886
936
|
if (go.isRequiredParameter(param.style) && (param.type.kind === 'string' || (param.type.kind === 'slice' && param.type.elementType.kind === 'string'))) {
|
|
@@ -889,9 +939,9 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
889
939
|
// else requires some amount of parsing/conversion.
|
|
890
940
|
paramVar = createLocalVariableName(param, 'Param');
|
|
891
941
|
}
|
|
892
|
-
content +=
|
|
942
|
+
content += `${indent.get()}${paramVar}, err := url.PathUnescape(${paramValue})\n`;
|
|
893
943
|
}
|
|
894
|
-
content +=
|
|
944
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
895
945
|
paramValue = paramVar;
|
|
896
946
|
}
|
|
897
947
|
// parse params as required
|
|
@@ -901,7 +951,7 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
901
951
|
if (param.collectionFormat !== 'multi') {
|
|
902
952
|
requiredHelpers.splitHelper = true;
|
|
903
953
|
const elementsParam = createLocalVariableName(param, 'Elements');
|
|
904
|
-
content +=
|
|
954
|
+
content += `${indent.get()}${elementsParam} := splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")\n`;
|
|
905
955
|
paramValue = elementsParam;
|
|
906
956
|
}
|
|
907
957
|
const paramVar = createLocalVariableName(param, 'Param');
|
|
@@ -921,20 +971,21 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
921
971
|
throw new CodegenError('InternalError', `unhandled element kind ${param.type.elementType.kind}`);
|
|
922
972
|
}
|
|
923
973
|
const toType = go.getTypeDeclaration(param.type.elementType, pkg);
|
|
924
|
-
content +=
|
|
925
|
-
content +=
|
|
974
|
+
content += `${indent.get()}${paramVar} := make([]${toType}, len(${paramValue}))\n`;
|
|
975
|
+
content += `${indent.get()}for i := 0; i < len(${paramValue}); i++ {\n`;
|
|
976
|
+
indent.push();
|
|
926
977
|
let fromVar;
|
|
927
978
|
// TODO: consolidate with non-collection parsing code
|
|
928
979
|
if (elementFormat === 'bool') {
|
|
929
980
|
imports.add('strconv');
|
|
930
981
|
fromVar = 'parsedBool';
|
|
931
|
-
content +=
|
|
932
|
-
content +=
|
|
982
|
+
content += `${indent.get()}${fromVar}, parseErr := strconv.ParseBool(${paramValue}[i])\n`;
|
|
983
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return nil, parseErr\n${indent.pop().get()}}\n`;
|
|
933
984
|
}
|
|
934
985
|
else if (elementFormat === 'float32' || elementFormat === 'float64' || elementFormat === 'int32' || elementFormat === 'int64') {
|
|
935
986
|
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
936
|
-
content +=
|
|
937
|
-
content +=
|
|
987
|
+
content += `${indent.get()}${fromVar}, parseErr := ${emitNumericConversion(`${paramValue}[i]`, elementFormat)}\n`;
|
|
988
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return nil, parseErr\n${indent.pop().get()}}\n`;
|
|
938
989
|
}
|
|
939
990
|
else if (elementFormat === 'string') {
|
|
940
991
|
// we're casting an enum string value to its const type
|
|
@@ -944,39 +995,39 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
944
995
|
else if (elementFormat === 'Std' || elementFormat === 'URL') {
|
|
945
996
|
imports.add('encoding/base64');
|
|
946
997
|
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
947
|
-
content +=
|
|
948
|
-
content +=
|
|
998
|
+
content += `${indent.get()}${fromVar}, parseErr := base64.${elementFormat}Encoding.DecodeString(${paramValue}[i])\n`;
|
|
999
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return nil, parseErr\n${indent.pop().get()}}\n`;
|
|
949
1000
|
}
|
|
950
1001
|
else if (elementFormat === 'RFC1123' || elementFormat === 'RFC3339' || elementFormat === 'Unix') {
|
|
951
1002
|
imports.add('time');
|
|
952
1003
|
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
953
1004
|
if (elementFormat === 'Unix') {
|
|
954
1005
|
imports.add('strconv');
|
|
955
|
-
content +=
|
|
956
|
-
content +=
|
|
957
|
-
content +=
|
|
1006
|
+
content += `${indent.get()}p, parseErr := strconv.ParseInt(${paramValue}[i], 10, 64)\n`;
|
|
1007
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return nil, parseErr\n${indent.pop().get()}}\n`;
|
|
1008
|
+
content += `${indent.get()}${fromVar} := time.Unix(p, 0).UTC()\n`;
|
|
958
1009
|
}
|
|
959
1010
|
else {
|
|
960
1011
|
let format = 'time.RFC3339Nano';
|
|
961
1012
|
if (elementFormat === 'RFC1123') {
|
|
962
1013
|
format = 'time.RFC1123';
|
|
963
1014
|
}
|
|
964
|
-
content +=
|
|
965
|
-
content +=
|
|
1015
|
+
content += `${indent.get()}${fromVar}, parseErr := time.Parse(${format}, ${paramValue}[i])\n`;
|
|
1016
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return nil, parseErr\n${indent.pop().get()}}\n`;
|
|
966
1017
|
}
|
|
967
1018
|
}
|
|
968
1019
|
else {
|
|
969
1020
|
throw new CodegenError('InternalError', `unhandled element format ${elementFormat}`);
|
|
970
1021
|
}
|
|
971
1022
|
// TODO: remove cast in some cases
|
|
972
|
-
content +=
|
|
1023
|
+
content += `${indent.get()}${paramVar}[i] = ${toType}(${fromVar})\n${indent.pop().get()}}\n`;
|
|
973
1024
|
}
|
|
974
1025
|
else if (!go.isRequiredParameter(param.style) && param.collectionFormat !== 'multi') {
|
|
975
1026
|
// for slices of strings that are required, the call to splitHelper(...) is inlined into
|
|
976
1027
|
// the invocation of the fake e.g. srv.FakeFunc(splitHelper...). but if it's optional, we
|
|
977
1028
|
// need to create a local first which will later be copied into the optional param group.
|
|
978
1029
|
requiredHelpers.splitHelper = true;
|
|
979
|
-
content +=
|
|
1030
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')} := splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")\n`;
|
|
980
1031
|
}
|
|
981
1032
|
}
|
|
982
1033
|
else if (param.type.kind === 'scalar' && param.type.type === 'bool') {
|
|
@@ -986,13 +1037,13 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
986
1037
|
requiredHelpers.parseOptional = true;
|
|
987
1038
|
from = `parseOptional(${paramValue}, strconv.ParseBool)`;
|
|
988
1039
|
}
|
|
989
|
-
content +=
|
|
990
|
-
content +=
|
|
1040
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${from}\n`;
|
|
1041
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
991
1042
|
}
|
|
992
1043
|
else if (param.type.kind === 'encodedBytes') {
|
|
993
1044
|
imports.add('encoding/base64');
|
|
994
|
-
content +=
|
|
995
|
-
content +=
|
|
1045
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := base64.${param.type.encoding}Encoding.DecodeString(${paramValue})\n`;
|
|
1046
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
996
1047
|
}
|
|
997
1048
|
else if (param.type.kind === 'time') {
|
|
998
1049
|
const formatMap = {
|
|
@@ -1009,8 +1060,8 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1009
1060
|
requiredHelpers.parseOptional = true;
|
|
1010
1061
|
from = `parseOptional(${paramValue}, func(v string) (time.Time, error) { return time.Parse(${format}, v) })`;
|
|
1011
1062
|
}
|
|
1012
|
-
content +=
|
|
1013
|
-
content +=
|
|
1063
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${from}\n`;
|
|
1064
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1014
1065
|
}
|
|
1015
1066
|
else {
|
|
1016
1067
|
imports.add('strconv');
|
|
@@ -1023,11 +1074,11 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1023
1074
|
requiredHelpers.parseWithCast = true;
|
|
1024
1075
|
parser = 'parseWithCast';
|
|
1025
1076
|
}
|
|
1026
|
-
content +=
|
|
1027
|
-
content +=
|
|
1028
|
-
content +=
|
|
1029
|
-
content +=
|
|
1030
|
-
content +=
|
|
1077
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${parser}(${paramValue}, func (v string) (time.Time, error) {\n`;
|
|
1078
|
+
content += `${indent.push().get()}p, parseErr := strconv.ParseInt(v, 10, 64)\n`;
|
|
1079
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return time.Time{}, parseErr\n${indent.pop().get()}}\n`;
|
|
1080
|
+
content += `${indent.get()}return time.Unix(p, 0).UTC(), nil\n${indent.pop().get()}})\n`;
|
|
1081
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1031
1082
|
}
|
|
1032
1083
|
}
|
|
1033
1084
|
else if (param.type.kind === 'scalar' && (param.type.type === 'float32' || param.type.type === 'float64' || param.type.type === 'int32' || param.type.type === 'int64')) {
|
|
@@ -1041,32 +1092,32 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1041
1092
|
parser = 'parseWithCast';
|
|
1042
1093
|
}
|
|
1043
1094
|
if (param.type.type === 'float32' || param.type.type === 'int32' || !go.isRequiredParameter(param.style)) {
|
|
1044
|
-
content +=
|
|
1045
|
-
content +=
|
|
1046
|
-
content +=
|
|
1095
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${parser}(${paramValue}, func(v string) (${param.type.type}, error) {\n`;
|
|
1096
|
+
content += `${indent.push().get()}p, parseErr := ${emitNumericConversion('v', param.type.type)}\n`;
|
|
1097
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return 0, parseErr\n${indent.pop().get()}}\n`;
|
|
1047
1098
|
let result = 'p';
|
|
1048
1099
|
if (param.type.type === 'float32' || param.type.type === 'int32') {
|
|
1049
1100
|
result = `${param.type.type}(${result})`;
|
|
1050
1101
|
}
|
|
1051
|
-
content +=
|
|
1102
|
+
content += `${indent.get()}return ${result}, nil\n${indent.pop().get()}})\n`;
|
|
1052
1103
|
}
|
|
1053
1104
|
else {
|
|
1054
|
-
content +=
|
|
1105
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${emitNumericConversion(paramValue, param.type.type)}\n`;
|
|
1055
1106
|
}
|
|
1056
|
-
content +=
|
|
1107
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1057
1108
|
}
|
|
1058
1109
|
else if (param.kind === 'headerMapParam') {
|
|
1059
1110
|
imports.add('strings');
|
|
1060
1111
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/to');
|
|
1061
1112
|
const localVar = createLocalVariableName(param, 'Param');
|
|
1062
|
-
content +=
|
|
1063
|
-
content +=
|
|
1113
|
+
content += `${indent.get()}var ${localVar} map[string]*string\n`;
|
|
1114
|
+
content += `${indent.get()}for hh := range ${paramValue} {\n`;
|
|
1064
1115
|
const headerPrefix = param.headerName;
|
|
1065
1116
|
requiredHelpers.getHeaderValue = true;
|
|
1066
|
-
content +=
|
|
1067
|
-
content +=
|
|
1068
|
-
content +=
|
|
1069
|
-
content +=
|
|
1117
|
+
content += `${indent.push().get()}if len(hh) > len("${headerPrefix}") && strings.EqualFold(hh[:len("x-ms-meta-")], "${headerPrefix}") {\n`;
|
|
1118
|
+
content += `${indent.push().get()}if ${localVar} == nil {\n${indent.push().get()}${localVar} = map[string]*string{}\n${indent.pop().get()}}\n`;
|
|
1119
|
+
content += `${indent.get()}${localVar}[hh[len("${headerPrefix}"):]] = to.Ptr(getHeaderValue(req.Header, hh))\n`;
|
|
1120
|
+
content += `${indent.pop().get()}}\n${indent.pop().get()}}\n`;
|
|
1070
1121
|
}
|
|
1071
1122
|
else if (param.type.kind === 'constant' && param.type.type !== 'string') {
|
|
1072
1123
|
let parseHelper;
|
|
@@ -1091,11 +1142,11 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1091
1142
|
zeroValue = '0';
|
|
1092
1143
|
}
|
|
1093
1144
|
const toConstType = go.getTypeDeclaration(param.type, pkg);
|
|
1094
|
-
content +=
|
|
1095
|
-
content +=
|
|
1096
|
-
content +=
|
|
1097
|
-
content +=
|
|
1098
|
-
content +=
|
|
1145
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')}, err := ${parseHelper}(${paramValue}, func(v string) (${toConstType}, error) {\n`;
|
|
1146
|
+
content += `${indent.push().get()}p, parseErr := ${parse}\n`;
|
|
1147
|
+
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return ${zeroValue}, parseErr\n${indent.pop().get()}}\n`;
|
|
1148
|
+
content += `${indent.get()}return ${toConstType}(p), nil\n${indent.pop().get()}})\n`;
|
|
1149
|
+
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1099
1150
|
}
|
|
1100
1151
|
else if (!go.isRequiredParameter(param.style)) {
|
|
1101
1152
|
// we check this last as it's a superset of the previous conditions
|
|
@@ -1104,23 +1155,25 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1104
1155
|
imports.addForType(param.type);
|
|
1105
1156
|
paramValue = `${go.getTypeDeclaration(param.type, pkg)}(${paramValue})`;
|
|
1106
1157
|
}
|
|
1107
|
-
content +=
|
|
1158
|
+
content += `${indent.get()}${createLocalVariableName(param, 'Param')} := getOptional(${paramValue})\n`;
|
|
1108
1159
|
}
|
|
1109
1160
|
}
|
|
1110
1161
|
// create the param groups and populate their values
|
|
1111
1162
|
for (const paramGroup of paramGroups.keys()) {
|
|
1112
1163
|
if (paramGroup.required) {
|
|
1113
|
-
content +=
|
|
1164
|
+
content += `${indent.get()}${naming.uncapitalize(paramGroup.name)} := ${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1114
1165
|
const params = paramGroups.get(paramGroup);
|
|
1115
1166
|
if (params) {
|
|
1167
|
+
indent.push();
|
|
1116
1168
|
for (const param of params) {
|
|
1117
|
-
content +=
|
|
1169
|
+
content += `${indent.get()}${naming.capitalize(param.name)}: ${getFinalParamValue(pkg, param, paramValues)},\n`;
|
|
1118
1170
|
}
|
|
1171
|
+
indent.pop();
|
|
1119
1172
|
}
|
|
1120
|
-
content +=
|
|
1173
|
+
content += `${indent.get()}}\n`;
|
|
1121
1174
|
}
|
|
1122
1175
|
else {
|
|
1123
|
-
content +=
|
|
1176
|
+
content += `${indent.get()}var ${naming.uncapitalize(paramGroup.name)} *${go.getTypeDeclaration(paramGroup, pkg)}\n`;
|
|
1124
1177
|
const params = paramGroups.get(paramGroup);
|
|
1125
1178
|
const paramNilCheck = new Array();
|
|
1126
1179
|
if (params) {
|
|
@@ -1148,19 +1201,21 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1148
1201
|
}
|
|
1149
1202
|
}
|
|
1150
1203
|
}
|
|
1151
|
-
content +=
|
|
1152
|
-
content +=
|
|
1204
|
+
content += `${indent.get()}if ${paramNilCheck.join(' || ')} {\n`;
|
|
1205
|
+
content += `${indent.push().get()}${naming.uncapitalize(paramGroup.name)} = &${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1153
1206
|
if (params) {
|
|
1207
|
+
indent.push();
|
|
1154
1208
|
for (const param of params) {
|
|
1155
1209
|
let byRef = '&';
|
|
1156
1210
|
if (param.byValue || (!go.isRequiredParameter(param.style) && param.kind !== 'bodyParam' && !go.isFormBodyParameter(param) && param.kind !== 'multipartFormBodyParam')) {
|
|
1157
1211
|
byRef = '';
|
|
1158
1212
|
}
|
|
1159
|
-
content +=
|
|
1213
|
+
content += `${indent.get()}${naming.capitalize(param.name)}: ${byRef}${getFinalParamValue(pkg, param, paramValues)},\n`;
|
|
1160
1214
|
}
|
|
1215
|
+
indent.pop();
|
|
1161
1216
|
}
|
|
1162
|
-
content +=
|
|
1163
|
-
content +=
|
|
1217
|
+
content += `${indent.get()}}\n`;
|
|
1218
|
+
content += `${indent.pop().get()}}\n`;
|
|
1164
1219
|
}
|
|
1165
1220
|
}
|
|
1166
1221
|
return {
|