@azure-tools/typespec-go 0.5.0 → 0.5.1

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 (38) hide show
  1. package/dist/codegen.go/src/clientFactory.js.map +1 -1
  2. package/dist/codegen.go/src/example.js.map +1 -1
  3. package/dist/codegen.go/src/fake/servers.js +164 -167
  4. package/dist/codegen.go/src/fake/servers.js.map +1 -1
  5. package/dist/codegen.go/src/helpers.d.ts +38 -11
  6. package/dist/codegen.go/src/helpers.d.ts.map +1 -1
  7. package/dist/codegen.go/src/helpers.js +168 -96
  8. package/dist/codegen.go/src/helpers.js.map +1 -1
  9. package/dist/codegen.go/src/operations.d.ts.map +1 -1
  10. package/dist/codegen.go/src/operations.js +205 -220
  11. package/dist/codegen.go/src/operations.js.map +1 -1
  12. package/dist/codegen.go/src/polymorphics.d.ts.map +1 -1
  13. package/dist/codegen.go/src/polymorphics.js +12 -13
  14. package/dist/codegen.go/src/polymorphics.js.map +1 -1
  15. package/dist/codegen.go/src/responses.js +17 -9
  16. package/dist/codegen.go/src/responses.js.map +1 -1
  17. package/dist/codegen.go/src/time.js +4 -4
  18. package/dist/codegen.go/src/time.js.map +1 -1
  19. package/dist/codemodel.go/src/client.d.ts +6 -4
  20. package/dist/codemodel.go/src/client.d.ts.map +1 -1
  21. package/dist/codemodel.go/src/client.js.map +1 -1
  22. package/dist/codemodel.go/src/examples.d.ts +5 -4
  23. package/dist/codemodel.go/src/examples.d.ts.map +1 -1
  24. package/dist/codemodel.go/src/examples.js.map +1 -1
  25. package/dist/codemodel.go/src/package.js.map +1 -1
  26. package/dist/codemodel.go/src/param.d.ts +183 -70
  27. package/dist/codemodel.go/src/param.d.ts.map +1 -1
  28. package/dist/codemodel.go/src/param.js +48 -56
  29. package/dist/codemodel.go/src/param.js.map +1 -1
  30. package/dist/codemodel.go/src/result.d.ts +90 -25
  31. package/dist/codemodel.go/src/result.d.ts.map +1 -1
  32. package/dist/codemodel.go/src/result.js +26 -53
  33. package/dist/codemodel.go/src/result.js.map +1 -1
  34. package/dist/typespec-go/src/tcgcadapter/clients.d.ts +3 -3
  35. package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -1
  36. package/dist/typespec-go/src/tcgcadapter/clients.js +27 -25
  37. package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -1
  38. package/package.json +3 -3
