@azure-tools/typespec-go 0.17.4 → 0.17.5-dev.5
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/src/codegen/core/example.js +11 -11
- package/dist/src/codegen/core/example.js.map +1 -1
- package/dist/src/codegen/core/helpers.d.ts +3 -8
- package/dist/src/codegen/core/helpers.d.ts.map +1 -1
- package/dist/src/codegen/core/helpers.js +28 -44
- 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 +3 -0
- package/dist/src/codegen/core/imports.js.map +1 -1
- package/dist/src/codegen/core/models.js +98 -96
- package/dist/src/codegen/core/models.js.map +1 -1
- package/dist/src/codegen/core/operations.js +4 -4
- 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/request-handler.d.ts.map +1 -1
- package/dist/src/codegen/core/request-handler.js +19 -15
- package/dist/src/codegen/core/request-handler.js.map +1 -1
- package/dist/src/codegen/core/response-handler.js +12 -10
- package/dist/src/codegen/core/response-handler.js.map +1 -1
- package/dist/src/codegen/core/responses.js +2 -10
- 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 +81 -68
- package/dist/src/codegen/fake/servers.js.map +1 -1
- package/dist/src/codemodel/client.js +1 -1
- 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 +40 -26
- 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 +11 -9
- package/dist/src/codemodel/result.d.ts.map +1 -1
- package/dist/src/codemodel/result.js +2 -4
- package/dist/src/codemodel/result.js.map +1 -1
- package/dist/src/codemodel/type.d.ts +62 -27
- package/dist/src/codemodel/type.d.ts.map +1 -1
- package/dist/src/codemodel/type.js +53 -21
- package/dist/src/codemodel/type.js.map +1 -1
- package/dist/src/tcgcadapter/clients.d.ts.map +1 -1
- package/dist/src/tcgcadapter/clients.js +41 -44
- package/dist/src/tcgcadapter/clients.js.map +1 -1
- package/dist/src/tcgcadapter/helpers.d.ts +2 -8
- package/dist/src/tcgcadapter/helpers.d.ts.map +1 -1
- package/dist/src/tcgcadapter/helpers.js +20 -18
- 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 +73 -27
- package/dist/src/tcgcadapter/types.js.map +1 -1
- package/package.json +23 -23
|
@@ -420,26 +420,30 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
420
420
|
let contentToMarshal;
|
|
421
421
|
const respField = getResultFieldName(method.returns.result);
|
|
422
422
|
const getResponseField = `server.GetResponse(respr).${respField}`;
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
423
|
+
if (go.isPtr(method.returns.result.monomorphicType, "scalar", "string")) {
|
|
424
|
+
switch (method.returns.result.monomorphicType.ptrType.kind) {
|
|
425
|
+
case "scalar": {
|
|
426
|
+
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/to");
|
|
427
|
+
// create a local var that will hold the string-formatted scalar
|
|
428
|
+
contentToMarshal = `formatted${respField}`;
|
|
429
|
+
content += `${indent.get()}var ${contentToMarshal} *string\n`;
|
|
430
|
+
const localVar = naming.uncapitalize(respField);
|
|
431
|
+
// we want the wrapped type so formatValue will deref it
|
|
432
|
+
const monomorphicType = method.returns.result.monomorphicType;
|
|
433
|
+
// if value := server.GetResponse(respr).Value; value != nil {...format as string...}
|
|
434
|
+
content += `${indent.get()}${helpers.buildIfBlock(indent, {
|
|
435
|
+
condition: `${localVar} := ${getResponseField}; ${localVar} != nil`,
|
|
436
|
+
body: (indent) => `${indent.get()}${contentToMarshal} = to.Ptr(${helpers.formatValue(localVar, monomorphicType, imports)})\n`,
|
|
437
|
+
})}\n`;
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
case "string":
|
|
441
|
+
contentToMarshal = getResponseField;
|
|
442
|
+
break;
|
|
437
443
|
}
|
|
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}`);
|
|
444
|
+
}
|
|
445
|
+
else {
|
|
446
|
+
throw new CodegenError("UnsupportedTsp", `unsupported text return kind ${method.returns.result.monomorphicType.kind} for method ${method.receiver.type.name}.${method.name}`);
|
|
443
447
|
}
|
|
444
448
|
content += `${indent.get()}resp, err := server.MarshalResponseAsText(respContent, ${contentToMarshal}, req)\n`;
|
|
445
449
|
}
|
|
@@ -450,9 +454,9 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
450
454
|
respField = "";
|
|
451
455
|
}
|
|
452
456
|
let responseField = `server.GetResponse(respr)${respField}`;
|
|
453
|
-
if (method.returns.result.monomorphicType
|
|
457
|
+
if (go.isPtr(method.returns.result.monomorphicType, "time")) {
|
|
454
458
|
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime");
|
|
455
|
-
responseField = `(*datetime.${method.returns.result.monomorphicType.format})(${responseField})`;
|
|
459
|
+
responseField = `(*datetime.${method.returns.result.monomorphicType.ptrType.format})(${responseField})`;
|
|
456
460
|
}
|
|
457
461
|
content += `${indent.get()}resp, err := server.MarshalResponseAs${method.returns.result.format}(respContent, ${responseField}, req)\n`;
|
|
458
462
|
}
|
|
@@ -477,7 +481,7 @@ function generateServerTransportMethods(pkg, serverTransport, finalMethods, impo
|
|
|
477
481
|
}
|
|
478
482
|
else {
|
|
479
483
|
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
|
|
484
|
+
content += `${indent.push().get()}resp.Header.Set("${helpers.canonicalizeHeaderName(header.headerName)}", ${helpers.formatValue("val", header.type, imports)})\n`;
|
|
481
485
|
content += `${indent.pop().get()}}\n`;
|
|
482
486
|
}
|
|
483
487
|
}
|
|
@@ -553,10 +557,11 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
553
557
|
content += `${indent.get()}req.Body.Close()\n`;
|
|
554
558
|
break;
|
|
555
559
|
default: {
|
|
556
|
-
|
|
557
|
-
|
|
560
|
+
const bodyParamType = go.unwrapPtr(bodyParam.type);
|
|
561
|
+
let bodyTypeName = go.getTypeDeclaration(bodyParamType, pkg);
|
|
562
|
+
if (bodyParamType.kind === "time") {
|
|
558
563
|
imports.add("github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime/datetime");
|
|
559
|
-
bodyTypeName = `datetime.${
|
|
564
|
+
bodyTypeName = `datetime.${bodyParamType.format}`;
|
|
560
565
|
}
|
|
561
566
|
content += `${indent.get()}body, err := server.UnmarshalRequestAs${bodyParam.bodyFormat}[${bodyTypeName}](req)\n`;
|
|
562
567
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
@@ -735,13 +740,14 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
735
740
|
for (const param of multipartBodyParams) {
|
|
736
741
|
if (isModelType(param.type)) {
|
|
737
742
|
for (const field of param.type.fields) {
|
|
738
|
-
content += emitCase(field.serializedName, `${param.name}.${field.name}`, field.type, field.
|
|
743
|
+
content += emitCase(field.serializedName, `${param.name}.${field.name}`, go.unwrapPtr(field.type), field.type.kind !== "ptr");
|
|
739
744
|
}
|
|
740
745
|
}
|
|
741
746
|
else {
|
|
742
|
-
//
|
|
743
|
-
// type
|
|
744
|
-
|
|
747
|
+
// optional params are wrapped in a pointer; the local var is declared
|
|
748
|
+
// as the pointer type, so dispatch on the unwrapped type and let
|
|
749
|
+
// emitCase wrap the value in to.Ptr when the destination is by-ref.
|
|
750
|
+
content += emitCase(param.name, param.name, go.unwrapPtr(param.type), !go.isPtr(param.type));
|
|
745
751
|
}
|
|
746
752
|
}
|
|
747
753
|
content += `${indent.get()}default:\n`;
|
|
@@ -780,7 +786,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
780
786
|
content += `${indent.get()}type partialBodyParams struct {\n`;
|
|
781
787
|
indent.push();
|
|
782
788
|
for (const partialBodyParam of partialBodyParams) {
|
|
783
|
-
content += `${indent.get()}${naming.capitalize(partialBodyParam.name)} ${
|
|
789
|
+
content += `${indent.get()}${naming.capitalize(partialBodyParam.name)} ${go.getTypeDeclaration(partialBodyParam.type, pkg)} \`json:"${partialBodyParam.serializedName}"\`\n`;
|
|
784
790
|
}
|
|
785
791
|
content += `${indent.pop().get()}}\n`;
|
|
786
792
|
content += `${indent.get()}body, err := server.UnmarshalRequestAs${partialBodyParams[0].format}[partialBodyParams](req)\n`;
|
|
@@ -790,7 +796,7 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
790
796
|
content += result.content;
|
|
791
797
|
// translate each partial body param to its field within the unmarshalled body
|
|
792
798
|
for (const partialBodyParam of partialBodyParams) {
|
|
793
|
-
result.params.set(partialBodyParam.name, `${helpers.
|
|
799
|
+
result.params.set(partialBodyParam.name, `${helpers.deref(partialBodyParam.type)}body.${naming.capitalize(partialBodyParam.name)}`);
|
|
794
800
|
}
|
|
795
801
|
const apiCall = `:= ${receiverName}.srv.${helpers.fixUpMethodName(method)}(${populateApiParams(pkg, method, result.params, imports)})`;
|
|
796
802
|
if (method.kind === "pageableMethod") {
|
|
@@ -803,7 +809,11 @@ function dispatchForOperationBody(pkg, receiverName, method, imports, indent) {
|
|
|
803
809
|
return content;
|
|
804
810
|
}
|
|
805
811
|
function emitTextBodyUnmarshal(pkg, bodyParam, imports, indent) {
|
|
806
|
-
const
|
|
812
|
+
const bodyParamType = go.unwrapPtr(bodyParam.type);
|
|
813
|
+
// we pass the unwrapped param type since we'll be declaring
|
|
814
|
+
// a local of the underlying type and we don't want it to be
|
|
815
|
+
// pointer-to-type
|
|
816
|
+
const typeName = go.getTypeDeclaration(bodyParamType, pkg);
|
|
807
817
|
const optional = !go.isRequiredParameter(bodyParam.style);
|
|
808
818
|
let content = "";
|
|
809
819
|
if (optional) {
|
|
@@ -815,30 +825,30 @@ function emitTextBodyUnmarshal(pkg, bodyParam, imports, indent) {
|
|
|
815
825
|
content += `${indent.get()}bodyRaw, err := server.UnmarshalRequestAsText(req)\n`;
|
|
816
826
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
817
827
|
const assignOrDecl = optional ? "=" : ":=";
|
|
818
|
-
switch (
|
|
828
|
+
switch (bodyParamType.kind) {
|
|
819
829
|
case "string":
|
|
820
830
|
content += `${indent.get()}body ${assignOrDecl} bodyRaw\n`;
|
|
821
831
|
break;
|
|
822
832
|
case "constant":
|
|
823
833
|
imports.addForType(bodyParam.type);
|
|
824
|
-
if (
|
|
834
|
+
if (bodyParamType.type === "string") {
|
|
825
835
|
content += `${indent.get()}body ${assignOrDecl} ${typeName}(bodyRaw)\n`;
|
|
826
836
|
}
|
|
827
837
|
else {
|
|
828
|
-
content += helpers.emitScalarParsing(
|
|
838
|
+
content += helpers.emitScalarParsing(bodyParamType, "bodyRaw", "bodyParsed", imports, indent);
|
|
829
839
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
830
840
|
content += `${indent.get()}body ${assignOrDecl} ${typeName}(bodyParsed)\n`;
|
|
831
841
|
}
|
|
832
842
|
break;
|
|
833
843
|
case "scalar":
|
|
834
|
-
content += helpers.emitScalarParsing(
|
|
844
|
+
content += helpers.emitScalarParsing(bodyParamType, "bodyRaw", optional ? "bodyParsed" : "body", imports, indent);
|
|
835
845
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
836
846
|
if (optional) {
|
|
837
847
|
content += `${indent.get()}body = bodyParsed\n`;
|
|
838
848
|
}
|
|
839
849
|
break;
|
|
840
850
|
case "time":
|
|
841
|
-
content += helpers.emitTimeParsing("bodyRaw",
|
|
851
|
+
content += helpers.emitTimeParsing("bodyRaw", bodyParamType, "bodyParsed", imports, indent);
|
|
842
852
|
content += `${indent.get()}${helpers.buildErrCheck(indent, "err", "nil")}\n`;
|
|
843
853
|
content += `${indent.get()}body ${assignOrDecl} bodyParsed\n`;
|
|
844
854
|
break;
|
|
@@ -1048,6 +1058,8 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1048
1058
|
// of paramValue will be updated with the var name that
|
|
1049
1059
|
// contains the unescaped value.
|
|
1050
1060
|
let paramValue = getRawParamValue(param);
|
|
1061
|
+
// optional params are pointer-wrapped; dispatch on the unwrapped type.
|
|
1062
|
+
const paramType = go.unwrapPtr(param.type);
|
|
1051
1063
|
// encoded path params are escaped, so we need to unescape them first.
|
|
1052
1064
|
// non-encoded path params are already in their final form (the client
|
|
1053
1065
|
// skips url.PathEscape for them), so they're passed through verbatim.
|
|
@@ -1097,8 +1109,9 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1097
1109
|
if (param.kind === "headerCollectionParam" ||
|
|
1098
1110
|
param.kind === "pathCollectionParam" ||
|
|
1099
1111
|
param.kind === "queryCollectionParam") {
|
|
1112
|
+
const elementType = go.unwrapPtr(param.type.elementType);
|
|
1100
1113
|
// any element type other than string will require some form of conversion/parsing
|
|
1101
|
-
if (
|
|
1114
|
+
if (elementType.kind !== "string") {
|
|
1102
1115
|
if (param.collectionFormat !== "multi") {
|
|
1103
1116
|
requiredHelpers.splitHelper = true;
|
|
1104
1117
|
const elementsParam = createLocalVariableName(param, "Elements");
|
|
@@ -1107,19 +1120,19 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1107
1120
|
}
|
|
1108
1121
|
const paramVar = createLocalVariableName(param, "Param");
|
|
1109
1122
|
let elementFormat;
|
|
1110
|
-
switch (
|
|
1123
|
+
switch (elementType.kind) {
|
|
1111
1124
|
case "constant":
|
|
1112
1125
|
case "scalar":
|
|
1113
|
-
elementFormat =
|
|
1126
|
+
elementFormat = elementType.type;
|
|
1114
1127
|
break;
|
|
1115
1128
|
case "encodedBytes":
|
|
1116
|
-
elementFormat =
|
|
1129
|
+
elementFormat = elementType.encoding;
|
|
1117
1130
|
break;
|
|
1118
1131
|
case "time":
|
|
1119
|
-
elementFormat =
|
|
1132
|
+
elementFormat = elementType.format;
|
|
1120
1133
|
break;
|
|
1121
1134
|
default:
|
|
1122
|
-
throw new CodegenError("InternalError", `unhandled element kind ${
|
|
1135
|
+
throw new CodegenError("InternalError", `unhandled element kind ${elementType.kind}`);
|
|
1123
1136
|
}
|
|
1124
1137
|
const toType = go.getTypeDeclaration(param.type.elementType, pkg);
|
|
1125
1138
|
content += `${indent.get()}${paramVar} := make([]${toType}, len(${paramValue}))\n`;
|
|
@@ -1188,7 +1201,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1188
1201
|
content += `${indent.get()}${createLocalVariableName(param, "Param")} := splitHelper(${paramValue}, "${helpers.getDelimiterForCollectionFormat(param.collectionFormat)}")\n`;
|
|
1189
1202
|
}
|
|
1190
1203
|
}
|
|
1191
|
-
else if (go.isScalar(
|
|
1204
|
+
else if (go.isScalar(paramType, "bool")) {
|
|
1192
1205
|
imports.add("strconv");
|
|
1193
1206
|
let from = `strconv.ParseBool(${paramValue})`;
|
|
1194
1207
|
if (!go.isRequiredParameter(param.style)) {
|
|
@@ -1198,12 +1211,12 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1198
1211
|
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${from}\n`;
|
|
1199
1212
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1200
1213
|
}
|
|
1201
|
-
else if (
|
|
1214
|
+
else if (paramType.kind === "encodedBytes") {
|
|
1202
1215
|
imports.add("encoding/base64");
|
|
1203
|
-
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := base64.${
|
|
1216
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := base64.${paramType.encoding}Encoding.DecodeString(${paramValue})\n`;
|
|
1204
1217
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1205
1218
|
}
|
|
1206
|
-
else if (
|
|
1219
|
+
else if (paramType.kind === "time") {
|
|
1207
1220
|
const formatMap = {
|
|
1208
1221
|
PlainDate: helpers.plainDateFormat,
|
|
1209
1222
|
PlainTime: helpers.plainTimeFormat,
|
|
@@ -1212,8 +1225,8 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1212
1225
|
RFC7231: helpers.RFC1123Format,
|
|
1213
1226
|
};
|
|
1214
1227
|
imports.add("time");
|
|
1215
|
-
if (
|
|
1216
|
-
const format = formatMap[
|
|
1228
|
+
if (paramType.format in formatMap) {
|
|
1229
|
+
const format = formatMap[paramType.format];
|
|
1217
1230
|
let from = `time.Parse(${format}, ${paramValue})`;
|
|
1218
1231
|
if (!go.isRequiredParameter(param.style)) {
|
|
1219
1232
|
requiredHelpers.parseOptional = true;
|
|
@@ -1241,7 +1254,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1241
1254
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1242
1255
|
}
|
|
1243
1256
|
}
|
|
1244
|
-
else if (go.isScalar(
|
|
1257
|
+
else if (go.isScalar(paramType, "float32", "float64", "int32", "int64")) {
|
|
1245
1258
|
let parser;
|
|
1246
1259
|
if (!go.isRequiredParameter(param.style)) {
|
|
1247
1260
|
requiredHelpers.parseOptional = true;
|
|
@@ -1251,20 +1264,20 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1251
1264
|
requiredHelpers.parseWithCast = true;
|
|
1252
1265
|
parser = "parseWithCast";
|
|
1253
1266
|
}
|
|
1254
|
-
if (
|
|
1255
|
-
|
|
1267
|
+
if (paramType.type === "float32" ||
|
|
1268
|
+
paramType.type === "int32" ||
|
|
1256
1269
|
!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",
|
|
1270
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${parser}(${paramValue}, func(v string) (${paramType.type}, error) {\n`;
|
|
1271
|
+
content += `${indent.push().get()}p, parseErr := ${emitNumericConversion("v", paramType.type)}\n`;
|
|
1259
1272
|
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return 0, parseErr\n${indent.pop().get()}}\n`;
|
|
1260
1273
|
let result = "p";
|
|
1261
|
-
if (
|
|
1262
|
-
result = `${
|
|
1274
|
+
if (paramType.type === "float32" || paramType.type === "int32") {
|
|
1275
|
+
result = `${paramType.type}(${result})`;
|
|
1263
1276
|
}
|
|
1264
1277
|
content += `${indent.get()}return ${result}, nil\n${indent.pop().get()}})\n`;
|
|
1265
1278
|
}
|
|
1266
1279
|
else {
|
|
1267
|
-
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${emitNumericConversion(paramValue,
|
|
1280
|
+
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${emitNumericConversion(paramValue, paramType.type)}\n`;
|
|
1268
1281
|
}
|
|
1269
1282
|
content += `${indent.get()}if err != nil {\n${indent.push().get()}return nil, err\n${indent.pop().get()}}\n`;
|
|
1270
1283
|
}
|
|
@@ -1281,7 +1294,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1281
1294
|
content += `${indent.get()}${localVar}[hh[len("${headerPrefix}"):]] = to.Ptr(getHeaderValue(req.Header, hh))\n`;
|
|
1282
1295
|
content += `${indent.pop().get()}}\n${indent.pop().get()}}\n`;
|
|
1283
1296
|
}
|
|
1284
|
-
else if (go.isConstant(
|
|
1297
|
+
else if (go.isConstant(paramType, "bool", "float32", "float64", "int32", "int64")) {
|
|
1285
1298
|
let parseHelper;
|
|
1286
1299
|
if (!go.isRequiredParameter(param.style)) {
|
|
1287
1300
|
requiredHelpers.parseOptional = true;
|
|
@@ -1293,17 +1306,17 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1293
1306
|
}
|
|
1294
1307
|
let parse;
|
|
1295
1308
|
let zeroValue;
|
|
1296
|
-
if (
|
|
1309
|
+
if (paramType.type === "bool") {
|
|
1297
1310
|
imports.add("strconv");
|
|
1298
1311
|
parse = "strconv.ParseBool(v)";
|
|
1299
1312
|
zeroValue = "false";
|
|
1300
1313
|
}
|
|
1301
1314
|
else {
|
|
1302
1315
|
// emitNumericConversion adds the necessary import of strconv
|
|
1303
|
-
parse = emitNumericConversion("v",
|
|
1316
|
+
parse = emitNumericConversion("v", paramType.type);
|
|
1304
1317
|
zeroValue = "0";
|
|
1305
1318
|
}
|
|
1306
|
-
const toConstType = go.getTypeDeclaration(
|
|
1319
|
+
const toConstType = go.getTypeDeclaration(paramType, pkg);
|
|
1307
1320
|
content += `${indent.get()}${createLocalVariableName(param, "Param")}, err := ${parseHelper}(${paramValue}, func(v string) (${toConstType}, error) {\n`;
|
|
1308
1321
|
content += `${indent.push().get()}p, parseErr := ${parse}\n`;
|
|
1309
1322
|
content += `${indent.get()}if parseErr != nil {\n${indent.push().get()}return ${zeroValue}, parseErr\n${indent.pop().get()}}\n`;
|
|
@@ -1313,9 +1326,9 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1313
1326
|
else if (!go.isRequiredParameter(param.style)) {
|
|
1314
1327
|
// we check this last as it's a superset of the previous conditions
|
|
1315
1328
|
requiredHelpers.getOptional = true;
|
|
1316
|
-
if (
|
|
1317
|
-
imports.addForType(
|
|
1318
|
-
paramValue = `${go.getTypeDeclaration(
|
|
1329
|
+
if (paramType.kind === "constant" || paramType.kind === "etag") {
|
|
1330
|
+
imports.addForType(paramType);
|
|
1331
|
+
paramValue = `${go.getTypeDeclaration(paramType, pkg)}(${paramValue})`;
|
|
1319
1332
|
}
|
|
1320
1333
|
content += `${indent.get()}${createLocalVariableName(param, "Param")} := getOptional(${paramValue})\n`;
|
|
1321
1334
|
}
|
|
@@ -1335,7 +1348,7 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1335
1348
|
content += `${indent.get()}}\n`;
|
|
1336
1349
|
}
|
|
1337
1350
|
else {
|
|
1338
|
-
content += `${indent.get()}var ${naming.uncapitalize(paramGroup.name)}
|
|
1351
|
+
content += `${indent.get()}var ${naming.uncapitalize(paramGroup.name)} ${go.getTypeDeclaration(paramGroup, pkg)}\n`;
|
|
1339
1352
|
const params = paramGroups.get(paramGroup);
|
|
1340
1353
|
const paramNilCheck = new Array();
|
|
1341
1354
|
if (params) {
|
|
@@ -1367,12 +1380,12 @@ function parseHeaderPathQueryParams(pkg, method, imports, indent) {
|
|
|
1367
1380
|
}
|
|
1368
1381
|
}
|
|
1369
1382
|
content += `${indent.get()}if ${paramNilCheck.join(" || ")} {\n`;
|
|
1370
|
-
content += `${indent.push().get()}${naming.uncapitalize(paramGroup.name)} =
|
|
1383
|
+
content += `${indent.push().get()}${naming.uncapitalize(paramGroup.name)} = ${go.getTypeDeclaration(paramGroup, pkg, true)}{\n`;
|
|
1371
1384
|
if (params) {
|
|
1372
1385
|
indent.push();
|
|
1373
1386
|
for (const param of params) {
|
|
1374
1387
|
let byRef = "&";
|
|
1375
|
-
if (param.
|
|
1388
|
+
if (param.type.kind !== "ptr" ||
|
|
1376
1389
|
(!go.isRequiredParameter(param.style) &&
|
|
1377
1390
|
param.kind !== "bodyParam" &&
|
|
1378
1391
|
!go.isFormBodyParameter(param) &&
|
|
@@ -1493,7 +1506,7 @@ function getFinalParamValue(pkg, param, paramValues) {
|
|
|
1493
1506
|
if ((param.kind === "bodyParam" ||
|
|
1494
1507
|
go.isFormBodyParameter(param) ||
|
|
1495
1508
|
param.kind === "multipartFormBodyParam") &&
|
|
1496
|
-
param.type.kind === "time" &&
|
|
1509
|
+
go.unwrapPtr(param.type).kind === "time" &&
|
|
1497
1510
|
(param.kind !== "bodyParam" || param.bodyFormat !== "Text")) {
|
|
1498
1511
|
// time types in the body have been unmarshalled into our time helpers thus require a cast to time.Time
|
|
1499
1512
|
return `time.Time(${paramValue})`;
|