@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
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
|
-
import { camelCase, capitalize, uncapitalize } from '@azure-tools/codegen';
|
|
6
|
-
import { values } from '@azure-tools/linq';
|
|
7
5
|
import * as go from '../../../codemodel.go/src/index.js';
|
|
6
|
+
import * as naming from '../../../naming.go/src/naming.js';
|
|
8
7
|
import * as helpers from '../core/helpers.js';
|
|
9
8
|
import { ImportManager } from '../core/imports.js';
|
|
10
9
|
import { fixUpMethodName } from '../core/operations.js';
|
|
@@ -32,7 +31,7 @@ export class OperationGroupContent {
|
|
|
32
31
|
const requiredHelpers = new RequiredHelpers();
|
|
33
32
|
export function getServerName(client) {
|
|
34
33
|
// for the fake server, we use the suffix Server instead of Client
|
|
35
|
-
return capitalize(client.name.replace(/[C|c]lient$/, 'Server'));
|
|
34
|
+
return naming.capitalize(client.name.replace(/[C|c]lient$/, 'Server'));
|
|
36
35
|
}
|
|
37
36
|
/**
|
|
38
37
|
* Generates the contents for the *_server.go files.
|
|
@@ -42,8 +41,8 @@ export function getServerName(client) {
|
|
|
42
41
|
*/
|
|
43
42
|
export function generateServers(pkg) {
|
|
44
43
|
const operations = new Array();
|
|
45
|
-
for (const client of
|
|
46
|
-
if (client.clientAccessors.length === 0 &&
|
|
44
|
+
for (const client of pkg.parent.clients) {
|
|
45
|
+
if (client.clientAccessors.length === 0 && helpers.clientHasNoExportedMethods(client)) {
|
|
47
46
|
// client has no client accessors and no exported methods, skip it
|
|
48
47
|
continue;
|
|
49
48
|
}
|
|
@@ -66,7 +65,7 @@ export function generateServers(pkg) {
|
|
|
66
65
|
// we might remove some clients from the list
|
|
67
66
|
const finalSubClients = new Array();
|
|
68
67
|
for (const clientAccessor of client.clientAccessors) {
|
|
69
|
-
if (
|
|
68
|
+
if (helpers.clientHasNoExportedMethods(clientAccessor.returns)) {
|
|
70
69
|
// client has no exported methods, skip it
|
|
71
70
|
continue;
|
|
72
71
|
}
|
|
@@ -75,7 +74,7 @@ export function generateServers(pkg) {
|
|
|
75
74
|
content += `\t${serverName} ${serverName}\n\n`;
|
|
76
75
|
finalSubClients.push(clientAccessor.returns);
|
|
77
76
|
}
|
|
78
|
-
for (const method of
|
|
77
|
+
for (const method of client.methods) {
|
|
79
78
|
if (helpers.isMethodInternal(method)) {
|
|
80
79
|
// method isn't exported, don't create a fake for it
|
|
81
80
|
continue;
|
|
@@ -145,7 +144,7 @@ export function generateServers(pkg) {
|
|
|
145
144
|
}
|
|
146
145
|
else {
|
|
147
146
|
content += `\treturn &${serverTransport}{\n\t\tsrv: srv,\n`;
|
|
148
|
-
for (const method of
|
|
147
|
+
for (const method of finalMethods) {
|
|
149
148
|
let respType = go.getTypeDeclaration(method.returns, pkg);
|
|
150
149
|
switch (method.kind) {
|
|
151
150
|
case 'lroMethod':
|
|
@@ -154,11 +153,11 @@ export function generateServers(pkg) {
|
|
|
154
153
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
155
154
|
}
|
|
156
155
|
requiredHelpers.tracker = true;
|
|
157
|
-
content += `\t\t${uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PollerResponder[${respType}]](),\n`;
|
|
156
|
+
content += `\t\t${naming.uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PollerResponder[${respType}]](),\n`;
|
|
158
157
|
break;
|
|
159
158
|
case 'pageableMethod':
|
|
160
159
|
requiredHelpers.tracker = true;
|
|
161
|
-
content += `\t\t${uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PagerResponder[${respType}]](),\n`;
|
|
160
|
+
content += `\t\t${naming.uncapitalize(fixUpMethodName(method))}: newTracker[azfake.PagerResponder[${respType}]](),\n`;
|
|
162
161
|
break;
|
|
163
162
|
}
|
|
164
163
|
}
|
|
@@ -178,7 +177,7 @@ export function generateServers(pkg) {
|
|
|
178
177
|
content += `\ttr${serverName} *${serverName}Transport\n`;
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
|
-
for (const method of
|
|
180
|
+
for (const method of finalMethods) {
|
|
182
181
|
// create state machines for any pager/poller operations
|
|
183
182
|
let respType = go.getTypeDeclaration(method.returns, pkg);
|
|
184
183
|
switch (method.kind) {
|
|
@@ -188,11 +187,11 @@ export function generateServers(pkg) {
|
|
|
188
187
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
189
188
|
}
|
|
190
189
|
requiredHelpers.tracker = true;
|
|
191
|
-
content += `\t${uncapitalize(fixUpMethodName(method))} *tracker[azfake.PollerResponder[${respType}]]\n`;
|
|
190
|
+
content += `\t${naming.uncapitalize(fixUpMethodName(method))} *tracker[azfake.PollerResponder[${respType}]]\n`;
|
|
192
191
|
break;
|
|
193
192
|
case 'pageableMethod':
|
|
194
193
|
requiredHelpers.tracker = true;
|
|
195
|
-
content += `\t${uncapitalize(fixUpMethodName(method))} *tracker[azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]]\n`;
|
|
194
|
+
content += `\t${naming.uncapitalize(fixUpMethodName(method))} *tracker[azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]]\n`;
|
|
196
195
|
break;
|
|
197
196
|
}
|
|
198
197
|
}
|
|
@@ -215,7 +214,7 @@ export function generateServers(pkg) {
|
|
|
215
214
|
return new ServerContent(operations, generateServerInternal(pkg, requiredHelpers));
|
|
216
215
|
}
|
|
217
216
|
function getTransportInterceptorVarName(client) {
|
|
218
|
-
return `${camelCase(getServerName(client))}TransportInterceptor`;
|
|
217
|
+
return `${helpers.camelCase(getServerName(client))}TransportInterceptor`;
|
|
219
218
|
}
|
|
220
219
|
// method names for fakes dispatching
|
|
221
220
|
const dispatchMethodFake = 'dispatchToMethodFake';
|
|
@@ -278,7 +277,7 @@ function generateServerTransportMethodDispatch(serverTransport, client, finalMet
|
|
|
278
277
|
content += `\t\t\t res.resp, res.err, intercepted = ${interceptorVarName}.Do(req)\n\t\t}\n`;
|
|
279
278
|
content += '\t\tif !intercepted {\n';
|
|
280
279
|
content += '\t\t\tswitch method {\n';
|
|
281
|
-
for (const method of
|
|
280
|
+
for (const method of finalMethods) {
|
|
282
281
|
const operationName = fixUpMethodName(method);
|
|
283
282
|
content += `\t\t\tcase "${client.name}.${operationName}":\n`;
|
|
284
283
|
content += `\t\t\t\tres.resp, res.err = ${receiverName}.dispatch${operationName}(req)\n`;
|
|
@@ -317,7 +316,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
317
316
|
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/fake/server');
|
|
318
317
|
const receiverName = serverTransport[0].toLowerCase();
|
|
319
318
|
let content = '';
|
|
320
|
-
for (const method of
|
|
319
|
+
for (const method of finalMethods) {
|
|
321
320
|
content += `func (${receiverName} *${serverTransport}) dispatch${fixUpMethodName(method)}(req *http.Request) (*http.Response, error) {\n`;
|
|
322
321
|
content += `\tif ${receiverName}.srv.${fixUpMethodName(method)} == nil {\n`;
|
|
323
322
|
content += `\t\treturn nil, &nonRetriableError{errors.New("fake for method ${fixUpMethodName(method)} not implemented")}\n\t}\n`;
|
|
@@ -365,7 +364,8 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
365
364
|
}
|
|
366
365
|
let responseField = `server.GetResponse(respr)${respField}`;
|
|
367
366
|
if (method.returns.result.monomorphicType.kind === 'time') {
|
|
368
|
-
|
|
367
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
368
|
+
responseField = `(*datetime.${method.returns.result.monomorphicType.format})(${responseField})`;
|
|
369
369
|
}
|
|
370
370
|
content += `\tresp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, ${responseField}, req)\n`;
|
|
371
371
|
}
|
|
@@ -377,7 +377,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
377
377
|
}
|
|
378
378
|
content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
|
|
379
379
|
// propagate any header response values into the *http.Response
|
|
380
|
-
for (const header of
|
|
380
|
+
for (const header of method.returns.headers) {
|
|
381
381
|
if (header.kind === 'headerMapResponse') {
|
|
382
382
|
content += `\tfor k, v := range server.GetResponse(respr).${header.fieldName} {\n`;
|
|
383
383
|
content += '\t\tif v != nil {\n';
|
|
@@ -415,7 +415,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
415
415
|
*/
|
|
416
416
|
function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
417
417
|
const methodParamGroups = helpers.getMethodParamGroups(method);
|
|
418
|
-
const numPathParams =
|
|
418
|
+
const numPathParams = methodParamGroups.pathParams.filter((each) => !go.isLiteralParameter(each.style)).length;
|
|
419
419
|
let content = '';
|
|
420
420
|
if (numPathParams > 0) {
|
|
421
421
|
imports.add('regexp');
|
|
@@ -428,7 +428,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
428
428
|
content += '\t\treturn nil, fmt.Errorf("failed to parse path %s", req.URL.Path)\n\t}\n';
|
|
429
429
|
}
|
|
430
430
|
const allQueryParams = methodParamGroups.encodedQueryParams.concat(methodParamGroups.unencodedQueryParams);
|
|
431
|
-
if (
|
|
431
|
+
if (allQueryParams.find((each) => each.location === 'method' && !go.isLiteralParameter(each.style))) {
|
|
432
432
|
content += '\tqp := req.URL.Query()\n';
|
|
433
433
|
}
|
|
434
434
|
// note that these are mutually exclusive
|
|
@@ -463,7 +463,8 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
463
463
|
default: {
|
|
464
464
|
let bodyTypeName = go.getTypeDeclaration(bodyParam.type, pkg);
|
|
465
465
|
if (bodyParam.type.kind === 'time') {
|
|
466
|
-
|
|
466
|
+
imports.add('github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime');
|
|
467
|
+
bodyTypeName = `datetime.${bodyParam.type.format}`;
|
|
467
468
|
}
|
|
468
469
|
content += `\tbody, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
|
|
469
470
|
content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
|
|
@@ -670,7 +671,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
670
671
|
// construct the partial body params type and unmarshal it
|
|
671
672
|
content += '\ttype partialBodyParams struct {\n';
|
|
672
673
|
for (const partialBodyParam of partialBodyParams) {
|
|
673
|
-
content += `\t\t${capitalize(partialBodyParam.name)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
|
|
674
|
+
content += `\t\t${naming.capitalize(partialBodyParam.name)} ${helpers.star(partialBodyParam.byValue)}${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
|
|
674
675
|
}
|
|
675
676
|
content += '\t}\n';
|
|
676
677
|
content += `\tbody, err := server.UnmarshalRequestAs${partialBodyParams[0].format}[partialBodyParams](req)\n`;
|
|
@@ -680,7 +681,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports) {
|
|
|
680
681
|
content += result.content;
|
|
681
682
|
// translate each partial body param to its field within the unmarshalled body
|
|
682
683
|
for (const partialBodyParam of partialBodyParams) {
|
|
683
|
-
result.params.set(partialBodyParam.name, `${helpers.star(partialBodyParam.byValue)}body.${capitalize(partialBodyParam.name)}`);
|
|
684
|
+
result.params.set(partialBodyParam.name, `${helpers.star(partialBodyParam.byValue)}body.${naming.capitalize(partialBodyParam.name)}`);
|
|
684
685
|
}
|
|
685
686
|
const apiCall = `:= ${receiverName}.srv.${fixUpMethodName(method)}(${populateApiParams(pkg, method, result.params, imports)})`;
|
|
686
687
|
if (method.kind === 'pageableMethod') {
|
|
@@ -721,8 +722,8 @@ function getMethodStatusCodes(method) {
|
|
|
721
722
|
*/
|
|
722
723
|
function dispatchForLROBody(pkg, receiverName, method, imports) {
|
|
723
724
|
const operationName = fixUpMethodName(method);
|
|
724
|
-
const localVarName = uncapitalize(operationName);
|
|
725
|
-
const operationStateMachine = `${receiverName}.${uncapitalize(operationName)}`;
|
|
725
|
+
const localVarName = naming.uncapitalize(operationName);
|
|
726
|
+
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
726
727
|
let content = `\t${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
727
728
|
content += `\tif ${localVarName} == nil {\n`;
|
|
728
729
|
content += dispatchForOperationBody(pkg, receiverName, method, imports);
|
|
@@ -751,8 +752,8 @@ function dispatchForLROBody(pkg, receiverName, method, imports) {
|
|
|
751
752
|
*/
|
|
752
753
|
function dispatchForPagerBody(pkg, receiverName, method, imports) {
|
|
753
754
|
const operationName = fixUpMethodName(method);
|
|
754
|
-
const localVarName = uncapitalize(operationName);
|
|
755
|
-
const operationStateMachine = `${receiverName}.${uncapitalize(operationName)}`;
|
|
755
|
+
const localVarName = naming.uncapitalize(operationName);
|
|
756
|
+
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
756
757
|
let content = `\t${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
757
758
|
content += `\tif ${localVarName} == nil {\n`;
|
|
758
759
|
content += dispatchForOperationBody(pkg, receiverName, method, imports);
|
|
@@ -811,7 +812,7 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
811
812
|
let content = '';
|
|
812
813
|
const paramValues = new Map();
|
|
813
814
|
const createLocalVariableName = function (param, suffix) {
|
|
814
|
-
const paramName = `${uncapitalize(param.name)}${suffix}`;
|
|
815
|
+
const paramName = `${naming.uncapitalize(param.name)}${suffix}`;
|
|
815
816
|
paramValues.set(param.name, paramName);
|
|
816
817
|
return paramName;
|
|
817
818
|
};
|
|
@@ -832,7 +833,7 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
832
833
|
// track the param groups that need to be instantiated/populated.
|
|
833
834
|
// we track the params separately as it might be a subset of ParameterGroup.params
|
|
834
835
|
const paramGroups = new Map();
|
|
835
|
-
for (const param of
|
|
836
|
+
for (const param of consolidateHostParams(method.parameters)) {
|
|
836
837
|
if (param.location === 'client' || go.isLiteralParameter(param.style)) {
|
|
837
838
|
// client params and parameter literals aren't passed to APIs
|
|
838
839
|
continue;
|
|
@@ -956,7 +957,7 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
956
957
|
content += '\t\tif parseErr != nil {\n\t\t\treturn nil, parseErr\n\t\t}\n';
|
|
957
958
|
}
|
|
958
959
|
else if (elementFormat === 'float32' || elementFormat === 'float64' || elementFormat === 'int32' || elementFormat === 'int64') {
|
|
959
|
-
fromVar = `parsed${capitalize(elementFormat)}`;
|
|
960
|
+
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
960
961
|
content += `\t\t${fromVar}, parseErr := ${emitNumericConversion(`${paramValue}[i]`, elementFormat)}\n`;
|
|
961
962
|
content += '\t\tif parseErr != nil {\n\t\t\treturn nil, parseErr\n\t\t}\n';
|
|
962
963
|
}
|
|
@@ -967,14 +968,14 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
967
968
|
}
|
|
968
969
|
else if (elementFormat === 'Std' || elementFormat === 'URL') {
|
|
969
970
|
imports.add('encoding/base64');
|
|
970
|
-
fromVar = `parsed${capitalize(elementFormat)}`;
|
|
971
|
+
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
971
972
|
content += `\t\t${fromVar}, parseErr := base64.${elementFormat}Encoding.DecodeString(${paramValue}[i])\n`;
|
|
972
973
|
content += '\t\tif parseErr != nil {\n\t\t\treturn nil, parseErr\n\t\t}\n';
|
|
973
974
|
}
|
|
974
|
-
else if (elementFormat === '
|
|
975
|
+
else if (elementFormat === 'RFC1123' || elementFormat === 'RFC3339' || elementFormat === 'Unix') {
|
|
975
976
|
imports.add('time');
|
|
976
|
-
fromVar = `parsed${capitalize(elementFormat)}`;
|
|
977
|
-
if (elementFormat === '
|
|
977
|
+
fromVar = `parsed${naming.capitalize(elementFormat)}`;
|
|
978
|
+
if (elementFormat === 'Unix') {
|
|
978
979
|
imports.add('strconv');
|
|
979
980
|
content += `\t\tp, parseErr := strconv.ParseInt(${paramValue}[i], 10, 64)\n`;
|
|
980
981
|
content += '\t\tif parseErr != nil {\n\t\t\treturn nil, parseErr\n\t\t}\n';
|
|
@@ -982,7 +983,7 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
982
983
|
}
|
|
983
984
|
else {
|
|
984
985
|
let format = 'time.RFC3339Nano';
|
|
985
|
-
if (elementFormat === '
|
|
986
|
+
if (elementFormat === 'RFC1123') {
|
|
986
987
|
format = 'time.RFC1123';
|
|
987
988
|
}
|
|
988
989
|
content += `\t\t${fromVar}, parseErr := time.Parse(${format}, ${paramValue}[i])\n`;
|
|
@@ -1019,26 +1020,15 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1019
1020
|
content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
|
|
1020
1021
|
}
|
|
1021
1022
|
else if (param.type.kind === 'time') {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
from = `parseOptional(${paramValue}, func(v string) (time.Time, error) { return time.Parse("${format}", v) })`;
|
|
1032
|
-
}
|
|
1033
|
-
content += `\t${createLocalVariableName(param, 'Param')}, err := ${from}\n`;
|
|
1034
|
-
content += '\tif err != nil {\n\t\treturn nil, err\n\t}\n';
|
|
1035
|
-
}
|
|
1036
|
-
else if (param.type.format === 'dateTimeRFC1123' || param.type.format === 'dateTimeRFC3339') {
|
|
1037
|
-
imports.add('time');
|
|
1038
|
-
let format = 'time.RFC3339Nano';
|
|
1039
|
-
if (param.type.format === 'dateTimeRFC1123') {
|
|
1040
|
-
format = 'time.RFC1123';
|
|
1041
|
-
}
|
|
1023
|
+
const formatMap = {
|
|
1024
|
+
'PlainDate': helpers.plainDateFormat,
|
|
1025
|
+
'PlainTime': helpers.plainTimeFormat,
|
|
1026
|
+
'RFC1123': helpers.RFC1123Format,
|
|
1027
|
+
'RFC3339': helpers.RFC3339Format,
|
|
1028
|
+
};
|
|
1029
|
+
imports.add('time');
|
|
1030
|
+
if (param.type.format in formatMap) {
|
|
1031
|
+
const format = formatMap[param.type.format];
|
|
1042
1032
|
let from = `time.Parse(${format}, ${paramValue})`;
|
|
1043
1033
|
if (!go.isRequiredParameter(param.style)) {
|
|
1044
1034
|
requiredHelpers.parseOptional = true;
|
|
@@ -1142,49 +1132,56 @@ function parseHeaderPathQueryParams(pkg, method, imports) {
|
|
|
1142
1132
|
}
|
|
1143
1133
|
}
|
|
1144
1134
|
// create the param groups and populate their values
|
|
1145
|
-
for (const paramGroup of
|
|
1135
|
+
for (const paramGroup of paramGroups.keys()) {
|
|
1146
1136
|
if (paramGroup.required) {
|
|
1147
|
-
content += `\t${uncapitalize(paramGroup.name)} := ${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1148
|
-
|
|
1149
|
-
|
|
1137
|
+
content += `\t${naming.uncapitalize(paramGroup.name)} := ${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1138
|
+
const params = paramGroups.get(paramGroup);
|
|
1139
|
+
if (params) {
|
|
1140
|
+
for (const param of params) {
|
|
1141
|
+
content += `\t\t${naming.capitalize(param.name)}: ${getFinalParamValue(pkg, param, paramValues)},\n`;
|
|
1142
|
+
}
|
|
1150
1143
|
}
|
|
1151
1144
|
content += '\t}\n';
|
|
1152
1145
|
}
|
|
1153
1146
|
else {
|
|
1154
|
-
content += `\tvar ${uncapitalize(paramGroup.name)} *${go.getTypeDeclaration(paramGroup, pkg)}\n`;
|
|
1147
|
+
content += `\tvar ${naming.uncapitalize(paramGroup.name)} *${go.getTypeDeclaration(paramGroup, pkg)}\n`;
|
|
1155
1148
|
const params = paramGroups.get(paramGroup);
|
|
1156
1149
|
const paramNilCheck = new Array();
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
else if (param.kind === 'bodyParam') {
|
|
1163
|
-
if (param.bodyFormat === 'binary') {
|
|
1164
|
-
imports.add('io');
|
|
1165
|
-
paramNilCheck.push('req.Body != nil');
|
|
1150
|
+
if (params) {
|
|
1151
|
+
for (const param of params) {
|
|
1152
|
+
// check array before body in case the body is just an array
|
|
1153
|
+
if (param.type.kind === 'slice') {
|
|
1154
|
+
paramNilCheck.push(`len(${getFinalParamValue(pkg, param, paramValues)}) > 0`);
|
|
1166
1155
|
}
|
|
1167
|
-
else {
|
|
1156
|
+
else if (param.kind === 'bodyParam') {
|
|
1157
|
+
if (param.bodyFormat === 'binary') {
|
|
1158
|
+
imports.add('io');
|
|
1159
|
+
paramNilCheck.push('req.Body != nil');
|
|
1160
|
+
}
|
|
1161
|
+
else {
|
|
1162
|
+
imports.add('reflect');
|
|
1163
|
+
paramNilCheck.push('!reflect.ValueOf(body).IsZero()');
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
else if (go.isFormBodyParameter(param) || param.kind === 'multipartFormBodyParam') {
|
|
1168
1167
|
imports.add('reflect');
|
|
1169
|
-
paramNilCheck.push(
|
|
1168
|
+
paramNilCheck.push(`!reflect.ValueOf(${param.name}).IsZero()`);
|
|
1169
|
+
}
|
|
1170
|
+
else {
|
|
1171
|
+
paramNilCheck.push(`${getFinalParamValue(pkg, param, paramValues)} != nil`);
|
|
1170
1172
|
}
|
|
1171
|
-
}
|
|
1172
|
-
else if (go.isFormBodyParameter(param) || param.kind === 'multipartFormBodyParam') {
|
|
1173
|
-
imports.add('reflect');
|
|
1174
|
-
paramNilCheck.push(`!reflect.ValueOf(${param.name}).IsZero()`);
|
|
1175
|
-
}
|
|
1176
|
-
else {
|
|
1177
|
-
paramNilCheck.push(`${getFinalParamValue(pkg, param, paramValues)} != nil`);
|
|
1178
1173
|
}
|
|
1179
1174
|
}
|
|
1180
1175
|
content += `\tif ${paramNilCheck.join(' || ')} {\n`;
|
|
1181
|
-
content += `\t\t${uncapitalize(paramGroup.name)} = &${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1176
|
+
content += `\t\t${naming.uncapitalize(paramGroup.name)} = &${go.getTypeDeclaration(paramGroup, pkg)}{\n`;
|
|
1177
|
+
if (params) {
|
|
1178
|
+
for (const param of params) {
|
|
1179
|
+
let byRef = '&';
|
|
1180
|
+
if (param.byValue || (!go.isRequiredParameter(param.style) && param.kind !== 'bodyParam' && !go.isFormBodyParameter(param) && param.kind !== 'multipartFormBodyParam')) {
|
|
1181
|
+
byRef = '';
|
|
1182
|
+
}
|
|
1183
|
+
content += `\t\t\t${naming.capitalize(param.name)}: ${byRef}${getFinalParamValue(pkg, param, paramValues)},\n`;
|
|
1186
1184
|
}
|
|
1187
|
-
content += `\t\t\t${capitalize(param.name)}: ${byRef}${getFinalParamValue(pkg, param, paramValues)},\n`;
|
|
1188
1185
|
}
|
|
1189
1186
|
content += '\t\t}\n';
|
|
1190
1187
|
content += '\t}\n';
|
|
@@ -1214,11 +1211,11 @@ function populateApiParams(pkg, method, paramValues, imports) {
|
|
|
1214
1211
|
params.push('req.Context()');
|
|
1215
1212
|
}
|
|
1216
1213
|
// now create the API call sig
|
|
1217
|
-
for (const param of
|
|
1214
|
+
for (const param of helpers.getMethodParameters(method, consolidateHostParams)) {
|
|
1218
1215
|
if (param.kind === 'paramGroup') {
|
|
1219
1216
|
if (param.groupName === method.optionalParamsGroup.groupName) {
|
|
1220
1217
|
// this is the optional params type. in some cases we just pass nil
|
|
1221
|
-
const countParams =
|
|
1218
|
+
const countParams = param.params.filter((each) => each.kind !== 'resumeTokenParam').length;
|
|
1222
1219
|
if (countParams === 0) {
|
|
1223
1220
|
// if the options param is empty or only contains the resume token param just pass nil
|
|
1224
1221
|
params.push('nil');
|
|
@@ -1227,7 +1224,7 @@ function populateApiParams(pkg, method, paramValues, imports) {
|
|
|
1227
1224
|
}
|
|
1228
1225
|
// by convention, for param groups, the param parsing code
|
|
1229
1226
|
// creates a local var with the name of the param
|
|
1230
|
-
params.push(uncapitalize(param.name));
|
|
1227
|
+
params.push(naming.uncapitalize(param.name));
|
|
1231
1228
|
continue;
|
|
1232
1229
|
}
|
|
1233
1230
|
imports.addForType(param.type);
|
|
@@ -1314,7 +1311,7 @@ function getFinalParamValue(pkg, param, paramValues) {
|
|
|
1314
1311
|
}
|
|
1315
1312
|
else if (param.kind === 'partialBodyParam') {
|
|
1316
1313
|
// use the value from the unmarshaled, intermediate struct type
|
|
1317
|
-
return `body.${capitalize(param.name)}`;
|
|
1314
|
+
return `body.${naming.capitalize(param.name)}`;
|
|
1318
1315
|
}
|
|
1319
1316
|
return paramValue;
|
|
1320
1317
|
}
|
|
@@ -1324,14 +1321,14 @@ function getFinalParamValue(pkg, param, paramValues) {
|
|
|
1324
1321
|
// there's no way to reliably split the host back up into its constituent parameters.
|
|
1325
1322
|
// so we just pass the full value as a single host parameter.
|
|
1326
1323
|
function consolidateHostParams(params) {
|
|
1327
|
-
if (!
|
|
1324
|
+
if (!params.find((each) => each.kind === 'uriParam')) {
|
|
1328
1325
|
// no host params
|
|
1329
1326
|
return params;
|
|
1330
1327
|
}
|
|
1331
1328
|
// consolidate multiple host params into a single "host" param
|
|
1332
1329
|
const consolidatedParams = new Array();
|
|
1333
1330
|
let hostParamAdded = false;
|
|
1334
|
-
for (const param of
|
|
1331
|
+
for (const param of params) {
|
|
1335
1332
|
if (param.kind !== 'uriParam') {
|
|
1336
1333
|
consolidatedParams.push(param);
|
|
1337
1334
|
}
|
|
@@ -1357,8 +1354,8 @@ function getAPIParametersSig(pkg, method, imports) {
|
|
|
1357
1354
|
imports.add('context');
|
|
1358
1355
|
params.push('ctx context.Context');
|
|
1359
1356
|
}
|
|
1360
|
-
for (const methodParam of
|
|
1361
|
-
let paramName = uncapitalize(methodParam.name);
|
|
1357
|
+
for (const methodParam of methodParams) {
|
|
1358
|
+
let paramName = naming.uncapitalize(methodParam.name);
|
|
1362
1359
|
if (methodParam.kind === 'uriParam') {
|
|
1363
1360
|
paramName = 'host';
|
|
1364
1361
|
}
|