@azure-tools/typespec-go 0.8.7 → 0.9.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.
Files changed (98) hide show
  1. package/dist/codegen.go/src/core/clientFactory.js +5 -5
  2. package/dist/codegen.go/src/core/clientFactory.js.map +1 -1
  3. package/dist/codegen.go/src/core/cloudConfig.js +1 -1
  4. package/dist/codegen.go/src/core/cloudConfig.js.map +1 -1
  5. package/dist/codegen.go/src/core/constants.js +1 -1
  6. package/dist/codegen.go/src/core/constants.js.map +1 -1
  7. package/dist/codegen.go/src/core/example.d.ts +1 -1
  8. package/dist/codegen.go/src/core/example.d.ts.map +1 -1
  9. package/dist/codegen.go/src/core/example.js +34 -36
  10. package/dist/codegen.go/src/core/example.js.map +1 -1
  11. package/dist/codegen.go/src/core/helpers.d.ts +4 -13
  12. package/dist/codegen.go/src/core/helpers.d.ts.map +1 -1
  13. package/dist/codegen.go/src/core/helpers.js +16 -37
  14. package/dist/codegen.go/src/core/helpers.js.map +1 -1
  15. package/dist/codegen.go/src/core/imports.d.ts +39 -3
  16. package/dist/codegen.go/src/core/imports.d.ts.map +1 -1
  17. package/dist/codegen.go/src/core/imports.js +69 -18
  18. package/dist/codegen.go/src/core/imports.js.map +1 -1
  19. package/dist/codegen.go/src/core/interfaces.d.ts.map +1 -1
  20. package/dist/codegen.go/src/core/interfaces.js +1 -2
  21. package/dist/codegen.go/src/core/interfaces.js.map +1 -1
  22. package/dist/codegen.go/src/core/models.d.ts +0 -1
  23. package/dist/codegen.go/src/core/models.d.ts.map +1 -1
  24. package/dist/codegen.go/src/core/models.js +163 -84
  25. package/dist/codegen.go/src/core/models.js.map +1 -1
  26. package/dist/codegen.go/src/core/operations.d.ts.map +1 -1
  27. package/dist/codegen.go/src/core/operations.js +63 -31
  28. package/dist/codegen.go/src/core/operations.js.map +1 -1
  29. package/dist/codegen.go/src/core/options.js +14 -6
  30. package/dist/codegen.go/src/core/options.js.map +1 -1
  31. package/dist/codegen.go/src/core/polymorphics.d.ts +1 -2
  32. package/dist/codegen.go/src/core/polymorphics.d.ts.map +1 -1
  33. package/dist/codegen.go/src/core/polymorphics.js +13 -12
  34. package/dist/codegen.go/src/core/polymorphics.js.map +1 -1
  35. package/dist/codegen.go/src/core/responses.js +35 -12
  36. package/dist/codegen.go/src/core/responses.js.map +1 -1
  37. package/dist/codegen.go/src/core/time.d.ts +1 -2
  38. package/dist/codegen.go/src/core/time.d.ts.map +1 -1
  39. package/dist/codegen.go/src/core/time.js +51 -18
  40. package/dist/codegen.go/src/core/time.js.map +1 -1
  41. package/dist/codegen.go/src/core/version.js +1 -1
  42. package/dist/codegen.go/src/core/version.js.map +1 -1
  43. package/dist/codegen.go/src/core/xmlAdditionalProps.js +2 -2
  44. package/dist/codegen.go/src/core/xmlAdditionalProps.js.map +1 -1
  45. package/dist/codegen.go/src/emitter.js +12 -11
  46. package/dist/codegen.go/src/emitter.js.map +1 -1
  47. package/dist/codegen.go/src/fake/factory.d.ts +1 -1
  48. package/dist/codegen.go/src/fake/factory.d.ts.map +1 -1
  49. package/dist/codegen.go/src/fake/factory.js +9 -8
  50. package/dist/codegen.go/src/fake/factory.js.map +1 -1
  51. package/dist/codegen.go/src/fake/internal.d.ts +1 -1
  52. package/dist/codegen.go/src/fake/internal.d.ts.map +1 -1
  53. package/dist/codegen.go/src/fake/internal.js +3 -3
  54. package/dist/codegen.go/src/fake/internal.js.map +1 -1
  55. package/dist/codegen.go/src/fake/servers.d.ts +1 -1
  56. package/dist/codegen.go/src/fake/servers.d.ts.map +1 -1
  57. package/dist/codegen.go/src/fake/servers.js +131 -81
  58. package/dist/codegen.go/src/fake/servers.js.map +1 -1
  59. package/dist/codemodel.go/src/client.d.ts +19 -10
  60. package/dist/codemodel.go/src/client.d.ts.map +1 -1
  61. package/dist/codemodel.go/src/client.js +14 -9
  62. package/dist/codemodel.go/src/client.js.map +1 -1
  63. package/dist/codemodel.go/src/module.d.ts +29 -0
  64. package/dist/codemodel.go/src/module.d.ts.map +1 -1
  65. package/dist/codemodel.go/src/module.js +36 -0
  66. package/dist/codemodel.go/src/module.js.map +1 -1
  67. package/dist/codemodel.go/src/param.d.ts +4 -1
  68. package/dist/codemodel.go/src/param.d.ts.map +1 -1
  69. package/dist/codemodel.go/src/param.js +2 -1
  70. package/dist/codemodel.go/src/param.js.map +1 -1
  71. package/dist/codemodel.go/src/result.d.ts +1 -0
  72. package/dist/codemodel.go/src/result.d.ts.map +1 -1
  73. package/dist/codemodel.go/src/result.js +1 -0
  74. package/dist/codemodel.go/src/result.js.map +1 -1
  75. package/dist/codemodel.go/src/type.d.ts +23 -13
  76. package/dist/codemodel.go/src/type.d.ts.map +1 -1
  77. package/dist/codemodel.go/src/type.js +50 -28
  78. package/dist/codemodel.go/src/type.js.map +1 -1
  79. package/dist/typespec-go/src/emitter.d.ts.map +1 -1
  80. package/dist/typespec-go/src/emitter.js +9 -2
  81. package/dist/typespec-go/src/emitter.js.map +1 -1
  82. package/dist/typespec-go/src/tcgcadapter/adapter.d.ts +23 -2
  83. package/dist/typespec-go/src/tcgcadapter/adapter.d.ts.map +1 -1
  84. package/dist/typespec-go/src/tcgcadapter/adapter.js +96 -67
  85. package/dist/typespec-go/src/tcgcadapter/adapter.js.map +1 -1
  86. package/dist/typespec-go/src/tcgcadapter/clients.d.ts +20 -16
  87. package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -1
  88. package/dist/typespec-go/src/tcgcadapter/clients.js +187 -119
  89. package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -1
  90. package/dist/typespec-go/src/tcgcadapter/errors.d.ts +1 -1
  91. package/dist/typespec-go/src/tcgcadapter/errors.d.ts.map +1 -1
  92. package/dist/typespec-go/src/tcgcadapter/errors.js +2 -1
  93. package/dist/typespec-go/src/tcgcadapter/errors.js.map +1 -1
  94. package/dist/typespec-go/src/tcgcadapter/types.d.ts +14 -7
  95. package/dist/typespec-go/src/tcgcadapter/types.d.ts.map +1 -1
  96. package/dist/typespec-go/src/tcgcadapter/types.js +38 -33
  97. package/dist/typespec-go/src/tcgcadapter/types.js.map +1 -1
  98. package/package.json +8 -8