@@ -98,7 +98,7 @@ export async function generateServers(codeModel) {
98
98
  const operationName = fixUpMethodName(method);
99
99
  content += `\t// ${operationName} is the fake for method ${client.name}.${operationName}\n`;
100
100
  const successCodes = new Array();
101
- if (method.responseEnvelope.result && go.isAnyResult(method.responseEnvelope.result)) {
101
+ if (method.responseEnvelope.result?.kind === 'anyResult') {
102
102
  for (const httpStatus of getMethodStatusCodes(method)) {
103
103
  const result = method.responseEnvelope.result.httpStatusCodeType[httpStatus];
104
104
  if (!result) {
@@ -322,19 +322,19 @@ function generateServerTransportMethods(codeModel, serverTransport, finalMethods
322
322
  const formattedStatusCodes = helpers.formatStatusCodes(method.httpStatusCodes);
323
323
  content += `\tif !contains([]int{${formattedStatusCodes}}, respContent.HTTPStatus) {\n`;
324
324
  content += `\t\treturn nil, &nonRetriableError{fmt.Errorf("unexpected status code %d. acceptable values are ${formattedStatusCodes}", respContent.HTTPStatus)}\n\t}\n`;
325
- if (!method.responseEnvelope.result || go.isHeadAsBooleanResult(method.responseEnvelope.result)) {
325
+ if (!method.responseEnvelope.result || method.responseEnvelope.result.kind === 'headAsBooleanResult') {
326
326
  content += '\tresp, err := server.NewResponse(respContent, req, nil)\n';
327
327
  }
328
- else if (go.isAnyResult(method.responseEnvelope.result)) {
328
+ else if (method.responseEnvelope.result.kind === 'anyResult') {
329
329
  content += `\tresp, err := server.MarshalResponseAs${method.responseEnvelope.result.format}(respContent, server.GetResponse(respr).${getResultFieldName(method.responseEnvelope.result)}, req)\n`;
330
330
  }
331
- else if (go.isBinaryResult(method.responseEnvelope.result)) {
331
+ else if (method.responseEnvelope.result.kind === 'binaryResult') {
332
332
  content += '\tresp, err := server.NewResponse(respContent, req, &server.ResponseOptions{\n';
333
333
  content += `\t\tBody: server.GetResponse(respr).${getResultFieldName(method.responseEnvelope.result)},\n`;
334
334
  content += '\t\tContentType: req.Header.Get("Content-Type"),\n';
335
335
  content += '\t})\n';
336
336
  }
337
- else if (go.isMonomorphicResult(method.responseEnvelope.result)) {
337
+ else if (method.responseEnvelope.result.kind === 'monomorphicResult') {
338
338
  if (go.isBytesType(method.responseEnvelope.result.monomorphicType)) {
339
339
  const encoding = method.responseEnvelope.result.monomorphicType.encoding;
340
340
  content += `\tresp, err := server.MarshalResponseAsByteArray(respContent, server.GetResponse(respr).${getResultFieldName(method.responseEnvelope.result)}, runtime.Base64${encoding}Format, req)\n`;
@@ -359,7 +359,7 @@ function generateServerTransportMethods(codeModel, serverTransport, finalMethods
359
359
  content += `\tresp, err := server.MarshalResponseAs${method.responseEnvelope.result.format}(respContent, ${responseField}, req)\n`;
360
360
  }
361
361
  }
362
- else if (go.isModelResult(method.responseEnvelope.result) || go.isPolymorphicResult(method.responseEnvelope.result)) {
362
+ else if (method.responseEnvelope.result.kind === 'modelResult' || method.responseEnvelope.result.kind === 'polymorphicResult') {
363
363
  const respField = `.${getResultFieldName(method.responseEnvelope.result)}`;
364
364
  const responseField = `server.GetResponse(respr)${respField}`;
365
365
  content += `\tresp, err := server.MarshalResponseAs${method.responseEnvelope.result.format}(respContent, ${responseField}, req)\n`;
@@ -367,10 +367,10 @@ function generateServerTransportMethods(codeModel, serverTransport, finalMethods
367
367
  content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
368
368
  // propagate any header response values into the *http.Response
369
369
  for (const header of values(method.responseEnvelope.headers)) {
370
- if (go.isHeaderMapResponse(header)) {
370
+ if (header.kind === 'headerMapResponse') {
371
371
  content += `\tfor k, v := range server.GetResponse(respr).${header.fieldName} {\n`;
372
372
  content += '\t\tif v != nil {\n';
373
- content += `\t\t\tresp.Header.Set("${header.collectionPrefix}"+k, *v)\n`;
373
+ content += `\t\t\tresp.Header.Set("${header.headerName}"+k, *v)\n`;
374
374
  content += '\t\t}\n';
375
375
  content += '\t}\n';
376
376
  }
@@ -393,11 +393,12 @@ function generateServerTransportMethods(codeModel, serverTransport, finalMethods
393
393
  return content;
394
394
  }
395
395
  function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
396
- const numPathParams = values(method.parameters).where((each) => { return go.isPathParameter(each) && !go.isLiteralParameter(each); }).count();
396
+ const methodParamGroups = helpers.getMethodParamGroups(method);
397
+ const numPathParams = values(methodParamGroups.pathParams).where((each) => { return !go.isLiteralParameter(each); }).count();
397
398
  let content = '';
398
399
  if (numPathParams > 0) {
399
400
  imports.add('regexp');
400
- content += `\tconst regexStr = \`${createPathParamsRegex(method)}\`\n`;
401
+ content += `\tconst regexStr = \`${createPathParamsRegex(method, methodParamGroups.pathParams)}\`\n`;
401
402
  content += '\tregex := regexp.MustCompile(regexStr)\n';
402
403
  content += '\tmatches := regex.FindStringSubmatch(req.URL.EscapedPath())\n';
403
404
  // the total number of matches is the number of capture groups
@@ -405,30 +406,70 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
405
406
  content += `\tif len(matches) < ${numPathParams + 1} {\n`;
406
407
  content += '\t\treturn nil, fmt.Errorf("failed to parse path %s", req.URL.Path)\n\t}\n';
407
408
  }
408
- if (values(method.parameters).where((each) => { return go.isQueryParameter(each) && each.location === 'method' && !go.isLiteralParameter(each); }).any()) {
409
+ const allQueryParams = methodParamGroups.encodedQueryParams.concat(methodParamGroups.unencodedQueryParams);
410
+ if (values(allQueryParams).where((each) => { return each.location === 'method' && !go.isLiteralParameter(each); }).any()) {
409
411
  content += '\tqp := req.URL.Query()\n';
410
412
  }
411
- const bodyParam = values(method.parameters).where((each) => {
412
- return go.isBodyParameter(each) || go.isFormBodyParameter(each) || go.isMultipartFormBodyParameter(each) || go.isPartialBodyParameter(each);
413
- }).first();
414
- if (!bodyParam) {
415
- // no body, just headers and/or query params
413
+ // note that these are mutually exclusive
414
+ const bodyParam = methodParamGroups.bodyParam;
415
+ const formBodyParams = methodParamGroups.formBodyParams;
416
+ const multipartBodyParams = methodParamGroups.multipartBodyParams;
417
+ const partialBodyParams = methodParamGroups.partialBodyParams;
418
+ if (bodyParam) {
419
+ switch (bodyParam.bodyFormat) {
420
+ case 'JSON':
421
+ case 'XML':
422
+ if (bodyParam && !go.isLiteralParameter(bodyParam)) {
423
+ imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
424
+ if (go.isBytesType(bodyParam.type)) {
425
+ content += `\tbody, err := server.UnmarshalRequestAsByteArray(req, runtime.Base64${bodyParam.type.encoding}Format)\n`;
426
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
427
+ }
428
+ else if (go.isSliceType(bodyParam.type) && bodyParam.type.rawJSONAsBytes) {
429
+ content += '\tbody, err := io.ReadAll(req.Body)\n';
430
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
431
+ content += '\treq.Body.Close()\n';
432
+ }
433
+ else if (go.isInterfaceType(bodyParam.type)) {
434
+ requiredHelpers.readRequestBody = true;
435
+ content += '\traw, err := readRequestBody(req)\n';
436
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
437
+ content += `\tbody, err := unmarshal${bodyParam.type.name}(raw)\n`;
438
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
439
+ }
440
+ else {
441
+ let bodyTypeName = go.getTypeDeclaration(bodyParam.type, clientPkg);
442
+ if (go.isTimeType(bodyParam.type)) {
443
+ bodyTypeName = bodyParam.type.dateTimeFormat;
444
+ }
445
+ content += `\tbody, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
446
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
447
+ }
448
+ }
449
+ break;
450
+ case 'Text':
451
+ if (bodyParam && !go.isLiteralParameter(bodyParam)) {
452
+ imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
453
+ content += '\tbody, err := server.UnmarshalRequestAsText(req)\n';
454
+ content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
455
+ }
456
+ break;
457
+ }
458
+ // nothing to do for binary media type
416
459
  }
417
- else if (go.isMultipartFormBodyParameter(bodyParam)) {
460
+ else if (multipartBodyParams.length > 0) {
418
461
  imports.add('io');
419
462
  imports.add('mime');
420
463
  imports.add('mime/multipart');
421
464
  content += '\t_, params, err := mime.ParseMediaType(req.Header.Get("Content-Type"))\n';
422
465
  content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
423
466
  content += '\treader := multipart.NewReader(req.Body, params["boundary"])\n';
424
- for (const param of values(method.parameters)) {
425
- if (go.isMultipartFormBodyParameter(param)) {
426
- let pkgPrefix = '';
427
- if (go.isConstantType(param.type) || go.isModelType(param.type)) {
428
- pkgPrefix = clientPkg + '.';
429
- }
430
- content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
467
+ for (const param of multipartBodyParams) {
468
+ let pkgPrefix = '';
469
+ if (go.isConstantType(param.type) || go.isModelType(param.type)) {
470
+ pkgPrefix = clientPkg + '.';
431
471
  }
472
+ content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
432
473
  }
433
474
  content += '\tfor {\n';
434
475
  content += '\t\tvar part *multipart.Part\n';
@@ -567,95 +608,49 @@ function dispatchForOperationBody(clientPkg, receiverName, method, imports) {
567
608
  }
568
609
  return caseContent;
569
610
  };
570
- for (const param of values(method.parameters)) {
571
- if (go.isMultipartFormBodyParameter(param)) {
572
- if (go.isModelType(param.type)) {
573
- for (const field of param.type.fields) {
574
- content += emitCase(field.serializedName, `${param.name}.${field.name}`, field.type);
575
- }
576
- }
577
- else {
578
- content += emitCase(param.name, param.name, param.type);
611
+ for (const param of multipartBodyParams) {
612
+ if (go.isModelType(param.type)) {
613
+ for (const field of param.type.fields) {
614
+ content += emitCase(field.serializedName, `${param.name}.${field.name}`, field.type);
579
615
  }
580
616
  }
617
+ else {
618
+ content += emitCase(param.name, param.name, param.type);
619
+ }
581
620
  }
582
621
  content += '\t\tdefault:\n\t\t\treturn nil, fmt.Errorf("unexpected part %s", fn)\n';
583
622
  content += '\t\t}\n'; // end switch
584
623
  content += '\t}\n'; // end for
585
624
  }
586
- else if (go.isFormBodyParameter(bodyParam)) {
587
- for (const param of values(method.parameters)) {
588
- if (go.isFormBodyParameter(param)) {
589
- let pkgPrefix = '';
590
- if (go.isConstantType(param.type)) {
591
- pkgPrefix = clientPkg + '.';
592
- }
593
- content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
625
+ else if (formBodyParams.length > 0) {
626
+ for (const param of formBodyParams) {
627
+ let pkgPrefix = '';
628
+ if (go.isConstantType(param.type)) {
629
+ pkgPrefix = clientPkg + '.';
594
630
  }
631
+ content += `\tvar ${param.name} ${pkgPrefix}${go.getTypeDeclaration(param.type)}\n`;
595
632
  }
596
633
  content += '\tif err := req.ParseForm(); err != nil {\n\t\treturn nil, &nonRetriableError{fmt.Errorf("failed parsing form data: %v", err)}\n\t}\n';
597
634
  content += '\tfor key := range req.Form {\n';
598
635
  content += '\t\tswitch key {\n';
599
- for (const param of values(method.parameters)) {
600
- if (go.isFormBodyParameter(param)) {
601
- content += `\t\tcase "${param.formDataName}":\n`;
602
- let assignedValue;
603
- if (go.isConstantType(param.type)) {
604
- assignedValue = `${go.getTypeDeclaration(param.type, clientPkg)}(req.FormValue(key))`;
605
- }
606
- else if (go.isPrimitiveType(param.type) && param.type.typeName === 'string') {
607
- assignedValue = 'req.FormValue(key)';
608
- }
609
- else {
610
- throw new CodegenError('InternalError', `uhandled form parameter type ${go.getTypeDeclaration(param.type)}`);
611
- }
612
- content += `\t\t\t${param.name} = ${assignedValue}\n`;
613
- }
614
- }
615
- content += '\t\t}\n'; // end switch
616
- content += '\t}\n'; // end for
617
- }
618
- else if (bodyParam.bodyFormat === 'binary') {
619
- // nothing to do for binary media type
620
- }
621
- else if (bodyParam.bodyFormat === 'Text') {
622
- if (bodyParam && !go.isLiteralParameter(bodyParam)) {
623
- imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
624
- content += '\tbody, err := server.UnmarshalRequestAsText(req)\n';
625
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
626
- }
627
- }
628
- else if (bodyParam.bodyFormat === 'JSON' || bodyParam.bodyFormat === 'XML') {
629
- if (bodyParam && !go.isLiteralParameter(bodyParam)) {
630
- imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake', 'azfake');
631
- if (go.isBytesType(bodyParam.type)) {
632
- content += `\tbody, err := server.UnmarshalRequestAsByteArray(req, runtime.Base64${bodyParam.type.encoding}Format)\n`;
633
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
634
- }
635
- else if (go.isSliceType(bodyParam.type) && bodyParam.type.rawJSONAsBytes) {
636
- content += '\tbody, err := io.ReadAll(req.Body)\n';
637
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
638
- content += '\treq.Body.Close()\n';
636
+ for (const param of formBodyParams) {
637
+ content += `\t\tcase "${param.formDataName}":\n`;
638
+ let assignedValue;
639
+ if (go.isConstantType(param.type)) {
640
+ assignedValue = `${go.getTypeDeclaration(param.type, clientPkg)}(req.FormValue(key))`;
639
641
  }
640
- else if (go.isInterfaceType(bodyParam.type)) {
641
- requiredHelpers.readRequestBody = true;
642
- content += '\traw, err := readRequestBody(req)\n';
643
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
644
- content += `\tbody, err := unmarshal${bodyParam.type.name}(raw)\n`;
645
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
642
+ else if (go.isPrimitiveType(param.type) && param.type.typeName === 'string') {
643
+ assignedValue = 'req.FormValue(key)';
646
644
  }
647
645
  else {
648
- let bodyTypeName = go.getTypeDeclaration(bodyParam.type, clientPkg);
649
- if (go.isTimeType(bodyParam.type)) {
650
- bodyTypeName = bodyParam.type.dateTimeFormat;
651
- }
652
- content += `\tbody, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
653
- content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
646
+ throw new CodegenError('InternalError', `uhandled form parameter type ${go.getTypeDeclaration(param.type)}`);
654
647
  }
648
+ content += `\t\t\t${param.name} = ${assignedValue}\n`;
655
649
  }
650
+ content += '\t\t}\n'; // end switch
651
+ content += '\t}\n'; // end for
656
652
  }
657
- const partialBodyParams = values(method.parameters).where((param) => { return go.isPartialBodyParameter(param); }).toArray();
658
- if (partialBodyParams.length > 0) {
653
+ else if (partialBodyParams.length > 0) {
659
654
  // construct the partial body params type and unmarshal it
660
655
  content += '\ttype partialBodyParams struct {\n';
661
656
  for (const partialBodyParam of partialBodyParams) {
@@ -751,7 +746,7 @@ function sanitizeRegexpCaptureGroupName(name) {
751
746
  // dash '-' characters are not allowed so replace them with '_'
752
747
  return name.replace('-', '_');
753
748
  }
754
- function createPathParamsRegex(method) {
749
+ function createPathParamsRegex(method, pathParams) {
755
750
  // "/subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}"
756
751
  // each path param will replaced with a regex capture.
757
752
  // note that some path params are optional.
@@ -760,10 +755,7 @@ function createPathParamsRegex(method) {
760
755
  // per RFC3986, these are the pchars that also double as regex tokens
761
756
  // . $ * + ()
762
757
  urlPath = urlPath.replace(/([.$*+()])/g, '\\$1');
763
- for (const param of values(method.parameters)) {
764
- if (!go.isPathParameter(param)) {
765
- continue;
766
- }
758
+ for (const param of pathParams) {
767
759
  const toReplace = `{${param.pathSegment}}`;
768
760
  let replaceWith = `(?P<${sanitizeRegexpCaptureGroupName(param.pathSegment)}>[!#&$-;=?-\\[\\]_a-zA-Z0-9~%@]+)`;
769
761
  if (param.style === 'optional' || param.style === 'flag') {
@@ -805,22 +797,28 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
805
797
  // client params and parameter literals aren't passed to APIs
806
798
  continue;
807
799
  }
808
- if (go.isResumeTokenParameter(param)) {
800
+ if (param.kind === 'resumeTokenParam') {
809
801
  // skip the ResumeToken param as we don't send that back to the caller
810
802
  continue;
811
803
  }
812
804
  // NOTE: param group check must happen before skipping body params.
813
805
  // this is to handle the case where the body param is grouped/optional
814
806
  if (param.group) {
815
- if (!paramGroups.has(param.group)) {
816
- paramGroups.set(param.group, new Array());
807
+ let params = paramGroups.get(param.group);
808
+ if (!params) {
809
+ params = new Array();
810
+ paramGroups.set(param.group, params);
817
811
  }
818
- const params = paramGroups.get(param.group);
819
812
  params.push(param);
820
813
  }
821
- if (go.isBodyParameter(param) || go.isFormBodyParameter(param) || go.isMultipartFormBodyParameter(param) || go.isPartialBodyParameter(param)) {
822
- // body params will be unmarshalled, no need for parsing.
823
- continue;
814
+ switch (param.kind) {
815
+ case 'bodyParam':
816
+ case 'formBodyCollectionParam':
817
+ case 'formBodyScalarParam':
818
+ case 'multipartFormBodyParam':
819
+ case 'partialBodyParam':
820
+ // body params will be unmarshalled, no need for parsing.
821
+ continue;
824
822
  }
825
823
  // paramValue is initialized with the "raw" source value.
826
824
  // e.g. getHeaderValue(...), qp.Get("foo") etc
@@ -830,7 +828,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
830
828
  let paramValue = getRawParamValue(param);
831
829
  // path/query params might be escaped, so we need to unescape them first.
832
830
  // must handle query collections first as it's a superset of query param.
833
- if (go.isQueryCollectionParameter(param) && param.collectionFormat === 'multi') {
831
+ if (param.kind === 'queryCollectionParam' && param.collectionFormat === 'multi') {
834
832
  imports.add('net/url');
835
833
  const escapedParam = createLocalVariableName(param, 'Escaped');
836
834
  content += `\t${escapedParam} := ${paramValue}\n`;
@@ -882,7 +880,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
882
880
  paramValue = paramVar;
883
881
  }
884
882
  // parse params as required
885
- if (go.isHeaderCollectionParameter(param) || go.isPathCollectionParameter(param) || go.isQueryCollectionParameter(param)) {
883
+ if (param.kind === 'headerCollectionParam' || param.kind === 'pathCollectionParam' || param.kind === 'queryCollectionParam') {
886
884
  // any element type other than string will require some form of conversion/parsing
887
885
  if (!(go.isPrimitiveType(param.type.elementType) && param.type.elementType.typeName === 'string')) {
888
886
  if (param.collectionFormat !== 'multi') {
@@ -1057,13 +1055,13 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1057
1055
  }
1058
1056
  content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
1059
1057
  }
1060
- else if (go.isHeaderMapParameter(param)) {
1058
+ else if (param.kind === 'headerMapParam') {
1061
1059
  imports.add('strings');
1062
1060
  imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/to');
1063
1061
  const localVar = createLocalVariableName(param, 'Param');
1064
1062
  content += `\tvar ${localVar} map[string]*string\n`;
1065
1063
  content += `\tfor hh := range ${paramValue} {\n`;
1066
- const headerPrefix = param.collectionPrefix;
1064
+ const headerPrefix = param.headerName;
1067
1065
  requiredHelpers.getHeaderValue = true;
1068
1066
  content += `\t\tif len(hh) > len("${headerPrefix}") && strings.EqualFold(hh[:len("x-ms-meta-")], "${headerPrefix}") {\n`;
1069
1067
  content += `\t\t\tif ${localVar} == nil {\n\t\t\t\t${localVar} = map[string]*string{}\n\t\t\t}\n`;
@@ -1126,7 +1124,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1126
1124
  if (go.isSliceType(param.type)) {
1127
1125
  paramNilCheck.push(`len(${getFinalParamValue(clientPkg, param, paramValues)}) > 0`);
1128
1126
  }
1129
- else if (go.isBodyParameter(param)) {
1127
+ else if (param.kind === 'bodyParam') {
1130
1128
  if (param.bodyFormat === 'binary') {
1131
1129
  imports.add('io');
1132
1130
  paramNilCheck.push('req.Body != nil');
@@ -1136,7 +1134,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1136
1134
  paramNilCheck.push('!reflect.ValueOf(body).IsZero()');
1137
1135
  }
1138
1136
  }
1139
- else if (go.isFormBodyParameter(param) || go.isMultipartFormBodyParameter(param)) {
1137
+ else if (go.isFormBodyParameter(param) || param.kind === 'multipartFormBodyParam') {
1140
1138
  imports.add('reflect');
1141
1139
  paramNilCheck.push(`!reflect.ValueOf(${param.name}).IsZero()`);
1142
1140
  }
@@ -1148,7 +1146,7 @@ function parseHeaderPathQueryParams(clientPkg, method, imports) {
1148
1146
  content += `\t\t${uncapitalize(paramGroup.name)} = &${clientPkg}.${paramGroup.groupName}{\n`;
1149
1147
  for (const param of values(params)) {
1150
1148
  let byRef = '&';
1151
- if (param.byValue || (!go.isRequiredParameter(param) && !go.isBodyParameter(param) && !go.isFormBodyParameter(param) && !go.isMultipartFormBodyParameter(param))) {
1149
+ if (param.byValue || (!go.isRequiredParameter(param) && param.kind !== 'bodyParam' && !go.isFormBodyParameter(param) && param.kind !== 'multipartFormBodyParam')) {
1152
1150
  byRef = '';
1153
1151
  }
1154
1152
  content += `\t\t\t${capitalize(param.name)}: ${byRef}${getFinalParamValue(clientPkg, param, paramValues)},\n`;
@@ -1174,10 +1172,10 @@ function populateApiParams(clientPkg, method, paramValues, imports) {
1174
1172
  }
1175
1173
  // now create the API call sig
1176
1174
  for (const param of values(helpers.getMethodParameters(method, consolidateHostParams))) {
1177
- if (helpers.isParameterGroup(param)) {
1175
+ if (param.kind === 'paramGroup') {
1178
1176
  if (param.groupName === method.optionalParamsGroup.groupName) {
1179
1177
  // this is the optional params type. in some cases we just pass nil
1180
- const countParams = values(param.params).where((each) => { return !go.isResumeTokenParameter(each); }).count();
1178
+ const countParams = values(param.params).where((each) => { return each.kind !== 'resumeTokenParam'; }).count();
1181
1179
  if (countParams === 0) {
1182
1180
  // if the options param is empty or only contains the resume token param just pass nil
1183
1181
  params.push('nil');
@@ -1197,43 +1195,42 @@ function populateApiParams(clientPkg, method, paramValues, imports) {
1197
1195
  // getRawParamValue returns the "raw" value for the specified parameter.
1198
1196
  // depending on the type, the value might require parsing before it can be passed to the fake.
1199
1197
  function getRawParamValue(param) {
1200
- if (go.isFormBodyParameter(param) || go.isMultipartFormBodyParameter(param) || go.isPartialBodyParameter(param)) {
1201
- // multipart form data values have been read and assigned
1202
- // to local params with the same name. must check this first
1203
- // as it's a superset of other cases that follow.
1204
- return param.name;
1205
- }
1206
- else if (go.isPathParameter(param)) {
1207
- // path params are in the matches slice
1208
- return `matches[regex.SubexpIndex("${sanitizeRegexpCaptureGroupName(param.pathSegment)}")]`;
1209
- }
1210
- else if (go.isQueryParameter(param)) {
1211
- // use qp
1212
- if (go.isQueryCollectionParameter(param) && param.collectionFormat === 'multi') {
1213
- return `qp["${param.queryParameter}"]`;
1214
- }
1215
- return `qp.Get("${param.queryParameter}")`;
1216
- }
1217
- else if (go.isHeaderParameter(param)) {
1218
- if (go.isHeaderMapParameter(param)) {
1198
+ switch (param.kind) {
1199
+ case 'bodyParam':
1200
+ if (param.bodyFormat === 'binary') {
1201
+ return 'req.Body.(io.ReadSeekCloser)';
1202
+ }
1203
+ // JSON/XML/text bodies have been deserialized into a local named body
1204
+ return 'body';
1205
+ case 'formBodyCollectionParam':
1206
+ case 'formBodyScalarParam':
1207
+ case 'multipartFormBodyParam':
1208
+ case 'partialBodyParam':
1209
+ // multipart form data values have been read and assigned
1210
+ // to local params with the same name.
1211
+ return param.name;
1212
+ case 'headerCollectionParam':
1213
+ case 'headerScalarParam':
1214
+ // use req
1215
+ requiredHelpers.getHeaderValue = true;
1216
+ return `getHeaderValue(req.Header, "${param.headerName}")`;
1217
+ case 'headerMapParam':
1219
1218
  return 'req.Header';
1220
- }
1221
- // use req
1222
- requiredHelpers.getHeaderValue = true;
1223
- return `getHeaderValue(req.Header, "${param.headerName}")`;
1224
- }
1225
- else if (go.isBodyParameter(param)) {
1226
- if (param.bodyFormat === 'binary') {
1227
- return 'req.Body.(io.ReadSeekCloser)';
1228
- }
1229
- // JSON/XML/text bodies have been deserialized into a local named body
1230
- return 'body';
1231
- }
1232
- else if (go.isURIParameter(param)) {
1233
- return 'req.URL.Host';
1234
- }
1235
- else {
1236
- throw new CodegenError('InternalError', `unhandled parameter ${param.name}`);
1219
+ case 'pathCollectionParam':
1220
+ case 'pathScalarParam':
1221
+ // path params are in the matches slice
1222
+ return `matches[regex.SubexpIndex("${sanitizeRegexpCaptureGroupName(param.pathSegment)}")]`;
1223
+ case 'queryCollectionParam':
1224
+ case 'queryScalarParam':
1225
+ // use qp
1226
+ if (param.kind === 'queryCollectionParam' && param.collectionFormat === 'multi') {
1227
+ return `qp["${param.queryParameter}"]`;
1228
+ }
1229
+ return `qp.Get("${param.queryParameter}")`;
1230
+ case 'uriParam':
1231
+ return 'req.URL.Host';
1232
+ default:
1233
+ throw new CodegenError('InternalError', `unhandled parameter ${param.name}`);
1237
1234
  }
1238
1235
  }
1239
1236
  // getFinalParamValue returns the "final" value of param to be passed to the fake.
@@ -1244,13 +1241,13 @@ function getFinalParamValue(clientPkg, param, paramValues) {
1244
1241
  paramValue = getRawParamValue(param);
1245
1242
  }
1246
1243
  // there are a few corner-cases that require some fix-ups
1247
- if ((go.isBodyParameter(param) || go.isFormBodyParameter(param) || go.isFormBodyCollectionParameter(param) || go.isMultipartFormBodyParameter(param)) && go.isTimeType(param.type)) {
1244
+ if ((param.kind === 'bodyParam' || go.isFormBodyParameter(param) || param.kind === 'multipartFormBodyParam') && go.isTimeType(param.type)) {
1248
1245
  // time types in the body have been unmarshalled into our time helpers thus require a cast to time.Time
1249
1246
  return `time.Time(${paramValue})`;
1250
1247
  }
1251
1248
  else if (go.isRequiredParameter(param)) {
1252
1249
  // optional params are always in their "final" form
1253
- if (go.isHeaderCollectionParameter(param) || go.isPathCollectionParameter(param) || go.isQueryCollectionParameter(param)) {
1250
+ if (param.kind === 'headerCollectionParam' || param.kind === 'pathCollectionParam' || param.kind === 'queryCollectionParam') {
1254
1251
  // for required params that are collections of strings, we split them inline.
1255
1252
  // not necessary for optional params as they're already in slice format.
1256
1253
  if (param.collectionFormat !== 'multi' && go.isPrimitiveType(param.type.elementType) && param.type.elementType.typeName === 'string') {
@@ -1263,7 +1260,7 @@ function getFinalParamValue(clientPkg, param, paramValues) {
1263
1260
  return `${go.getTypeDeclaration(param.type, clientPkg)}(${paramValue})`;
1264
1261
  }
1265
1262
  }
1266
- else if (go.isPartialBodyParameter(param)) {
1263
+ else if (param.kind === 'partialBodyParam') {
1267
1264
  // use the value from the unmarshaled, intermediate struct type
1268
1265
  return `body.${capitalize(param.name)}`;
1269
1266
  }
@@ -1275,7 +1272,7 @@ function getFinalParamValue(clientPkg, param, paramValues) {
1275
1272
  // there's no way to reliably split the host back up into its constituent parameters.
1276
1273
  // so we just pass the full value as a single host parameter.
1277
1274
  function consolidateHostParams(params) {
1278
- if (!values(params).where((each) => { return go.isURIParameter(each); }).any()) {
1275
+ if (!values(params).where((each) => { return each.kind === 'uriParam'; }).any()) {
1279
1276
  // no host params
1280
1277
  return params;
1281
1278
  }
@@ -1283,7 +1280,7 @@ function consolidateHostParams(params) {
1283
1280
  const consolidatedParams = new Array();
1284
1281
  let hostParamAdded = false;
1285
1282
  for (const param of values(params)) {
1286
- if (!go.isURIParameter(param)) {
1283
+ if (param.kind !== 'uriParam') {
1287
1284
  consolidatedParams.push(param);
1288
1285
  }
1289
1286
  else if (!hostParamAdded) {
@@ -1303,7 +1300,7 @@ function getAPIParametersSig(method, imports, pkgName) {
1303
1300
  }
1304
1301
  for (const methodParam of values(methodParams)) {
1305
1302
  let paramName = uncapitalize(methodParam.name);
1306
- if (helpers.isParameter(methodParam) && go.isURIParameter(methodParam)) {
1303
+ if (methodParam.kind === 'uriParam') {
1307
1304
  paramName = 'host';
1308
1305
  }
1309
1306
  params.push(`${paramName} ${helpers.formatParameterTypeName(methodParam, pkgName)}`);
@@ -1312,15 +1309,15 @@ function getAPIParametersSig(method, imports, pkgName) {
1312
1309
  }
1313
1310
  // copied from generator/helpers.ts but without the XML-specific stuff
1314
1311
  function getResultFieldName(result) {
1315
- if (go.isAnyResult(result)) {
1316
- return result.fieldName;
1317
- }
1318
- else if (go.isModelResult(result)) {
1319
- return result.modelType.name;
1320
- }
1321
- else if (go.isPolymorphicResult(result)) {
1322
- return result.interfaceType.name;
1312
+ switch (result.kind) {
1313
+ case 'anyResult':
1314
+ return result.fieldName;
1315
+ case 'modelResult':
1316
+ return result.modelType.name;
1317
+ case 'polymorphicResult':
1318
+ return result.interfaceType.name;
1319
+ default:
1320
+ return result.fieldName;
1323
1321
  }
1324
- return result.fieldName;
1325
1322
  }
1326
1323
  //# sourceMappingURL=servers.js.map