@azure-tools/typespec-go 0.17.4-dev.6 → 0.17.5-dev.10
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/CHANGELOG.md +8 -0
- package/dist/src/codegen/core/example.js +20 -20
- package/dist/src/codegen/core/example.js.map +1 -1
- package/dist/src/codegen/core/helpers.d.ts +3 -9
- package/dist/src/codegen/core/helpers.d.ts.map +1 -1
- package/dist/src/codegen/core/helpers.js +33 -74
- package/dist/src/codegen/core/helpers.js.map +1 -1
- package/dist/src/codegen/core/imports.d.ts.map +1 -1
- package/dist/src/codegen/core/imports.js +4 -3
- package/dist/src/codegen/core/imports.js.map +1 -1
- package/dist/src/codegen/core/models.d.ts.map +1 -1
- package/dist/src/codegen/core/models.js +193 -143
- package/dist/src/codegen/core/models.js.map +1 -1
- package/dist/src/codegen/core/operations.js +11 -17
- package/dist/src/codegen/core/operations.js.map +1 -1
- package/dist/src/codegen/core/options.js +1 -5
- package/dist/src/codegen/core/options.js.map +1 -1
- package/dist/src/codegen/core/polymorphics.d.ts.map +1 -1
- package/dist/src/codegen/core/polymorphics.js +3 -5
- package/dist/src/codegen/core/polymorphics.js.map +1 -1
- package/dist/src/codegen/core/request-handler.d.ts.map +1 -1
- package/dist/src/codegen/core/request-handler.js +29 -22
- package/dist/src/codegen/core/request-handler.js.map +1 -1
- package/dist/src/codegen/core/response-handler.js +17 -15
- package/dist/src/codegen/core/response-handler.js.map +1 -1
- package/dist/src/codegen/core/responses.js +8 -22
- package/dist/src/codegen/core/responses.js.map +1 -1
- package/dist/src/codegen/core/unions.js +21 -16
- package/dist/src/codegen/core/unions.js.map +1 -1
- package/dist/src/codegen/fake/servers.js +105 -98
- package/dist/src/codegen/fake/servers.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +8 -3
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js +3 -3
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/codemodel/method.d.ts +1 -3
- package/dist/src/codemodel/method.d.ts.map +1 -1
- package/dist/src/codemodel/method.js +1 -2
- package/dist/src/codemodel/method.js.map +1 -1
- package/dist/src/codemodel/param.d.ts +41 -29
- package/dist/src/codemodel/param.d.ts.map +1 -1
- package/dist/src/codemodel/param.js +33 -33
- package/dist/src/codemodel/param.js.map +1 -1
- package/dist/src/codemodel/result.d.ts +21 -15
- package/dist/src/codemodel/result.d.ts.map +1 -1
- package/dist/src/codemodel/result.js +8 -24
- package/dist/src/codemodel/result.js.map +1 -1
- package/dist/src/codemodel/type.d.ts +83 -54
- package/dist/src/codemodel/type.d.ts.map +1 -1
- package/dist/src/codemodel/type.js +68 -30
- package/dist/src/codemodel/type.js.map +1 -1
- package/dist/src/tcgcadapter/clients.d.ts +2 -1
- package/dist/src/tcgcadapter/clients.d.ts.map +1 -1
- package/dist/src/tcgcadapter/clients.js +99 -107
- package/dist/src/tcgcadapter/clients.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +8 -27
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +32 -87
- package/dist/src/tcgcadapter/helpers.js.map +1 -1
- package/dist/src/tcgcadapter/types.d.ts +5 -3
- package/dist/src/tcgcadapter/types.d.ts.map +1 -1
- package/dist/src/tcgcadapter/types.js +113 -45
- package/dist/src/tcgcadapter/types.js.map +1 -1
- package/package.json +40 -40
|
@@ -97,7 +97,7 @@ export function generateServers(pkg, target) {
|
|
|
97
97
|
serverResponse = `resp azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
98
98
|
break;
|
|
99
99
|
}
|
|
100
|
-
const operationName =
|
|
100
|
+
const operationName = method.name;
|
|
101
101
|
content += `${indent.get()}// ${operationName} is the fake for method ${client.name}.${operationName}\n`;
|
|
102
102
|
const successCodes = new Array();
|
|
103
103
|
if (method.returns.result?.kind === "anyResult") {
|
|
@@ -157,11 +157,11 @@ export function generateServers(pkg, target) {
|
|
|
157
157
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
158
158
|
}
|
|
159
159
|
requiredHelpers.tracker = true;
|
|
160
|
-
content += `${indent.get()}${naming.uncapitalize(
|
|
160
|
+
content += `${indent.get()}${naming.uncapitalize(method.name)}: newTracker[azfake.PollerResponder[${respType}]](),\n`;
|
|
161
161
|
break;
|
|
162
162
|
case "pageableMethod":
|
|
163
163
|
requiredHelpers.tracker = true;
|
|
164
|
-
content += `${indent.get()}${naming.uncapitalize(
|
|
164
|
+
content += `${indent.get()}${naming.uncapitalize(method.name)}: newTracker[azfake.PagerResponder[${respType}]](),\n`;
|
|
165
165
|
break;
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -192,11 +192,11 @@ export function generateServers(pkg, target) {
|
|
|
192
192
|
respType = `azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]`;
|
|
193
193
|
}
|
|
194
194
|
requiredHelpers.tracker = true;
|
|
195
|
-
content += `${indent.get()}${naming.uncapitalize(
|
|
195
|
+
content += `${indent.get()}${naming.uncapitalize(method.name)} *tracker[azfake.PollerResponder[${respType}]]\n`;
|
|
196
196
|
break;
|
|
197
197
|
case "pageableMethod":
|
|
198
198
|
requiredHelpers.tracker = true;
|
|
199
|
-
content += `${indent.get()}${naming.uncapitalize(
|
|
199
|
+
content += `${indent.get()}${naming.uncapitalize(method.name)} *tracker[azfake.PagerResponder[${go.getTypeDeclaration(method.returns, pkg)}]]\n`;
|
|
200
200
|
break;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
@@ -332,9 +332,8 @@ function generateServerTransportMethodDispatch(serverTransport, client, finalMet
|
|
|
332
332
|
indent.push();
|
|
333
333
|
content += `${indent.get()}switch method {\n`;
|
|
334
334
|
for (const method of finalMethods) {
|
|
335
|
-
|
|
336
|
-
content += `${indent.get()}
|
|
337
|
-
content += `${indent.push().get()}res.resp, res.err = ${receiverName}.dispatch${operationName}(req)\n`;
|
|
335
|
+
content += `${indent.get()}case "${client.name}.${method.name}":\n`;
|
|
336
|
+
content += `${indent.push().get()}res.resp, res.err = ${receiverName}.dispatch${method.name}(req)\n`;
|
|
338
337
|
indent.pop();
|
|
339
338
|
}
|
|
340
339
|
content += `${indent.push().get()}default:\n`;
|
|
@@ -372,9 +371,9 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
372
371
|
const receiverName = serverTransport[0].toLowerCase();
|
|
373
372
|
let content = "";
|
|
374
373
|
for (const method of finalMethods) {
|
|
375
|
-
content += `func (${receiverName} *${serverTransport}) dispatch${
|
|
376
|
-
content += `${indent.get()}if ${receiverName}.srv.${
|
|
377
|
-
content += `${indent.push().get()}return nil, &nonRetriableError{errors.New("fake for method ${
|
|
374
|
+
content += `func (${receiverName} *${serverTransport}) dispatch${method.name}(req *http.Request) (*http.Response, error) {\n`;
|
|
375
|
+
content += `${indent.get()}if ${receiverName}.srv.${method.name} == nil {\n`;
|
|
376
|
+
content += `${indent.push().get()}return nil, &nonRetriableError{errors.New("fake for method ${method.name} not implemented")}\n`;
|
|
378
377
|
content += `${indent.pop().get()}}\n`;
|
|
379
378
|
switch (method.kind) {
|
|
380
379
|
case "lroMethod":
|
|
@@ -403,11 +402,11 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
403
402
|
content += `${indent.pop().get()}})\n`;
|
|
404
403
|
}
|
|
405
404
|
else if (method.returns.result.kind === "monomorphicResult") {
|
|
406
|
-
if (method.returns.result.
|
|
407
|
-
const encoding = method.returns.result.
|
|
405
|
+
if (method.returns.result.type.kind === "encodedBytes") {
|
|
406
|
+
const encoding = method.returns.result.type.encoding;
|
|
408
407
|
content += `${indent.get()}resp, err := server.MarshalResponseAsByteArray(respContent, server.GetResponse(respr).${getResultFieldName(method.returns.result)}, runtime.Base64${encoding}Format, req)\n`;
|
|
409
408
|
}
|
|
410
|
-
else if (method.returns.result.
|
|
409
|
+
else if (method.returns.result.type.kind === "rawJSON") {
|
|
411
410
|
imports.add("bytes");
|
|
412
411
|
imports.add("io");
|
|
413
412
|
content += `${indent.get()}resp, err := server.NewResponse(respContent, req, &server.ResponseOptions{\n`;
|
|
@@ -420,39 +419,43 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
420
419
|
let contentToMarshal;
|
|
421
420
|
const respField = getResultFieldName(method.returns.result);
|
|
422
421
|
const getResponseField = `server.GetResponse(respr).${respField}`;
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
422
|
+
if (go.isPtr(method.returns.result.type, "scalar", "string")) {
|
|
423
|
+
switch (method.returns.result.type.ptrType.kind) {
|
|
424
|
+
case "scalar": {
|
|
425
|
+
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/to");
|
|
426
|
+
// create a local var that will hold the string-formatted scalar
|
|
427
|
+
contentToMarshal = `formatted${respField}`;
|
|
428
|
+
content += `${indent.get()}var ${contentToMarshal} *string\n`;
|
|
429
|
+
const localVar = naming.uncapitalize(respField);
|
|
430
|
+
// we want the wrapped type so formatValue will deref it
|
|
431
|
+
const monomorphicType = method.returns.result.type;
|
|
432
|
+
// if value := server.GetResponse(respr).Value; value != nil {...format as string...}
|
|
433
|
+
content += `${indent.get()}${helpers.buildIfBlock(indent, {
|
|
434
|
+
condition: `${localVar} := ${getResponseField}; ${localVar} != nil`,
|
|
435
|
+
body: (indent) => `${indent.get()}${contentToMarshal} = to.Ptr(${helpers.formatValue(localVar, monomorphicType, imports)})\n`,
|
|
436
|
+
})}\n`;
|
|
437
|
+
break;
|
|
438
|
+
}
|
|
439
|
+
case "string":
|
|
440
|
+
contentToMarshal = getResponseField;
|
|
441
|
+
break;
|
|
437
442
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
default:
|
|
442
|
-
throw new CodegenError("UnsupportedTsp", `unsupported text return kind ${method.returns.result.monomorphicType.kind} for method ${method.receiver.type.name}.${method.name}`);
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
throw new CodegenError("UnsupportedTsp", `unsupported text return kind ${method.returns.result.type.kind} for method ${method.receiver.type.name}.${method.name}`);
|
|
443
446
|
}
|
|
444
447
|
content += `${indent.get()}resp, err := server.MarshalResponseAsText(respContent, ${contentToMarshal}, req)\n`;
|
|
445
448
|
}
|
|
446
449
|
else {
|
|
447
450
|
let respField = `.${getResultFieldName(method.returns.result)}`;
|
|
448
451
|
if (method.returns.result.format === "XML" &&
|
|
449
|
-
method.returns.result.
|
|
452
|
+
method.returns.result.type.kind === "slice") {
|
|
450
453
|
respField = "";
|
|
451
454
|
}
|
|
452
455
|
let responseField = `server.GetResponse(respr)${respField}`;
|
|
453
|
-
if (method.returns.result.
|
|
456
|
+
if (go.isPtr(method.returns.result.type, "time")) {
|
|
454
457
|
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime");
|
|
455
|
-
responseField = `(*datetime.${method.returns.result.
|
|
458
|
+
responseField = `(*datetime.${method.returns.result.type.ptrType.format})(${responseField})`;
|
|
456
459
|
}
|
|
457
460
|
content += `${indent.get()}resp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, ${responseField}, req)\n`;
|
|
458
461
|
}
|
|
@@ -477,7 +480,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
477
480
|
}
|
|
478
481
|
else {
|
|
479
482
|
content += `${indent.get()}if val := server.GetResponse(respr).${header.fieldName}; val != nil {\n`;
|
|
480
|
-
content += `${indent.push().get()}resp.Header.Set("${helpers.canonicalizeHeaderName(header.headerName)}", ${helpers.formatValue("val", header.type, imports
|
|
483
|
+
content += `${indent.push().get()}resp.Header.Set("${helpers.canonicalizeHeaderName(header.headerName)}", ${helpers.formatValue("val", header.type, imports)})\n`;
|
|
481
484
|
content += `${indent.pop().get()}}\n`;
|
|
482
485
|
}
|
|
483
486
|
}
|
|
@@ -553,10 +556,11 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
553
556
|
content += `${indent.get()}req.Body.Close()\n`;
|
|
554
557
|
break;
|
|
555
558
|
default: {
|
|
556
|
-
|
|
557
|
-
|
|
559
|
+
const bodyParamType = go.unwrapPtr(bodyParam.type);
|
|
560
|
+
let bodyTypeName = go.getTypeDeclaration(bodyParamType, pkg);
|
|
561
|
+
if (bodyParamType.kind === "time") {
|
|
558
562
|
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime");
|
|
559
|
-
bodyTypeName = `datetime.${
|
|
563
|
+
bodyTypeName = `datetime.${bodyParamType.format}`;
|
|
560
564
|
}
|
|
561
565
|
content += `${indent.get()}body, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
|
|
562
566
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
@@ -705,13 +709,13 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
705
709
|
}
|
|
706
710
|
}
|
|
707
711
|
else if (type.kind === "slice") {
|
|
708
|
-
if (type.
|
|
712
|
+
if (type.itemType.kind === "readSeekCloser") {
|
|
709
713
|
imports.add("bytes");
|
|
710
714
|
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming");
|
|
711
715
|
assignedValue = `append(${paramVar}, streaming.NopCloser(bytes.NewReader(content)))`;
|
|
712
716
|
}
|
|
713
717
|
else {
|
|
714
|
-
throw new CodegenError("InternalError", `unhandled multipart parameter array element kind ${type.
|
|
718
|
+
throw new CodegenError("InternalError", `unhandled multipart parameter array element kind ${type.itemType.kind}`);
|
|
715
719
|
}
|
|
716
720
|
}
|
|
717
721
|
else if (type.kind === "encodedBytes") {
|
|
@@ -735,13 +739,14 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
735
739
|
for (const param of multipartBodyParams) {
|
|
736
740
|
if (isModelType(param.type)) {
|
|
737
741
|
for (const field of param.type.fields) {
|
|
738
|
-
content += emitCase(field.serializedName, `${param.name}.${field.name}`, field.type, field.
|
|
742
|
+
content += emitCase(field.serializedName, `${param.name}.${field.name}`, go.unwrapPtr(field.type), field.type.kind !== "ptr");
|
|
739
743
|
}
|
|
740
744
|
}
|
|
741
745
|
else {
|
|
742
|
-
//
|
|
743
|
-
// type
|
|
744
|
-
|
|
746
|
+
// optional params are wrapped in a pointer; the local var is declared
|
|
747
|
+
// as the pointer type, so dispatch on the unwrapped type and let
|
|
748
|
+
// emitCase wrap the value in to.Ptr when the destination is by-ref.
|
|
749
|
+
content += emitCase(param.name, param.name, go.unwrapPtr(param.type), !go.isPtr(param.type));
|
|
745
750
|
}
|
|
746
751
|
}
|
|
747
752
|
content += `${indent.get()}default:\n`;
|
|
@@ -780,7 +785,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
780
785
|
content += `${indent.get()}type partialBodyParams struct {\n`;
|
|
781
786
|
indent.push();
|
|
782
787
|
for (const partialBodyParam of partialBodyParams) {
|
|
783
|
-
content += `${indent.get()}${naming.capitalize(partialBodyParam.name)} ${
|
|
788
|
+
content += `${indent.get()}${naming.capitalize(partialBodyParam.name)} ${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
|
|
784
789
|
}
|
|
785
790
|
content += `${indent.pop().get()}}\n`;
|
|
786
791
|
content += `${indent.get()}body, err := server.UnmarshalRequestAs${partialBodyParams[0].format}[partialBodyParams](req)\n`;
|
|
@@ -790,9 +795,9 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
790
795
|
content += result.content;
|
|
791
796
|
// translate each partial body param to its field within the unmarshalled body
|
|
792
797
|
for (const partialBodyParam of partialBodyParams) {
|
|
793
|
-
result.params.set(partialBodyParam.name, `${helpers.
|
|
798
|
+
result.params.set(partialBodyParam.name, `${helpers.deref(partialBodyParam.type)}body.${naming.capitalize(partialBodyParam.name)}`);
|
|
794
799
|
}
|
|
795
|
-
const apiCall = `:= ${receiverName}.srv.${
|
|
800
|
+
const apiCall = `:= ${receiverName}.srv.${method.name}(${populateApiParams(pkg, method, result.params, imports)})`;
|
|
796
801
|
if (method.kind === "pageableMethod") {
|
|
797
802
|
content += `resp ${apiCall}\n`;
|
|
798
803
|
return content;
|
|
@@ -803,7 +808,11 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
803
808
|
return content;
|
|
804
809
|
}
|
|
805
810
|
function emitTextBodyUnmarshal(pkg, bodyParam, imports, indent) {
|
|
806
|
-
const
|
|
811
|
+
const bodyParamType = go.unwrapPtr(bodyParam.type);
|
|
812
|
+
// we pass the unwrapped param type since we'll be declaring
|
|
813
|
+
// a local of the underlying type and we don't want it to be
|
|
814
|
+
// pointer-to-type
|
|
815
|
+
const typeName = go.getTypeDeclaration(bodyParamType, pkg);
|
|
807
816
|
const optional = !go.isRequiredParameter(bodyParam.style);
|
|
808
817
|
let content = "";
|
|
809
818
|
if (optional) {
|
|
@@ -815,30 +824,30 @@ function emitTextBodyUnmarshal(pkg, bodyParam, imports, indent) {
|
|
|
815
824
|
content += `${indent.get()}bodyRaw, err := server.UnmarshalRequestAsText(req)\n`;
|
|
816
825
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
817
826
|
const assignOrDecl = optional ? "=" : ":=";
|
|
818
|
-
switch (
|
|
827
|
+
switch (bodyParamType.kind) {
|
|
819
828
|
case "string":
|
|
820
829
|
content += `${indent.get()}body ${assignOrDecl} bodyRaw\n`;
|
|
821
830
|
break;
|
|
822
831
|
case "constant":
|
|
823
832
|
imports.addForType(bodyParam.type);
|
|
824
|
-
if (
|
|
833
|
+
if (bodyParamType.type === "string") {
|
|
825
834
|
content += `${indent.get()}body ${assignOrDecl} ${typeName}(bodyRaw)\n`;
|
|
826
835
|
}
|
|
827
836
|
else {
|
|
828
|
-
content += helpers.emitScalarParsing(
|
|
837
|
+
content += helpers.emitScalarParsing(bodyParamType, "bodyRaw", "bodyParsed", imports, indent);
|
|
829
838
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
830
839
|
content += `${indent.get()}body ${assignOrDecl} ${typeName}(bodyParsed)\n`;
|
|
831
840
|
}
|
|
832
841
|
break;
|
|
833
842
|
case "scalar":
|
|
834
|
-
content += helpers.emitScalarParsing(
|
|
843
|
+
content += helpers.emitScalarParsing(bodyParamType, "bodyRaw", optional ? "bodyParsed" : "body", imports, indent);
|
|
835
844
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
836
845
|
if (optional) {
|
|
837
846
|
content += `${indent.get()}body = bodyParsed\n`;
|
|
838
847
|
}
|
|
839
848
|
break;
|
|
840
849
|
case "time":
|
|
841
|
-
content += helpers.emitTimeParsing("bodyRaw",
|
|
850
|
+
content += helpers.emitTimeParsing("bodyRaw", bodyParamType, "bodyParsed", imports, indent);
|
|
842
851
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
843
852
|
content += `${indent.get()}body ${assignOrDecl} bodyParsed\n`;
|
|
844
853
|
break;
|
|
@@ -879,9 +888,8 @@ function getMethodStatusCodes(method) {
|
|
|
879
888
|
* @returns the text for the LRO dispatch logic
|
|
880
889
|
*/
|
|
881
890
|
function dispatchForLROBody(pkg, receiverName, method, imports, indent) {
|
|
882
|
-
const
|
|
883
|
-
const
|
|
884
|
-
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
891
|
+
const localVarName = naming.uncapitalize(method.name);
|
|
892
|
+
const operationStateMachine = `${receiverName}.${naming.uncapitalize(method.name)}`;
|
|
885
893
|
let content = `${indent.get()}${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
886
894
|
content += `${indent.get()}if ${localVarName} == nil {\n`;
|
|
887
895
|
content += dispatchForOperationBody(pkg, receiverName, method, imports, indent);
|
|
@@ -916,9 +924,8 @@ function dispatchForLROBody(pkg, receiverName, method, imports, indent) {
|
|
|
916
924
|
* @returns the text for the pageable dispatch logic
|
|
917
925
|
*/
|
|
918
926
|
function dispatchForPagerBody(pkg, receiverName, method, imports, indent) {
|
|
919
|
-
const
|
|
920
|
-
const
|
|
921
|
-
const operationStateMachine = `${receiverName}.${naming.uncapitalize(operationName)}`;
|
|
927
|
+
const localVarName = naming.uncapitalize(method.name);
|
|
928
|
+
const operationStateMachine = `${receiverName}.${naming.uncapitalize(method.name)}`;
|
|
922
929
|
let content = `${indent.get()}${localVarName} := ${operationStateMachine}.get(req)\n`;
|
|
923
930
|
content += `${indent.get()}if ${localVarName} == nil {\n`;
|
|
924
931
|
content += dispatchForOperationBody(pkg, receiverName, method, imports, indent);
|
|
@@ -1048,6 +1055,8 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1048
1055
|
// of paramValue will be updated with the var name that
|
|
1049
1056
|
// contains the unescaped value.
|
|
1050
1057
|
let paramValue = getRawParamValue(param);
|
|
1058
|
+
// optional params are pointer-wrapped; dispatch on the unwrapped type.
|
|
1059
|
+
const paramType = go.unwrapPtr(param.type);
|
|
1051
1060
|
// encoded path params are escaped, so we need to unescape them first.
|
|
1052
1061
|
// non-encoded path params are already in their final form (the client
|
|
1053
1062
|
// skips url.PathEscape for them), so they're passed through verbatim.
|
|
@@ -1097,8 +1106,9 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1097
1106
|
if (param.kind === "headerCollectionParam" ||
|
|
1098
1107
|
param.kind === "pathCollectionParam" ||
|
|
1099
1108
|
param.kind === "queryCollectionParam") {
|
|
1109
|
+
const elementType = go.unwrapPtr(param.type.itemType);
|
|
1100
1110
|
// any element type other than string will require some form of conversion/parsing
|
|
1101
|
-
if (
|
|
1111
|
+
if (elementType.kind !== "string") {
|
|
1102
1112
|
if (param.collectionFormat !== "multi") {
|
|
1103
1113
|
requiredHelpers.splitHelper = true;
|
|
1104
1114
|
const elementsParam = createLocalVariableName(param, "Elements");
|
|
@@ -1107,21 +1117,21 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1107
1117
|
}
|
|
1108
1118
|
const paramVar = createLocalVariableName(param, "Param");
|
|
1109
1119
|
let elementFormat;
|
|
1110
|
-
switch (
|
|
1120
|
+
switch (elementType.kind) {
|
|
1111
1121
|
case "constant":
|
|
1112
1122
|
case "scalar":
|
|
1113
|
-
elementFormat =
|
|
1123
|
+
elementFormat = elementType.type;
|
|
1114
1124
|
break;
|
|
1115
1125
|
case "encodedBytes":
|
|
1116
|
-
elementFormat =
|
|
1126
|
+
elementFormat = elementType.encoding;
|
|
1117
1127
|
break;
|
|
1118
1128
|
case "time":
|
|
1119
|
-
elementFormat =
|
|
1129
|
+
elementFormat = elementType.format;
|
|
1120
1130
|
break;
|
|
1121
1131
|
default:
|
|
1122
|
-
throw new CodegenError("InternalError", `unhandled element kind ${
|
|
1132
|
+
throw new CodegenError("InternalError", `unhandled element kind ${elementType.kind}`);
|
|
1123
1133
|
}
|
|
1124
|
-
const toType = go.getTypeDeclaration(param.type.
|
|
1134
|
+
const toType = go.getTypeDeclaration(param.type.itemType, pkg);
|
|
1125
1135
|
content += `${indent.get()}${paramVar} := make([]${toType}, len(${paramValue}))\n`;
|
|
1126
1136
|
content += `${indent.get()}for i := 0; i < len(${paramValue}); i++ {\n`;
|
|
1127
1137
|
indent.push();
|
|
@@ -1188,7 +1198,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1188
1198
|
content += `${indent.get()}${createLocalVariableName(param, "Param")} := splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")\n`;
|
|
1189
1199
|
}
|
|
1190
1200
|
}
|
|
1191
|
-
else if (go.isScalar(
|
|
1201
|
+
else if (go.isScalar(paramType, "bool")) {
|
|
1192
1202
|
imports.add("strconv");
|
|
1193
1203
|
let from = `strconv.ParseBool(${paramValue})`;
|
|
1194
1204
|
if (!go.isRequiredParameter(param.style)) {
|
|
@@ -1198,12 +1208,12 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1198
1208
|
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${from}\n`;
|
|
1199
1209
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1200
1210
|
}
|
|
1201
|
-
else if (
|
|
1211
|
+
else if (paramType.kind === "encodedBytes") {
|
|
1202
1212
|
imports.add("encoding/base64");
|
|
1203
|
-
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := base64.${
|
|
1213
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := base64.${paramType.encoding}Encoding.DecodeString(${paramValue})\n`;
|
|
1204
1214
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1205
1215
|
}
|
|
1206
|
-
else if (
|
|
1216
|
+
else if (paramType.kind === "time") {
|
|
1207
1217
|
const formatMap = {
|
|
1208
1218
|
PlainDate: helpers.plainDateFormat,
|
|
1209
1219
|
PlainTime: helpers.plainTimeFormat,
|
|
@@ -1212,8 +1222,8 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1212
1222
|
RFC7231: helpers.RFC1123Format,
|
|
1213
1223
|
};
|
|
1214
1224
|
imports.add("time");
|
|
1215
|
-
if (
|
|
1216
|
-
const format = formatMap[
|
|
1225
|
+
if (paramType.format in formatMap) {
|
|
1226
|
+
const format = formatMap[paramType.format];
|
|
1217
1227
|
let from = `time.Parse(${format}, ${paramValue})`;
|
|
1218
1228
|
if (!go.isRequiredParameter(param.style)) {
|
|
1219
1229
|
requiredHelpers.parseOptional = true;
|
|
@@ -1241,7 +1251,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1241
1251
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1242
1252
|
}
|
|
1243
1253
|
}
|
|
1244
|
-
else if (go.isScalar(
|
|
1254
|
+
else if (go.isScalar(paramType, "float32", "float64", "int32", "int64")) {
|
|
1245
1255
|
let parser;
|
|
1246
1256
|
if (!go.isRequiredParameter(param.style)) {
|
|
1247
1257
|
requiredHelpers.parseOptional = true;
|
|
@@ -1251,20 +1261,20 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1251
1261
|
requiredHelpers.parseWithCast = true;
|
|
1252
1262
|
parser = "parseWithCast";
|
|
1253
1263
|
}
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
1264
|
+
if (paramType.type === "float32" ||
|
|
1265
|
+
paramType.type === "int32" ||
|
|
1256
1266
|
!go.isRequiredParameter(param.style)) {
|
|
1257
|
-
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${parser}(${paramValue}, func(v string) (${
|
|
1258
|
-
content += `${indent.push().get()}p, parseErr := ${emitNumericConversion("v",
|
|
1267
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${parser}(${paramValue}, func(v string) (${paramType.type}, error) {\n`;
|
|
1268
|
+
content += `${indent.push().get()}p, parseErr := ${emitNumericConversion("v", paramType.type)}\n`;
|
|
1259
1269
|
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return 0, parseErr\n${indent.pop().get()}}\n`;
|
|
1260
1270
|
let result = "p";
|
|
1261
|
-
if (
|
|
1262
|
-
result = `${
|
|
1271
|
+
if (paramType.type === "float32" || paramType.type === "int32") {
|
|
1272
|
+
result = `${paramType.type}(${result})`;
|
|
1263
1273
|
}
|
|
1264
1274
|
content += `${indent.get()}return ${result}, nil\n${indent.pop().get()}})\n`;
|
|
1265
1275
|
}
|
|
1266
1276
|
else {
|
|
1267
|
-
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${emitNumericConversion(paramValue,
|
|
1277
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${emitNumericConversion(paramValue, paramType.type)}\n`;
|
|
1268
1278
|
}
|
|
1269
1279
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1270
1280
|
}
|
|
@@ -1281,7 +1291,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1281
1291
|
content += `${indent.get()}${localVar}[hh[len("${headerPrefix}"):]] = to.Ptr(getHeaderValue(req.Header, hh))\n`;
|
|
1282
1292
|
content += `${indent.pop().get()}}\n${indent.pop().get()}}\n`;
|
|
1283
1293
|
}
|
|
1284
|
-
else if (go.isConstant(
|
|
1294
|
+
else if (go.isConstant(paramType, "bool", "float32", "float64", "int32", "int64")) {
|
|
1285
1295
|
let parseHelper;
|
|
1286
1296
|
if (!go.isRequiredParameter(param.style)) {
|
|
1287
1297
|
requiredHelpers.parseOptional = true;
|
|
@@ -1293,17 +1303,17 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1293
1303
|
}
|
|
1294
1304
|
let parse;
|
|
1295
1305
|
let zeroValue;
|
|
1296
|
-
if (
|
|
1306
|
+
if (paramType.type === "bool") {
|
|
1297
1307
|
imports.add("strconv");
|
|
1298
1308
|
parse = "strconv.ParseBool(v)";
|
|
1299
1309
|
zeroValue = "false";
|
|
1300
1310
|
}
|
|
1301
1311
|
else {
|
|
1302
1312
|
// emitNumericConversion adds the necessary import of strconv
|
|
1303
|
-
parse = emitNumericConversion("v",
|
|
1313
|
+
parse = emitNumericConversion("v", paramType.type);
|
|
1304
1314
|
zeroValue = "0";
|
|
1305
1315
|
}
|
|
1306
|
-
const toConstType = go.getTypeDeclaration(
|
|
1316
|
+
const toConstType = go.getTypeDeclaration(paramType, pkg);
|
|
1307
1317
|
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${parseHelper}(${paramValue}, func(v string) (${toConstType}, error) {\n`;
|
|
1308
1318
|
content += `${indent.push().get()}p, parseErr := ${parse}\n`;
|
|
1309
1319
|
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return ${zeroValue}, parseErr\n${indent.pop().get()}}\n`;
|
|
@@ -1313,9 +1323,9 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1313
1323
|
else if (!go.isRequiredParameter(param.style)) {
|
|
1314
1324
|
// we check this last as it's a superset of the previous conditions
|
|
1315
1325
|
requiredHelpers.getOptional = true;
|
|
1316
|
-
if (
|
|
1317
|
-
imports.addForType(
|
|
1318
|
-
paramValue = `${go.getTypeDeclaration(
|
|
1326
|
+
if (paramType.kind === "constant" || paramType.kind === "etag") {
|
|
1327
|
+
imports.addForType(paramType);
|
|
1328
|
+
paramValue = `${go.getTypeDeclaration(paramType, pkg)}(${paramValue})`;
|
|
1319
1329
|
}
|
|
1320
1330
|
content += `${indent.get()}${createLocalVariableName(param, "Param")} := getOptional(${paramValue})\n`;
|
|
1321
1331
|
}
|
|
@@ -1335,7 +1345,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1335
1345
|
content += `${indent.get()}}\n`;
|
|
1336
1346
|
}
|
|
1337
1347
|
else {
|
|
1338
|
-
content += `${indent.get()}var ${naming.uncapitalize(paramGroup.name)}
|
|
1348
|
+
content += `${indent.get()}var ${naming.uncapitalize(paramGroup.name)} ${go.getTypeDeclaration(paramGroup, pkg)}\n`;
|
|
1339
1349
|
const params = paramGroups.get(paramGroup);
|
|
1340
1350
|
const paramNilCheck = new Array();
|
|
1341
1351
|
if (params) {
|
|
@@ -1367,12 +1377,12 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1367
1377
|
}
|
|
1368
1378
|
}
|
|
1369
1379
|
content += `${indent.get()}if ${paramNilCheck.join(" || ")} {\n`;
|
|
1370
|
-
content += `${indent.push().get()}${naming.uncapitalize(paramGroup.name)} =
|
|
1380
|
+
content += `${indent.push().get()}${naming.uncapitalize(paramGroup.name)} = ${go.getTypeDeclaration(paramGroup, pkg, true)}{\n`;
|
|
1371
1381
|
if (params) {
|
|
1372
1382
|
indent.push();
|
|
1373
1383
|
for (const param of params) {
|
|
1374
1384
|
let byRef = "&";
|
|
1375
|
-
if (param.
|
|
1385
|
+
if (param.type.kind !== "ptr" ||
|
|
1376
1386
|
(!go.isRequiredParameter(param.style) &&
|
|
1377
1387
|
param.kind !== "bodyParam" &&
|
|
1378
1388
|
!go.isFormBodyParameter(param) &&
|
|
@@ -1493,7 +1503,7 @@ function getFinalParamValue(pkg, param, paramValues) {
|
|
|
1493
1503
|
if ((param.kind === "bodyParam" ||
|
|
1494
1504
|
go.isFormBodyParameter(param) ||
|
|
1495
1505
|
param.kind === "multipartFormBodyParam") &&
|
|
1496
|
-
param.type.kind === "time" &&
|
|
1506
|
+
go.unwrapPtr(param.type).kind === "time" &&
|
|
1497
1507
|
(param.kind !== "bodyParam" || param.bodyFormat !== "Text")) {
|
|
1498
1508
|
// time types in the body have been unmarshalled into our time helpers thus require a cast to time.Time
|
|
1499
1509
|
return `time.Time(${paramValue})`;
|
|
@@ -1505,7 +1515,7 @@ function getFinalParamValue(pkg, param, paramValues) {
|
|
|
1505
1515
|
param.kind === "queryCollectionParam") {
|
|
1506
1516
|
// for required params that are collections of strings, we split them inline.
|
|
1507
1517
|
// not necessary for optional params as they're already in slice format.
|
|
1508
|
-
if (param.collectionFormat !== "multi" && param.type.
|
|
1518
|
+
if (param.collectionFormat !== "multi" && param.type.itemType.kind === "string") {
|
|
1509
1519
|
requiredHelpers.splitHelper = true;
|
|
1510
1520
|
return `splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")`;
|
|
1511
1521
|
}
|
|
@@ -1573,12 +1583,9 @@ function getAPIParametersSig(pkg, method, imports) {
|
|
|
1573
1583
|
// copied from generator/helpers.ts but without the XML-specific stuff
|
|
1574
1584
|
function getResultFieldName(result) {
|
|
1575
1585
|
switch (result.kind) {
|
|
1576
|
-
case "anyResult":
|
|
1577
|
-
return result.fieldName;
|
|
1578
1586
|
case "modelResult":
|
|
1579
|
-
return result.modelType.name;
|
|
1580
1587
|
case "polymorphicResult":
|
|
1581
|
-
return result.
|
|
1588
|
+
return result.type.name;
|
|
1582
1589
|
default:
|
|
1583
1590
|
return result.fieldName;
|
|
1584
1591
|
}
|