@@ -42,14 +42,13 @@ export function getServerName(client) {
42
42
  */
43
43
  export function generateServers(pkg) {
44
44
  const operations = new Array();
45
- const clientPkg = helpers.getPackageName(pkg);
46
- for (const client of values(pkg.clients)) {
45
+ for (const client of values(pkg.parent.clients)) {
47
46
  if (client.clientAccessors.length === 0 && values(client.methods).all(method => { return helpers.isMethodInternal(method); })) {
48
47
  // client has no client accessors and no exported methods, skip it
49
48
  continue;
50
49
  }
51
50
  // the list of packages to import
52
- const imports = new ImportManager();
51
+ const imports = new ImportManager(pkg);
53
52
  // add standard imports
54
53
  imports.add('errors');
55
54
  imports.add('fmt');
@@ -57,7 +56,7 @@ export function generateServers(pkg) {
57
56
  imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime');
58
57
  const serverName = getServerName(client);
59
58
  let content;
60
- content = `// ${serverName} is a fake server for instances of the ${clientPkg}.${client.name} type.\n`;
59
+ content = `// ${serverName} is a fake server for instances of the ${go.getTypeDeclaration(client, pkg)} type.\n`;
61
60
  content += `type ${serverName} struct{\n`;
62
61
  // we might remove some operations from the list
63
62
  const finalMethods = new Array();
@@ -67,14 +66,14 @@ export function generateServers(pkg) {
67
66
  // we might remove some clients from the list
68
67
  const finalSubClients = new Array();
69
68
  for (const clientAccessor of client.clientAccessors) {
70
- if (values(clientAccessor.subClient.methods).all(method => { return helpers.isMethodInternal(method); })) {
69
+ if (values(clientAccessor.returns.methods).all(method => { return helpers.isMethodInternal(method); })) {
71
70
  // client has no exported methods, skip it
72
71
  continue;
73
72
  }
74
- const serverName = getServerName(clientAccessor.subClient);
75
- content += `\t// ${serverName} contains the fakes for client ${clientAccessor.subClient.name}\n`;
73
+ const serverName = getServerName(clientAccessor.returns);
74
+ content += `\t// ${serverName} contains the fakes for client ${clientAccessor.returns.name}\n`;
76
75
  content += `\t${serverName} ${serverName}\n\n`;
77
- finalSubClients.push(clientAccessor.subClient);
76
+ finalSubClients.push(clientAccessor.returns);
78
77
  }
79
78
  for (const method of values(client.methods)) {
80
79
  if (helpers.isMethodInternal(method)) {
@@ -85,17 +84,17 @@ export function generateServers(pkg) {
85
84
  switch (method.kind) {
86
85
  case 'lroMethod':
87
86
  case 'lroPageableMethod':
88
- let respType = `${clientPkg}.${method.returns.name}`;
87
+ let respType = go.getTypeDeclaration(method.returns, pkg);
89
88
  if (method.kind === 'lroPageableMethod') {
90
- respType = `azfake.PagerResponder[${clientPkg}.${method.returns.name}]`;
89
+ respType = `azfake.PagerResponder[${respType}]`;
91
90
  }
92
91
  serverResponse = `resp azfake.PollerResponder[${respType}], errResp azfake.ErrorResponder`;
93
92
  break;
94
93
  case 'method':
95
- serverResponse = `resp azfake.Responder[${clientPkg}.${method.returns.name}], errResp azfake.ErrorResponder`;
94
+ serverResponse = `resp azfake.Responder[${go.getTypeDeclaration(method.returns, pkg)}], errResp azfake.ErrorResponder`;
96
95
  break;
97
96
  case 'pageableMethod':
98
- serverResponse = `resp azfake.PagerResponder[${clientPkg}.${method.returns.name}]`;
97
+ serverResponse = `resp azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
99
98
  break;
100
99
  }
101
100
  const operationName = fixUpMethodName(method);
@@ -109,7 +108,7 @@ export function generateServers(pkg) {
109
108
  successCodes.push(`${helpers.formatStatusCode(httpStatus)} (no return type)`);
110
109
  continue;
111
110
  }
112
- successCodes.push(`${helpers.formatStatusCode(httpStatus)} (returns ${go.getTypeDeclaration(result, clientPkg)})`);
111
+ successCodes.push(`${helpers.formatStatusCode(httpStatus)} (returns ${go.getTypeDeclaration(result, pkg)})`);
113
112
  }
114
113
  content += '\t// HTTP status codes to indicate success:\n';
115
114
  for (const successCode of successCodes) {
@@ -122,7 +121,7 @@ export function generateServers(pkg) {
122
121
  }
123
122
  content += `\t// HTTP status codes to indicate success: ${successCodes.join(', ')}\n`;
124
123
  }
125
- content += `\t${operationName} func(${getAPIParametersSig(method, imports, clientPkg)}) (${serverResponse})\n\n`;
124
+ content += `\t${operationName} func(${getAPIParametersSig(pkg, method, imports)}) (${serverResponse})\n\n`;
126
125
  finalMethods.push(method);
127
126
  switch (method.kind) {
128
127
  case 'lroMethod':
@@ -138,7 +137,7 @@ export function generateServers(pkg) {
138
137
  ///////////////////////////////////////////////////////////////////////////
139
138
  const serverTransport = `${serverName}Transport`;
140
139
  content += `// New${serverTransport} creates a new instance of ${serverTransport} with the provided implementation.\n`;
141
- content += `// The returned ${serverTransport} instance is connected to an instance of ${clientPkg}.${client.name} via the\n`;
140
+ content += `// The returned ${serverTransport} instance is connected to an instance of ${go.getTypeDeclaration(client, pkg)} via the\n`;
142
141
  content += '// azcore.ClientOptions.Transporter field in the client\'s constructor parameters.\n';
143
142
  content += `func New${serverTransport}(srv *${serverName}) *${serverTransport} {\n`;
144
143
  if (countLROs === 0 && countPagers === 0) {
@@ -147,12 +146,12 @@ export function generateServers(pkg) {
147
146
  else {
148
147
  content += `\treturn &${serverTransport}{\n\t\tsrv: srv,\n`;
149
148
  for (const method of values(finalMethods)) {
150
- let respType = `${clientPkg}.${method.returns.name}`;
149
+ let respType = go.getTypeDeclaration(method.returns, pkg);
151
150
  switch (method.kind) {
152
151
  case 'lroMethod':
153
152
  case 'lroPageableMethod':
154
153
  if (method.kind === 'lroPageableMethod') {
155
- respType = `azfake.PagerResponder[${clientPkg}.${method.returns.name}]`;
154
+ respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
156
155
  }
157
156
  requiredHelpers.tracker = true;
158
157
  content += `\t\t${uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PollerResponder[${respType}]](),\n`;
@@ -165,7 +164,7 @@ export function generateServers(pkg) {
165
164
  }
166
165
  content += '\t}\n}\n\n';
167
166
  }
168
- content += `// ${serverTransport} connects instances of ${clientPkg}.${client.name} to instances of ${serverName}.\n`;
167
+ content += `// ${serverTransport} connects instances of ${go.getTypeDeclaration(client, pkg)} to instances of ${serverName}.\n`;
169
168
  content += `// Don't use this type directly, use New${serverTransport} instead.\n`;
170
169
  content += `type ${serverTransport} struct {\n`;
171
170
  content += `\tsrv *${serverName}\n`;
@@ -181,19 +180,19 @@ export function generateServers(pkg) {
181
180
  }
182
181
  for (const method of values(finalMethods)) {
183
182
  // create state machines for any pager/poller operations
184
- let respType = `${clientPkg}.${method.returns.name}`;
183
+ let respType = go.getTypeDeclaration(method.returns, pkg);
185
184
  switch (method.kind) {
186
185
  case 'lroMethod':
187
186
  case 'lroPageableMethod':
188
187
  if (method.kind === 'lroPageableMethod') {
189
- respType = `azfake.PagerResponder[${clientPkg}.${method.returns.name}]`;
188
+ respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
190
189
  }
191
190
  requiredHelpers.tracker = true;
192
191
  content += `\t${uncapitalize(fixUpMethodName(method))} *tracker[azfake.PollerResponder[${respType}]]\n`;
193
192
  break;
194
193
  case 'pageableMethod':
195
194
  requiredHelpers.tracker = true;
196
- content += `\t${uncapitalize(fixUpMethodName(method))} *tracker[azfake.PagerResponder[${clientPkg}.${method.returns.name}]]\n`;
195
+ content += `\t${uncapitalize(fixUpMethodName(method))} *tracker[azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]]\n`;
197
196
  break;
198
197
  }
199
198
  }
@@ -208,7 +207,7 @@ export function generateServers(pkg) {
208
207
  content += '\tDo(*http.Request) (*http.Response, error, bool)\n}\n';
209
208
  ///////////////////////////////////////////////////////////////////////////
210
209
  // stitch everything together
211
- let text = helpers.contentPreamble('fake');
210
+ let text = helpers.contentPreamble(pkg);
212
211
  text += imports.text();
213
212
  text += content;
214
213
  operations.push(new OperationGroupContent(serverName, text));
@@ -300,14 +299,22 @@ function generateServerTransportMethodDispatch(serverTransport, client, finalMet
300
299
  content += '\t}\n}\n\n';
301
300
  return content;
302
301
  }
302
+ /**
303
+ * generates the server transport methods for a fake server transport
304
+ *
305
+ * @param pkg contains the package content
306
+ * @param serverTransport the name of the server transport type
307
+ * @param finalMethods the array of methods for which to generate the fake transports
308
+ * @param imports the import manager currently in scope
309
+ * @returns the text for the server transport methods
310
+ */
303
311
  function generateServerTransportMethods(pkg, serverTransport, finalMethods, imports) {
304
312
  if (finalMethods.length === 0) {
305
313
  return '';
306
314
  }
307
- imports.addForPkg(pkg);
315
+ imports.addForPkg(pkg.parent);
308
316
  imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
309
317
  imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server');
310
- const clientPkg = helpers.getPackageName(pkg);
311
318
  const receiverName = serverTransport[0].toLowerCase();
312
319
  let content = '';
313
320
  for (const method of values(finalMethods)) {
@@ -318,10 +325,10 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
318
325
  case 'lroMethod':
319
326
  case 'lroPageableMethod':
320
327
  // must check LRO before pager as you can have paged LROs
321
- content += dispatchForLROBody(clientPkg, receiverName, method, imports);
328
+ content += dispatchForLROBody(pkg, receiverName, method, imports);
322
329
  break;
323
330
  case 'method': {
324
- content += dispatchForOperationBody(clientPkg, receiverName, method, imports);
331
+ content += dispatchForOperationBody(pkg, receiverName, method, imports);
325
332
  content += '\trespContent := server.GetResponseContent(respr)\n';
326
333
  const formattedStatusCodes = helpers.formatStatusCodes(method.httpStatusCodes);
327
334
  content += `\tif !contains([]int{${formattedStatusCodes}}, respContent.HTTPStatus) {\n`;
@@ -387,7 +394,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
387
394
  break;
388
395
  }
389
396
  case 'pageableMethod':
390
- content += dispatchForPagerBody(clientPkg, receiverName, method, imports);
397
+ content += dispatchForPagerBody(pkg, receiverName, method, imports);
391
398
  break;
392
399
  default:
393
400
  method;
@@ -396,7 +403,17 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
396
403
  }
397
404
  return content;
398
405
  }
399
- function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
406
+ /**
407
+ * generates the core dispatching logic for a server dispatch method.
408
+ * this code is common to all method types.
409
+ *
410
+ * @param pkg contains the package content
411
+ * @param receiverName the name of the receiver for the dispatch method
412
+ * @param method the method for which to emit dispatching logic
413
+ * @param imports the import manager currently in scope
414
+ * @returns the text for dispatching logic
415
+ */
416
+ function dispatchForOperationBody(pkg, receiverName, method, imports) {
400
417
  const methodParamGroups = helpers.getMethodParamGroups(method);
401
418
  const numPathParams = values(methodParamGroups.pathParams).where((each) => { return !go.isLiteralParameter(each.style); }).count();
402
419
  let content = '';
@@ -444,7 +461,7 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
444
461
  content += '\treq.Body.Close()\n';
445
462
  break;
446
463
  default: {
447
- let bodyTypeName = go.getTypeDeclaration(bodyParam.type, clientPkg);
464
+ let bodyTypeName = go.getTypeDeclaration(bodyParam.type, pkg);
448
465
  if (bodyParam.type.kind === 'time') {
449
466
  bodyTypeName = bodyParam.type.format;
450
467
  }
@@ -472,15 +489,7 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
472
489
  content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
473
490
  content += '\treader := multipart.NewReader(req.Body, params["boundary"])\n';
474
491
  for (const param of multipartBodyParams) {
475
- let pkgPrefix = '';
476
- switch (param.type.kind) {
477
- case 'constant':
478
- case 'model':
479
- case 'polymorphicModel':
480
- pkgPrefix = clientPkg + '.';
481
- break;
482
- }
483
- content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
492
+ content += `\tvar ${param.name} ${go.getTypeDeclaration(param.type, pkg)}\n`;
484
493
  }
485
494
  content += '\tfor {\n';
486
495
  content += '\t\tvar part *multipart.Part\n';
@@ -556,7 +565,7 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
556
565
  from = 'content';
557
566
  break;
558
567
  }
559
- assignedValue = `${clientPkg}.${type.name}(${from})`;
568
+ assignedValue = `${go.getTypeDeclaration(type, pkg)}(${from})`;
560
569
  }
561
570
  else if (type.kind === 'scalar') {
562
571
  switch (type.type) {
@@ -634,11 +643,7 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
634
643
  }
635
644
  else if (formBodyParams.length > 0) {
636
645
  for (const param of formBodyParams) {
637
- let pkgPrefix = '';
638
- if (param.type.kind === 'constant') {
639
- pkgPrefix = clientPkg + '.';
640
- }
641
- content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
646
+ content += `\tvar ${param.name} ${go.getTypeDeclaration(param.type, pkg)}\n`;
642
647
  }
643
648
  content += '\tif err := req.ParseForm(); err != nil {\n\t\treturn nil, &nonRetriableError{fmt.Errorf("failed parsing form data: %v", err)}\n\t}\n';
644
649
  content += '\tfor key := range req.Form {\n';
@@ -648,7 +653,7 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
648
653
  let assignedValue;
649
654
  switch (param.type.kind) {
650
655
  case 'constant':
651
- assignedValue = `${go.getTypeDeclaration(param.type, clientPkg)}(req.FormValue(key))`;
656
+ assignedValue = `${go.getTypeDeclaration(param.type, pkg)}(req.FormValue(key))`;
652
657
  break;
653
658
  case 'string':
654
659
  assignedValue = 'req.FormValue(key)';
@@ -665,19 +670,19 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
665
670
  // construct the partial body params type and unmarshal it
666
671
  content += '\ttype partialBodyParams struct {\n';
667
672
  for (const partialBodyParam of partialBodyParams) {
668
- content += `\t\t${capitalize(partialBodyParam.name)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, clientPkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
673
+ content += `\t\t${capitalize(partialBodyParam.name)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
669
674
  }
670
675
  content += '\t}\n';
671
676
  content += `\tbody, err := server.UnmarshalRequestAs${partialBodyParams[0].format}[partialBodyParams](req)\n`;
672
677
  content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
673
678
  }
674
- const result = parseHeaderPathQueryParams(clientPkg, method, imports);
679
+ const result = parseHeaderPathQueryParams(pkg, method, imports);
675
680
  content += result.content;
676
681
  // translate each partial body param to its field within the unmarshalled body
677
682
  for (const partialBodyParam of partialBodyParams) {
678
683
  result.params.set(partialBodyParam.name, `${helpers.star(partialBodyParam.byValue)}body.${capitalize(partialBodyParam.name)}`);
679
684
  }
680
- const apiCall = `:= ${receiverName}.srv.${fixUpMethodName(method)}(${populateApiParams(clientPkg, method, result.params, imports)})`;
685
+ const apiCall = `:= ${receiverName}.srv.${fixUpMethodName(method)}(${populateApiParams(pkg, method, result.params, imports)})`;
681
686
  if (method.kind === 'pageableMethod') {
682
687
  content += `resp ${apiCall}\n`;
683
688
  return content;
@@ -705,13 +710,22 @@ function getMethodStatusCodes(method) {
705
710
  }
706
711
  return statusCodes;
707
712
  }
708
- function dispatchForLROBody(clientPkg, receiverName, method, imports) {
713
+ /**
714
+ * generates the dispatching logic for an LRO server dispatch method
715
+ *
716
+ * @param pkg contains the package contents
717
+ * @param receiverName the name of the receiver for the dispatch method
718
+ * @param method the LRO method for which to emit the dispatch logic
719
+ * @param imports the import manager currently in scope
720
+ * @returns the text for the LRO dispatch logic
721
+ */
722
+ function dispatchForLROBody(pkg, receiverName, method, imports) {
709
723
  const operationName = fixUpMethodName(method);
710
724
  const localVarName = uncapitalize(operationName);
711
725
  const operationStateMachine = `${receiverName}.${uncapitalize(operationName)}`;
712
726
  let content = `\t${localVarName} := ${operationStateMachine}.get(req)\n`;
713
727
  content += `\tif ${localVarName} == nil {\n`;
714
- content += dispatchForOperationBody(clientPkg, receiverName, method, imports);
728
+ content += dispatchForOperationBody(pkg, receiverName, method, imports);
715
729
  content += `\t\t${localVarName} = &respr\n`;
716
730
  content += `\t\t${operationStateMachine}.add(req, ${localVarName})\n`;
717
731
  content += '\t}\n\n';
@@ -726,18 +740,27 @@ function dispatchForLROBody(clientPkg, receiverName, method, imports) {
726
740
  content += '\treturn resp, nil\n';
727
741
  return content;
728
742
  }
729
- function dispatchForPagerBody(clientPkg, receiverName, method, imports) {
743
+ /**
744
+ * generates the dispatching logic for a paged server dispatch method
745
+ *
746
+ * @param pkg contains the package contents
747
+ * @param receiverName the name of the receiver for the dispatch method
748
+ * @param method the pageable method for which to emit the dispatch logic
749
+ * @param imports the import manager currently in scope
750
+ * @returns the text for the pageable dispatch logic
751
+ */
752
+ function dispatchForPagerBody(pkg, receiverName, method, imports) {
730
753
  const operationName = fixUpMethodName(method);
731
754
  const localVarName = uncapitalize(operationName);
732
755
  const operationStateMachine = `${receiverName}.${uncapitalize(operationName)}`;
733
756
  let content = `\t${localVarName} := ${operationStateMachine}.get(req)\n`;
734
757
  content += `\tif ${localVarName} == nil {\n`;
735
- content += dispatchForOperationBody(clientPkg, receiverName, method, imports);
758
+ content += dispatchForOperationBody(pkg, receiverName, method, imports);
736
759
  content += `\t\t${localVarName} = &resp\n`;
737
760
  content += `\t\t${operationStateMachine}.add(req, ${localVarName})\n`;
738
761
  if (method.nextLinkName) {
739
762
  imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/to');
740
- content += `\t\tserver.PagerResponderInjectNextLinks(${localVarName}, req, func(page *${clientPkg}.${method.returns.name}, createLink func() string) {\n`;
763
+ content += `\t\tserver.PagerResponderInjectNextLinks(${localVarName}, req, func(page *${go.getTypeDeclaration(method.returns, pkg)}, createLink func() string) {\n`;
741
764
  content += `\t\t\tpage.${method.nextLinkName} = to.Ptr(createLink())\n`;
742
765
  content += '\t\t})\n';
743
766
  }
@@ -776,9 +799,15 @@ function createPathParamsRegex(method, pathParams) {
776
799
  }
777
800
  return urlPath;
778
801
  }
779
- // parses header/path/query params as required.
780
- // returns the parsing code and the params that contain the parsed values.
781
- function parseHeaderPathQueryParams(clientPkg, method, imports) {
802
+ /**
803
+ * parses header/path/query params as required
804
+ *
805
+ * @param pkg contains the package contents
806
+ * @param method the method for which to emit parameter parsing logic
807
+ * @param imports the import manager currently in scope
808
+ * @returns the parsing code and the params that contain the parsed values
809
+ */
810
+ function parseHeaderPathQueryParams(pkg, method, imports) {
782
811
  let content = '';
783
812
  const paramValues = new Map();
784
813
  const createLocalVariableName = function (param, suffix) {
@@ -871,10 +900,10 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
871
900
  // for string-based enums, we perform the conversion as part of unescaping
872
901
  requiredHelpers.parseWithCast = true;
873
902
  paramVar = createLocalVariableName(param, 'Param');
874
- content += `\t${paramVar}, err := parseWithCast(${paramValue}, func (v string) (${go.getTypeDeclaration(param.type, clientPkg)}, error) {\n`;
903
+ content += `\t${paramVar}, err := parseWithCast(${paramValue}, func (v string) (${go.getTypeDeclaration(param.type, pkg)}, error) {\n`;
875
904
  content += `\t\tp, unescapeErr := url.${where}Unescape(v)\n`;
876
905
  content += '\t\tif unescapeErr != nil {\n\t\t\treturn "", unescapeErr\n\t\t}\n';
877
- content += `\t\treturn ${go.getTypeDeclaration(param.type, clientPkg)}(p), nil\n\t})\n`;
906
+ content += `\t\treturn ${go.getTypeDeclaration(param.type, pkg)}(p), nil\n\t})\n`;
878
907
  }
879
908
  else {
880
909
  if (go.isRequiredParameter(param.style) &&
@@ -915,10 +944,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
915
944
  default:
916
945
  throw new CodegenError('InternalError', `unhandled element kind ${param.type.elementType.kind}`);
917
946
  }
918
- let toType = go.getTypeDeclaration(param.type.elementType);
919
- if (param.type.elementType.kind === 'constant') {
920
- toType = `${clientPkg}.${toType}`;
921
- }
947
+ const toType = go.getTypeDeclaration(param.type.elementType, pkg);
922
948
  content += `\t${paramVar} := make([]${toType}, len(${paramValue}))\n`;
923
949
  content += `\tfor i := 0; i < len(${paramValue}); i++ {\n`;
924
950
  let fromVar;
@@ -1099,7 +1125,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1099
1125
  parse = emitNumericConversion('v', param.type.type);
1100
1126
  zeroValue = '0';
1101
1127
  }
1102
- const toConstType = go.getTypeDeclaration(param.type, clientPkg);
1128
+ const toConstType = go.getTypeDeclaration(param.type, pkg);
1103
1129
  content += `\t${createLocalVariableName(param, 'Param')}, err := ${parseHelper}(${paramValue}, func(v string) (${toConstType}, error) {\n`;
1104
1130
  content += `\t\tp, parseErr := ${parse}\n`;
1105
1131
  content += `\t\tif parseErr != nil {\n\t\t\treturn ${zeroValue}, parseErr\n\t\t}\n`;
@@ -1110,7 +1136,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1110
1136
  // we check this last as it's a superset of the previous conditions
1111
1137
  requiredHelpers.getOptional = true;
1112
1138
  if (param.type.kind === 'constant') {
1113
- paramValue = `${go.getTypeDeclaration(param.type, clientPkg)}(${paramValue})`;
1139
+ paramValue = `${go.getTypeDeclaration(param.type, pkg)}(${paramValue})`;
1114
1140
  }
1115
1141
  content += `\t${createLocalVariableName(param, 'Param')} := getOptional(${paramValue})\n`;
1116
1142
  }
@@ -1118,20 +1144,20 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1118
1144
  // create the param groups and populate their values
1119
1145
  for (const paramGroup of values(paramGroups.keys())) {
1120
1146
  if (paramGroup.required) {
1121
- content += `\t${uncapitalize(paramGroup.name)} := ${clientPkg}.${paramGroup.groupName}{\n`;
1147
+ content += `\t${uncapitalize(paramGroup.name)} := ${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
1122
1148
  for (const param of values(paramGroups.get(paramGroup))) {
1123
- content += `\t\t${capitalize(param.name)}: ${getFinalParamValue(clientPkg, param, paramValues)},\n`;
1149
+ content += `\t\t${capitalize(param.name)}: ${getFinalParamValue(pkg, param, paramValues)},\n`;
1124
1150
  }
1125
1151
  content += '\t}\n';
1126
1152
  }
1127
1153
  else {
1128
- content += `\tvar ${uncapitalize(paramGroup.name)} *${clientPkg}.${paramGroup.groupName}\n`;
1154
+ content += `\tvar ${uncapitalize(paramGroup.name)} *${go.getTypeDeclaration(paramGroup, pkg)}\n`;
1129
1155
  const params = paramGroups.get(paramGroup);
1130
1156
  const paramNilCheck = new Array();
1131
1157
  for (const param of values(params)) {
1132
1158
  // check array before body in case the body is just an array
1133
1159
  if (param.type.kind === 'slice') {
1134
- paramNilCheck.push(`len(${getFinalParamValue(clientPkg, param, paramValues)}) > 0`);
1160
+ paramNilCheck.push(`len(${getFinalParamValue(pkg, param, paramValues)}) > 0`);
1135
1161
  }
1136
1162
  else if (param.kind === 'bodyParam') {
1137
1163
  if (param.bodyFormat === 'binary') {
@@ -1148,17 +1174,17 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1148
1174
  paramNilCheck.push(`!reflect.ValueOf(${param.name}).IsZero()`);
1149
1175
  }
1150
1176
  else {
1151
- paramNilCheck.push(`${getFinalParamValue(clientPkg, param, paramValues)} != nil`);
1177
+ paramNilCheck.push(`${getFinalParamValue(pkg, param, paramValues)} != nil`);
1152
1178
  }
1153
1179
  }
1154
1180
  content += `\tif ${paramNilCheck.join(' || ')} {\n`;
1155
- content += `\t\t${uncapitalize(paramGroup.name)} = &${clientPkg}.${paramGroup.groupName}{\n`;
1181
+ content += `\t\t${uncapitalize(paramGroup.name)} = &${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
1156
1182
  for (const param of values(params)) {
1157
1183
  let byRef = '&';
1158
1184
  if (param.byValue || (!go.isRequiredParameter(param.style) && param.kind !== 'bodyParam' && !go.isFormBodyParameter(param) && param.kind !== 'multipartFormBodyParam')) {
1159
1185
  byRef = '';
1160
1186
  }
1161
- content += `\t\t\t${capitalize(param.name)}: ${byRef}${getFinalParamValue(clientPkg, param, paramValues)},\n`;
1187
+ content += `\t\t\t${capitalize(param.name)}: ${byRef}${getFinalParamValue(pkg, param, paramValues)},\n`;
1162
1188
  }
1163
1189
  content += '\t\t}\n';
1164
1190
  content += '\t}\n';
@@ -1169,8 +1195,16 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1169
1195
  params: paramValues
1170
1196
  };
1171
1197
  }
1172
- // works in conjunction with parseHeaderPathQueryParams
1173
- function populateApiParams(clientPkg, method, paramValues, imports) {
1198
+ /**
1199
+ * generates the code to populate the method parameters that get passed to the fake
1200
+ *
1201
+ * @param pkg contains the package contents
1202
+ * @param method the method to be called with the parsed parameters
1203
+ * @param paramValues maps a parameter name to the value to be passed to the fake
1204
+ * @param imports the import manager currently in scope
1205
+ * @returns the text for the parameters to be passed to the fake
1206
+ */
1207
+ function populateApiParams(pkg, method, paramValues, imports) {
1174
1208
  // FooOperation(req.Context(), matches[regex.SubexpIndex("resourceGroupName")], qp.Get("api-version"), nil)
1175
1209
  // this assumes that our caller has created matches and qp as required
1176
1210
  const params = new Array();
@@ -1196,8 +1230,8 @@ function populateApiParams(clientPkg, method, paramValues, imports) {
1196
1230
  params.push(uncapitalize(param.name));
1197
1231
  continue;
1198
1232
  }
1199
- imports.addImportForType(param.type);
1200
- params.push(getFinalParamValue(clientPkg, param, paramValues));
1233
+ imports.addForType(param.type);
1234
+ params.push(getFinalParamValue(pkg, param, paramValues));
1201
1235
  }
1202
1236
  return params.join(', ');
1203
1237
  }
@@ -1242,8 +1276,17 @@ function getRawParamValue(param) {
1242
1276
  throw new CodegenError('InternalError', `unhandled parameter ${param.name}`);
1243
1277
  }
1244
1278
  }
1245
- // getFinalParamValue returns the "final" value of param to be passed to the fake.
1246
- function getFinalParamValue(clientPkg, param, paramValues) {
1279
+ /**
1280
+ * returns the final value of param to be passed to the fake.
1281
+ * this is usually the value in paramValues but can be slightly
1282
+ * different for some cases.
1283
+ *
1284
+ * @param pkg the contents of the package
1285
+ * @param param the parameter being evaluated
1286
+ * @param paramValues maps a parameter name to the value to be passed to the fake
1287
+ * @returns the value to pass for the provided parameter
1288
+ */
1289
+ function getFinalParamValue(pkg, param, paramValues) {
1247
1290
  let paramValue = paramValues.get(param.name);
1248
1291
  if (!paramValue) {
1249
1292
  // the param didn't require parsing so the "raw" value can be used
@@ -1266,7 +1309,7 @@ function getFinalParamValue(clientPkg, param, paramValues) {
1266
1309
  }
1267
1310
  else if (go.isHeaderParameter(param) && param.type.kind === 'constant' && param.type.type === 'string') {
1268
1311
  // since headers aren't escaped, we cast required, string-based enums inline
1269
- return `${go.getTypeDeclaration(param.type, clientPkg)}(${paramValue})`;
1312
+ return `${go.getTypeDeclaration(param.type, pkg)}(${paramValue})`;
1270
1313
  }
1271
1314
  }
1272
1315
  else if (param.kind === 'partialBodyParam') {
@@ -1299,8 +1342,15 @@ function consolidateHostParams(params) {
1299
1342
  }
1300
1343
  return consolidatedParams;
1301
1344
  }
1302
- // copied from generator/operations.ts but with a slight tweak to consolidate host parameters
1303
- function getAPIParametersSig(method, imports, pkgName) {
1345
+ /**
1346
+ * copied from generator/operations.ts but with a slight tweak to consolidate host parameters
1347
+ *
1348
+ * @param pkg the contents of the package
1349
+ * @param method the method for which to generate the parameter signature
1350
+ * @param imports the import manager currently in scope
1351
+ * @returns the text for the method's parameter signature
1352
+ */
1353
+ function getAPIParametersSig(pkg, method, imports) {
1304
1354
  const methodParams = helpers.getMethodParameters(method, consolidateHostParams);
1305
1355
  const params = new Array();
1306
1356
  if (method.kind !== 'pageableMethod') {
@@ -1312,7 +1362,7 @@ function getAPIParametersSig(method, imports, pkgName) {
1312
1362
  if (methodParam.kind === 'uriParam') {
1313
1363
  paramName = 'host';
1314
1364
  }
1315
- params.push(`${paramName} ${helpers.formatParameterTypeName(methodParam, pkgName)}`);
1365
+ params.push(`${paramName} ${helpers.formatParameterTypeName(pkg, methodParam)}`);
1316
1366
  }
1317
1367
  return params.join(', ');
1318
1368
  }