@azure-tools/typespec-go 0.9.0 → 0.9.2
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/constants.d.ts.map +1 -1
- package/dist/codegen.go/src/core/constants.js +3 -4
- package/dist/codegen.go/src/core/constants.js.map +1 -1
- package/dist/codegen.go/src/core/example.d.ts.map +1 -1
- package/dist/codegen.go/src/core/example.js +15 -24
- package/dist/codegen.go/src/core/example.js.map +1 -1
- package/dist/codegen.go/src/core/gomod.js +28 -2
- package/dist/codegen.go/src/core/gomod.js.map +1 -1
- package/dist/codegen.go/src/core/helpers.d.ts +14 -4
- package/dist/codegen.go/src/core/helpers.d.ts.map +1 -1
- package/dist/codegen.go/src/core/helpers.js +202 -28
- package/dist/codegen.go/src/core/helpers.js.map +1 -1
- package/dist/codegen.go/src/core/imports.d.ts.map +1 -1
- package/dist/codegen.go/src/core/imports.js +2 -3
- package/dist/codegen.go/src/core/imports.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 -5
- package/dist/codegen.go/src/core/interfaces.js.map +1 -1
- package/dist/codegen.go/src/core/metadata.js +1 -1
- package/dist/codegen.go/src/core/metadata.js.map +1 -1
- package/dist/codegen.go/src/core/models.d.ts.map +1 -1
- package/dist/codegen.go/src/core/models.js +78 -26
- 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 +69 -64
- package/dist/codegen.go/src/core/operations.js.map +1 -1
- package/dist/codegen.go/src/core/options.d.ts.map +1 -1
- package/dist/codegen.go/src/core/options.js +3 -4
- 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 +2 -3
- 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 +3 -5
- package/dist/codegen.go/src/core/responses.js.map +1 -1
- package/dist/codegen.go/src/emitter.d.ts.map +1 -1
- package/dist/codegen.go/src/emitter.js +0 -9
- package/dist/codegen.go/src/emitter.js.map +1 -1
- package/dist/codegen.go/src/fake/factory.d.ts.map +1 -1
- package/dist/codegen.go/src/fake/factory.js +1 -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 +89 -92
- package/dist/codegen.go/src/fake/servers.js.map +1 -1
- package/dist/codemodel.go/src/type.d.ts +1 -1
- package/dist/codemodel.go/src/type.d.ts.map +1 -1
- package/dist/naming.go/src/naming.d.ts.map +1 -1
- package/dist/naming.go/src/naming.js +2 -1
- package/dist/naming.go/src/naming.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.js +6 -1
- package/dist/typespec-go/src/tcgcadapter/adapter.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/clients.js +12 -11
- package/dist/typespec-go/src/tcgcadapter/clients.js.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.d.ts.map +1 -1
- package/dist/typespec-go/src/tcgcadapter/types.js +18 -17
- package/dist/typespec-go/src/tcgcadapter/types.js.map +1 -1
- package/package.json +24 -24
- package/dist/codegen.go/src/core/time.d.ts +0 -14
- package/dist/codegen.go/src/core/time.d.ts.map +0 -1
- package/dist/codegen.go/src/core/time.js +0 -580
- package/dist/codegen.go/src/core/time.js.map +0 -1
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as go from '../../../codemodel.go/src/index.js';
|
|
6
|
-
import
|
|
7
|
-
import { capitalize, comment, uncapitalize } from '@azure-tools/codegen';
|
|
8
|
-
import { values } from '@azure-tools/linq';
|
|
6
|
+
import * as naming from '../../../naming.go/src/naming.js';
|
|
9
7
|
import * as helpers from './helpers.js';
|
|
10
8
|
import { ImportManager } from './imports.js';
|
|
11
9
|
import { CodegenError } from './errors.js';
|
|
@@ -78,13 +76,13 @@ export function generateOperations(pkg, target, options) {
|
|
|
78
76
|
// now emit any client params (non parameterized host params case)
|
|
79
77
|
if (client.parameters.length > 0) {
|
|
80
78
|
const addedGroups = new Set();
|
|
81
|
-
for (const clientParam of
|
|
79
|
+
for (const clientParam of client.parameters) {
|
|
82
80
|
if (go.isLiteralParameter(clientParam.style)) {
|
|
83
81
|
continue;
|
|
84
82
|
}
|
|
85
83
|
if (clientParam.group) {
|
|
86
84
|
if (!addedGroups.has(clientParam.group.groupName)) {
|
|
87
|
-
clientText += `\t${uncapitalize(clientParam.group.groupName)} ${!isParamPointer(clientParam) ? '' : '*'}${clientParam.group.groupName}\n`;
|
|
85
|
+
clientText += `\t${naming.uncapitalize(clientParam.group.groupName)} ${!isParamPointer(clientParam) ? '' : '*'}${clientParam.group.groupName}\n`;
|
|
88
86
|
addedGroups.add(clientParam.group.groupName);
|
|
89
87
|
}
|
|
90
88
|
continue;
|
|
@@ -187,14 +185,14 @@ function generateConstructors(client, type, imports) {
|
|
|
187
185
|
// we use azcore.ClientOptions.APIVersion
|
|
188
186
|
continue;
|
|
189
187
|
}
|
|
190
|
-
ctorText += helpers.formatDocCommentWithPrefix(ensureNameCase(param.name), param.docs);
|
|
188
|
+
ctorText += helpers.formatDocCommentWithPrefix(naming.ensureNameCase(param.name), param.docs);
|
|
191
189
|
if (go.isClientSideDefault(param.style)) {
|
|
192
190
|
if (!param.docs.description && !param.docs.summary) {
|
|
193
191
|
ctorText += '\n';
|
|
194
192
|
}
|
|
195
|
-
ctorText += `\t${comment(`The default value is ${helpers.formatLiteralValue(param.style.defaultValue, false)}`, '// ')}.\n`;
|
|
193
|
+
ctorText += `\t${helpers.comment(`The default value is ${helpers.formatLiteralValue(param.style.defaultValue, false)}`, '// ')}.\n`;
|
|
196
194
|
}
|
|
197
|
-
ctorText += `\t${ensureNameCase(param.name)} *${go.getTypeDeclaration(param.type, client.pkg)}\n`;
|
|
195
|
+
ctorText += `\t${naming.ensureNameCase(param.name)} *${go.getTypeDeclaration(param.type, client.pkg)}\n`;
|
|
198
196
|
}
|
|
199
197
|
ctorText += '}\n\n';
|
|
200
198
|
}
|
|
@@ -342,7 +340,7 @@ function generateConstructors(client, type, imports) {
|
|
|
342
340
|
name = 'APIVersion';
|
|
343
341
|
}
|
|
344
342
|
else {
|
|
345
|
-
name = ensureNameCase(param.name);
|
|
343
|
+
name = naming.ensureNameCase(param.name);
|
|
346
344
|
}
|
|
347
345
|
ctorText += `\t${param.name} := ${helpers.formatLiteralValue(param.style.defaultValue, false)}\n`;
|
|
348
346
|
ctorText += `\tif options.${name} != ${helpers.zeroValue(param)} {\n\t\t${param.name} = ${helpers.star(param.byValue)}options.${name}\n\t}\n`;
|
|
@@ -371,7 +369,7 @@ function generateConstructors(client, type, imports) {
|
|
|
371
369
|
// ensure clientVar doesn't collide with any params
|
|
372
370
|
for (const param of consolidatedCtorParams) {
|
|
373
371
|
if (param.name === clientVar) {
|
|
374
|
-
clientVar = ensureNameCase(client.name, true);
|
|
372
|
+
clientVar = naming.ensureNameCase(client.name, true);
|
|
375
373
|
break;
|
|
376
374
|
}
|
|
377
375
|
}
|
|
@@ -379,7 +377,7 @@ function generateConstructors(client, type, imports) {
|
|
|
379
377
|
// NOTE: we don't enumerate consolidatedCtorParams here
|
|
380
378
|
// as any supplemental endpoint params are ephemeral and
|
|
381
379
|
// consumed during client construction.
|
|
382
|
-
for (const parameter of
|
|
380
|
+
for (const parameter of client.parameters) {
|
|
383
381
|
if (go.isLiteralParameter(parameter.style)) {
|
|
384
382
|
continue;
|
|
385
383
|
}
|
|
@@ -411,7 +409,7 @@ function formatHeaderResponseValue(headerResp, imports, respObj, zeroResp) {
|
|
|
411
409
|
return text;
|
|
412
410
|
}
|
|
413
411
|
let text = `\tif val := resp.Header.Get("${headerResp.headerName}"); val != "" {\n`;
|
|
414
|
-
let name = uncapitalize(headerResp.fieldName);
|
|
412
|
+
let name = naming.uncapitalize(headerResp.fieldName);
|
|
415
413
|
let byRef = '&';
|
|
416
414
|
switch (headerResp.type.kind) {
|
|
417
415
|
case 'constant':
|
|
@@ -459,17 +457,17 @@ function formatHeaderResponseValue(headerResp, imports, respObj, zeroResp) {
|
|
|
459
457
|
case 'time':
|
|
460
458
|
imports.add('time');
|
|
461
459
|
switch (headerResp.type.format) {
|
|
462
|
-
case '
|
|
463
|
-
case '
|
|
464
|
-
text += `\t\t${name}, err := time.Parse(${headerResp.type.format === '
|
|
460
|
+
case 'RFC1123':
|
|
461
|
+
case 'RFC3339':
|
|
462
|
+
text += `\t\t${name}, err := time.Parse(${headerResp.type.format === 'RFC1123' ? helpers.RFC1123Format : helpers.RFC3339Format}, val)\n`;
|
|
465
463
|
break;
|
|
466
|
-
case '
|
|
467
|
-
text += `\t\t${name}, err := time.Parse(
|
|
464
|
+
case 'PlainDate':
|
|
465
|
+
text += `\t\t${name}, err := time.Parse(${helpers.plainDateFormat}, val)\n`;
|
|
468
466
|
break;
|
|
469
|
-
case '
|
|
470
|
-
text += `\t\t${name}, err := time.Parse(
|
|
467
|
+
case 'PlainTime':
|
|
468
|
+
text += `\t\t${name}, err := time.Parse(${helpers.plainTimeFormat}, val)\n`;
|
|
471
469
|
break;
|
|
472
|
-
case '
|
|
470
|
+
case 'Unix':
|
|
473
471
|
imports.add('strconv');
|
|
474
472
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/to');
|
|
475
473
|
text += '\t\tsec, err := strconv.ParseInt(val, 10, 64)\n';
|
|
@@ -558,7 +556,7 @@ function emitPagerDefinition(method, imports, options) {
|
|
|
558
556
|
text += `\t\t\t\t\treturn client.${method.nextPageMethod.name}(${nextOpParams.join(', ')})\n\t\t\t\t},\n\t\t\t})\n`;
|
|
559
557
|
}
|
|
560
558
|
else if (method.nextLinkVerb !== 'get') {
|
|
561
|
-
text += `&runtime.FetcherForNextLinkOptions{\n\t\t\t\tHTTPVerb: http.Method${capitalize(method.nextLinkVerb)},\n\t\t\t})\n`;
|
|
559
|
+
text += `&runtime.FetcherForNextLinkOptions{\n\t\t\t\tHTTPVerb: http.Method${naming.capitalize(method.nextLinkVerb)},\n\t\t\t})\n`;
|
|
562
560
|
}
|
|
563
561
|
else {
|
|
564
562
|
text += 'nil)\n';
|
|
@@ -637,7 +635,7 @@ function generateOperation(method, imports, options) {
|
|
|
637
635
|
methodName = method.naming.internalMethod;
|
|
638
636
|
}
|
|
639
637
|
else {
|
|
640
|
-
for (const param of
|
|
638
|
+
for (const param of helpers.getMethodParameters(method)) {
|
|
641
639
|
text += helpers.formatCommentAsBulletItem(param.name, param.docs);
|
|
642
640
|
}
|
|
643
641
|
}
|
|
@@ -703,14 +701,14 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
703
701
|
if (method.kind !== 'nextPageMethod') {
|
|
704
702
|
name = method.naming.requestMethod;
|
|
705
703
|
}
|
|
706
|
-
for (const param of
|
|
704
|
+
for (const param of method.parameters) {
|
|
707
705
|
if (param.location !== 'method' || !go.isRequiredParameter(param.style)) {
|
|
708
706
|
continue;
|
|
709
707
|
}
|
|
710
708
|
imports.addForType(param.type);
|
|
711
709
|
}
|
|
712
710
|
const returns = ['*policy.Request', 'error'];
|
|
713
|
-
let text = `${comment(name, '// ')} creates the ${method.name} request.\n`;
|
|
711
|
+
let text = `${helpers.comment(name, '// ')} creates the ${method.name} request.\n`;
|
|
714
712
|
text += `func ${getClientReceiverDefinition(method.receiver)} ${name}(${helpers.getCreateRequestParametersSig(method)}) (${returns.join(', ')}) {\n`;
|
|
715
713
|
const hostParams = new Array();
|
|
716
714
|
for (const parameter of method.receiver.type.parameters) {
|
|
@@ -731,7 +729,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
731
729
|
text += `\thost = strings.ReplaceAll(host, "{${hostParam.uriPathSegment}}", ${helpers.formatValue(`client.${hostParam.name}`, hostParam.type, imports)})\n`;
|
|
732
730
|
}
|
|
733
731
|
// check for any method local host params
|
|
734
|
-
for (const param of
|
|
732
|
+
for (const param of method.parameters) {
|
|
735
733
|
if (param.location === 'method' && param.kind === 'uriParam') {
|
|
736
734
|
text += `\thost = strings.ReplaceAll(host, "{${param.uriPathSegment}}", ${helpers.formatValue(helpers.getParamName(param), param.type, imports)})\n`;
|
|
737
735
|
}
|
|
@@ -768,12 +766,12 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
768
766
|
if (param.location === 'client') {
|
|
769
767
|
client = 'client.';
|
|
770
768
|
}
|
|
771
|
-
const paramGroupName = uncapitalize(param.group.name);
|
|
769
|
+
const paramGroupName = naming.uncapitalize(param.group.name);
|
|
772
770
|
let optionalParamGroupCheck = `${client}${paramGroupName} != nil && `;
|
|
773
771
|
if (param.group.required) {
|
|
774
772
|
optionalParamGroupCheck = '';
|
|
775
773
|
}
|
|
776
|
-
return `\tif ${optionalParamGroupCheck}${client}${paramGroupName}.${capitalize(param.name)} != nil {\n`;
|
|
774
|
+
return `\tif ${optionalParamGroupCheck}${client}${paramGroupName}.${naming.capitalize(param.name)} != nil {\n`;
|
|
777
775
|
};
|
|
778
776
|
if (hasPathParams) {
|
|
779
777
|
// swagger defines path params, emit path and replace tokens
|
|
@@ -816,7 +814,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
816
814
|
// param isn't required, so emit a local var with
|
|
817
815
|
// the correct default value, then populate it with
|
|
818
816
|
// the optional value when set.
|
|
819
|
-
paramValue = `optional${capitalize(pp.name)}`;
|
|
817
|
+
paramValue = `optional${naming.capitalize(pp.name)}`;
|
|
820
818
|
text += `\t${paramValue} := ""\n`;
|
|
821
819
|
text += emitParamGroupCheck(pp);
|
|
822
820
|
text += `\t${paramValue} = ${helpers.formatParamValue(pp, imports)}\n\t}\n`;
|
|
@@ -846,7 +844,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
846
844
|
text += `\turlPath = strings.ReplaceAll(urlPath, "{${pp.pathSegment}}", ${paramValue})\n`;
|
|
847
845
|
}
|
|
848
846
|
}
|
|
849
|
-
text += `\treq, err := runtime.NewRequest(ctx, http.Method${capitalize(method.httpMethod)}, ${hostParam})\n`;
|
|
847
|
+
text += `\treq, err := runtime.NewRequest(ctx, http.Method${naming.capitalize(method.httpMethod)}, ${hostParam})\n`;
|
|
850
848
|
text += '\tif err != nil {\n';
|
|
851
849
|
text += '\t\treturn nil, err\n';
|
|
852
850
|
text += '\t}\n';
|
|
@@ -877,7 +875,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
877
875
|
// emit encoded params first
|
|
878
876
|
if (encodedParams.length > 0) {
|
|
879
877
|
text += '\treqQP := req.Raw().URL.Query()\n';
|
|
880
|
-
for (const qp of
|
|
878
|
+
for (const qp of encodedParams.sort((a, b) => { return helpers.sortAscending(a.queryParameter, b.queryParameter); })) {
|
|
881
879
|
let setter;
|
|
882
880
|
if (qp.kind === 'queryCollectionParam' && qp.collectionFormat === 'multi') {
|
|
883
881
|
setter = `\tfor _, qv := range ${helpers.getParamName(qp)} {\n`;
|
|
@@ -921,7 +919,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
921
919
|
else {
|
|
922
920
|
text += '\tunencodedParams := []string{}\n';
|
|
923
921
|
}
|
|
924
|
-
for (const qp of
|
|
922
|
+
for (const qp of unencodedParams.sort((a, b) => { return helpers.sortAscending(a.queryParameter, b.queryParameter); })) {
|
|
925
923
|
let setter;
|
|
926
924
|
if (qp.kind === 'queryCollectionParam' && qp.collectionFormat === 'multi') {
|
|
927
925
|
setter = `\tfor _, qv := range ${helpers.getParamName(qp)} {\n`;
|
|
@@ -1016,7 +1014,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1016
1014
|
tagName = bodyParam.xml.name;
|
|
1017
1015
|
}
|
|
1018
1016
|
text += `\t\tXMLName xml.Name \`xml:"${tagName}"\`\n`;
|
|
1019
|
-
const fieldName = capitalize(bodyParam.name);
|
|
1017
|
+
const fieldName = naming.capitalize(bodyParam.name);
|
|
1020
1018
|
let tag = go.getTypeDeclaration(bodyParam.type.elementType, method.receiver.type.pkg);
|
|
1021
1019
|
if (bodyParam.type.elementType.kind === 'model' && bodyParam.type.elementType.xml?.name) {
|
|
1022
1020
|
tag = bodyParam.type.elementType.xml.name;
|
|
@@ -1029,10 +1027,11 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1029
1027
|
}
|
|
1030
1028
|
body = `wrapper{${fieldName}: ${addr}${body}}`;
|
|
1031
1029
|
}
|
|
1032
|
-
else if (bodyParam.type.kind === 'time' && bodyParam.type.format !== '
|
|
1030
|
+
else if (bodyParam.type.kind === 'time' && bodyParam.type.format !== 'RFC3339') {
|
|
1033
1031
|
// wrap the body in the internal time type
|
|
1034
|
-
// no need for
|
|
1035
|
-
|
|
1032
|
+
// no need for RFC3339 as the JSON marshaler defaults to that.
|
|
1033
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1034
|
+
body = `datetime.${bodyParam.type.format}(${body})`;
|
|
1036
1035
|
}
|
|
1037
1036
|
else if (isArrayOfDateTimeForMarshalling(bodyParam.type)) {
|
|
1038
1037
|
const timeInfo = isArrayOfDateTimeForMarshalling(bodyParam.type);
|
|
@@ -1040,17 +1039,19 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1040
1039
|
if (timeInfo?.elemByVal) {
|
|
1041
1040
|
elementPtr = '';
|
|
1042
1041
|
}
|
|
1043
|
-
|
|
1042
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1043
|
+
text += `\taux := make([]${elementPtr}datetime.${timeInfo?.format}, len(${body}))\n`;
|
|
1044
1044
|
text += `\tfor i := 0; i < len(${body}); i++ {\n`;
|
|
1045
|
-
text += `\t\taux[i] = (${elementPtr}
|
|
1045
|
+
text += `\t\taux[i] = (${elementPtr}datetime.${timeInfo?.format})(${body}[i])\n`;
|
|
1046
1046
|
text += '\t}\n';
|
|
1047
1047
|
body = 'aux';
|
|
1048
1048
|
}
|
|
1049
1049
|
else if (isMapOfDateTime(bodyParam.type)) {
|
|
1050
|
-
|
|
1051
|
-
|
|
1050
|
+
let timeType = isMapOfDateTime(bodyParam.type);
|
|
1051
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1052
|
+
text += `\taux := map[string]*datetime.${timeType}{}\n`;
|
|
1052
1053
|
text += `\tfor k, v := range ${body} {\n`;
|
|
1053
|
-
text += `\t\taux[k] = (
|
|
1054
|
+
text += `\t\taux[k] = (*datetime.${timeType})(v)\n`;
|
|
1054
1055
|
text += '\t}\n';
|
|
1055
1056
|
body = 'aux';
|
|
1056
1057
|
}
|
|
@@ -1108,13 +1109,13 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1108
1109
|
// define and instantiate an instance of the wire type, using the values from each param.
|
|
1109
1110
|
text += '\tbody := struct {\n';
|
|
1110
1111
|
for (const partialBodyParam of partialBodyParams) {
|
|
1111
|
-
text += `\t\t${capitalize(partialBodyParam.serializedName)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, method.receiver.type.pkg)} \`${partialBodyParam.format.toLowerCase()}:"${partialBodyParam.serializedName}"\`\n`;
|
|
1112
|
+
text += `\t\t${naming.capitalize(partialBodyParam.serializedName)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, method.receiver.type.pkg)} \`${partialBodyParam.format.toLowerCase()}:"${partialBodyParam.serializedName}"\`\n`;
|
|
1112
1113
|
}
|
|
1113
1114
|
text += '\t}{\n';
|
|
1114
1115
|
// required params are emitted as initializers in the struct literal
|
|
1115
1116
|
for (const partialBodyParam of partialBodyParams) {
|
|
1116
1117
|
if (go.isRequiredParameter(partialBodyParam.style)) {
|
|
1117
|
-
text += `\t\t${capitalize(partialBodyParam.serializedName)}: ${uncapitalize(partialBodyParam.name)},\n`;
|
|
1118
|
+
text += `\t\t${naming.capitalize(partialBodyParam.serializedName)}: ${naming.uncapitalize(partialBodyParam.name)},\n`;
|
|
1118
1119
|
}
|
|
1119
1120
|
}
|
|
1120
1121
|
text += '\t}\n';
|
|
@@ -1122,7 +1123,7 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1122
1123
|
for (const partialBodyParam of partialBodyParams) {
|
|
1123
1124
|
if (!go.isRequiredParameter(partialBodyParam.style)) {
|
|
1124
1125
|
text += emitParamGroupCheck(partialBodyParam);
|
|
1125
|
-
text += `\t\tbody.${capitalize(partialBodyParam.serializedName)} = options.${capitalize(partialBodyParam.name)}\n\t}\n`;
|
|
1126
|
+
text += `\t\tbody.${naming.capitalize(partialBodyParam.serializedName)} = options.${naming.capitalize(partialBodyParam.name)}\n\t}\n`;
|
|
1126
1127
|
}
|
|
1127
1128
|
}
|
|
1128
1129
|
// TODO: spread params are JSON only https://github.com/Azure/autorest.go/issues/1455
|
|
@@ -1184,10 +1185,10 @@ function createProtocolRequest(azureARM, method, imports) {
|
|
|
1184
1185
|
return text;
|
|
1185
1186
|
}
|
|
1186
1187
|
function emitClientSideDefault(param, csd, setterFormat, imports) {
|
|
1187
|
-
const defaultVar = uncapitalize(param.name) + 'Default';
|
|
1188
|
+
const defaultVar = naming.uncapitalize(param.name) + 'Default';
|
|
1188
1189
|
let text = `\t${defaultVar} := ${helpers.formatLiteralValue(csd.defaultValue, true)}\n`;
|
|
1189
|
-
text += `\tif options != nil && options.${capitalize(param.name)} != nil {\n`;
|
|
1190
|
-
text += `\t\t${defaultVar} = *options.${capitalize(param.name)}\n`;
|
|
1190
|
+
text += `\tif options != nil && options.${naming.capitalize(param.name)} != nil {\n`;
|
|
1191
|
+
text += `\t\t${defaultVar} = *options.${naming.capitalize(param.name)}\n`;
|
|
1191
1192
|
text += '}\n';
|
|
1192
1193
|
let serializedName;
|
|
1193
1194
|
switch (param.kind) {
|
|
@@ -1220,16 +1221,16 @@ function isArrayOfDateTimeForMarshalling(paramType) {
|
|
|
1220
1221
|
return undefined;
|
|
1221
1222
|
}
|
|
1222
1223
|
switch (paramType.elementType.format) {
|
|
1223
|
-
case '
|
|
1224
|
-
case '
|
|
1225
|
-
case '
|
|
1226
|
-
case '
|
|
1224
|
+
case 'PlainDate':
|
|
1225
|
+
case 'RFC1123':
|
|
1226
|
+
case 'PlainTime':
|
|
1227
|
+
case 'Unix':
|
|
1227
1228
|
return {
|
|
1228
1229
|
format: paramType.elementType.format,
|
|
1229
1230
|
elemByVal: paramType.elementTypeByValue
|
|
1230
1231
|
};
|
|
1231
1232
|
default:
|
|
1232
|
-
//
|
|
1233
|
+
// RFC3339 uses the default marshaller
|
|
1233
1234
|
return undefined;
|
|
1234
1235
|
}
|
|
1235
1236
|
}
|
|
@@ -1238,12 +1239,13 @@ function isArrayOfDateTimeForMarshalling(paramType) {
|
|
|
1238
1239
|
function needsResponseHandler(method) {
|
|
1239
1240
|
return helpers.hasSchemaResponse(method) || method.returns.headers.length > 0;
|
|
1240
1241
|
}
|
|
1241
|
-
function generateResponseUnmarshaller(method, type, format, unmarshalTarget) {
|
|
1242
|
+
function generateResponseUnmarshaller(method, type, format, unmarshalTarget, imports) {
|
|
1242
1243
|
let unmarshallerText = '';
|
|
1243
1244
|
const zeroValue = getZeroReturnValue(method, 'handler');
|
|
1244
1245
|
if (type.kind === 'time') {
|
|
1245
1246
|
// use the designated time type for unmarshalling
|
|
1246
|
-
|
|
1247
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1248
|
+
unmarshallerText += `\tvar aux *datetime.${type.format}\n`;
|
|
1247
1249
|
unmarshallerText += `\tif err := runtime.UnmarshalAs${format}(resp, &aux); err != nil {\n`;
|
|
1248
1250
|
unmarshallerText += `\t\treturn ${zeroValue}, err\n`;
|
|
1249
1251
|
unmarshallerText += '\t}\n';
|
|
@@ -1257,7 +1259,8 @@ function generateResponseUnmarshaller(method, type, format, unmarshalTarget) {
|
|
|
1257
1259
|
if (timeInfo?.elemByVal) {
|
|
1258
1260
|
elementPtr = '';
|
|
1259
1261
|
}
|
|
1260
|
-
|
|
1262
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1263
|
+
unmarshallerText += `\tvar aux []${elementPtr}datetime.${timeInfo?.format}\n`;
|
|
1261
1264
|
unmarshallerText += `\tif err := runtime.UnmarshalAs${format}(resp, &aux); err != nil {\n`;
|
|
1262
1265
|
unmarshallerText += `\t\treturn ${zeroValue}, err\n`;
|
|
1263
1266
|
unmarshallerText += '\t}\n';
|
|
@@ -1269,7 +1272,9 @@ function generateResponseUnmarshaller(method, type, format, unmarshalTarget) {
|
|
|
1269
1272
|
return unmarshallerText;
|
|
1270
1273
|
}
|
|
1271
1274
|
else if (isMapOfDateTime(type)) {
|
|
1272
|
-
|
|
1275
|
+
let timeType = isMapOfDateTime(type);
|
|
1276
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
1277
|
+
unmarshallerText += `\taux := map[string]*datetime.${timeType}{}\n`;
|
|
1273
1278
|
unmarshallerText += `\tif err := runtime.UnmarshalAs${format}(resp, &aux); err != nil {\n`;
|
|
1274
1279
|
unmarshallerText += `\t\treturn ${zeroValue}, err\n`;
|
|
1275
1280
|
unmarshallerText += '\t}\n';
|
|
@@ -1313,10 +1318,10 @@ function createProtocolResponse(method, imports) {
|
|
|
1313
1318
|
return '';
|
|
1314
1319
|
}
|
|
1315
1320
|
const name = method.naming.responseMethod;
|
|
1316
|
-
let text = `${comment(name, '// ')} handles the ${method.name} response.\n`;
|
|
1321
|
+
let text = `${helpers.comment(name, '// ')} handles the ${method.name} response.\n`;
|
|
1317
1322
|
text += `func ${getClientReceiverDefinition(method.receiver)} ${name}(resp *http.Response) (${generateReturnsInfo(method, 'handler').join(', ')}) {\n`;
|
|
1318
1323
|
const addHeaders = function (headers) {
|
|
1319
|
-
for (const header of
|
|
1324
|
+
for (const header of headers) {
|
|
1320
1325
|
text += formatHeaderResponseValue(header, imports, 'result', `${method.returns.name}{}`);
|
|
1321
1326
|
}
|
|
1322
1327
|
};
|
|
@@ -1341,7 +1346,7 @@ function createProtocolResponse(method, imports) {
|
|
|
1341
1346
|
continue;
|
|
1342
1347
|
}
|
|
1343
1348
|
text += `\tvar val ${go.getTypeDeclaration(resultType, method.receiver.type.pkg)}\n`;
|
|
1344
|
-
text += generateResponseUnmarshaller(method, resultType, result.format, 'val');
|
|
1349
|
+
text += generateResponseUnmarshaller(method, resultType, result.format, 'val', imports);
|
|
1345
1350
|
text += '\tresult.Value = val\n';
|
|
1346
1351
|
}
|
|
1347
1352
|
text += '\tdefault:\n';
|
|
@@ -1359,7 +1364,7 @@ function createProtocolResponse(method, imports) {
|
|
|
1359
1364
|
case 'modelResult':
|
|
1360
1365
|
text += `\tresult := ${method.returns.name}{}\n`;
|
|
1361
1366
|
addHeaders(method.returns.headers);
|
|
1362
|
-
text += generateResponseUnmarshaller(method, result.modelType, result.format, `result.${helpers.getResultFieldName(method)}
|
|
1367
|
+
text += generateResponseUnmarshaller(method, result.modelType, result.format, `result.${helpers.getResultFieldName(method)}`, imports);
|
|
1363
1368
|
break;
|
|
1364
1369
|
case 'monomorphicResult':
|
|
1365
1370
|
text += `\tresult := ${method.returns.name}{}\n`;
|
|
@@ -1369,12 +1374,12 @@ function createProtocolResponse(method, imports) {
|
|
|
1369
1374
|
if (result.format === 'XML' && result.monomorphicType.kind === 'slice') {
|
|
1370
1375
|
target = 'result';
|
|
1371
1376
|
}
|
|
1372
|
-
text += generateResponseUnmarshaller(method, result.monomorphicType, result.format, target);
|
|
1377
|
+
text += generateResponseUnmarshaller(method, result.monomorphicType, result.format, target, imports);
|
|
1373
1378
|
break;
|
|
1374
1379
|
case 'polymorphicResult':
|
|
1375
1380
|
text += `\tresult := ${method.returns.name}{}\n`;
|
|
1376
1381
|
addHeaders(method.returns.headers);
|
|
1377
|
-
text += generateResponseUnmarshaller(method, result.interface, result.format, 'result');
|
|
1382
|
+
text += generateResponseUnmarshaller(method, result.interface, result.format, 'result', imports);
|
|
1378
1383
|
break;
|
|
1379
1384
|
default:
|
|
1380
1385
|
result;
|
|
@@ -1429,11 +1434,11 @@ function getAPIParametersSig(method, imports) {
|
|
|
1429
1434
|
imports.add('context');
|
|
1430
1435
|
params.push('ctx context.Context');
|
|
1431
1436
|
}
|
|
1432
|
-
for (const methodParam of
|
|
1437
|
+
for (const methodParam of methodParams) {
|
|
1433
1438
|
if (methodParam.kind !== 'paramGroup') {
|
|
1434
1439
|
imports.addForType(methodParam.type);
|
|
1435
1440
|
}
|
|
1436
|
-
params.push(`${uncapitalize(methodParam.name)} ${helpers.formatParameterTypeName(method.receiver.type.pkg, methodParam)}`);
|
|
1441
|
+
params.push(`${naming.uncapitalize(methodParam.name)} ${helpers.formatParameterTypeName(method.receiver.type.pkg, methodParam)}`);
|
|
1437
1442
|
}
|
|
1438
1443
|
}
|
|
1439
1444
|
return params.join(', ');
|
|
@@ -1492,7 +1497,7 @@ function generateLROBeginMethod(method, imports, options) {
|
|
|
1492
1497
|
}
|
|
1493
1498
|
const zeroResp = getZeroReturnValue(method, 'api');
|
|
1494
1499
|
const methodParams = helpers.getMethodParameters(method);
|
|
1495
|
-
for (const param of
|
|
1500
|
+
for (const param of methodParams) {
|
|
1496
1501
|
text += helpers.formatCommentAsBulletItem(param.name, param.docs);
|
|
1497
1502
|
}
|
|
1498
1503
|
text += `func ${getClientReceiverDefinition(method.receiver)} ${fixUpMethodName(method)}(${params}) (${returns.join(', ')}) {\n`;
|