@azure-tools/typespec-rust 0.35.0 → 0.36.0
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/clients.js +10 -2
- package/dist/src/codegen/clients.js.map +1 -1
- package/dist/src/codegen/context.d.ts.map +1 -1
- package/dist/src/codegen/context.js +1 -2
- package/dist/src/codegen/context.js.map +1 -1
- package/dist/src/codegen/docTests.d.ts.map +1 -1
- package/dist/src/codegen/docTests.js +1 -2
- package/dist/src/codegen/docTests.js.map +1 -1
- package/dist/src/codemodel/client.d.ts +2 -2
- package/dist/src/codemodel/client.d.ts.map +1 -1
- package/dist/src/codemodel/client.js.map +1 -1
- package/dist/src/emitter.js +1 -1
- package/dist/src/emitter.js.map +1 -1
- package/dist/src/tcgcadapter/adapter.d.ts +9 -3
- package/dist/src/tcgcadapter/adapter.d.ts.map +1 -1
- package/dist/src/tcgcadapter/adapter.js +78 -62
- package/dist/src/tcgcadapter/adapter.js.map +1 -1
- package/package.json +5 -5
package/dist/src/emitter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitter.js","sourceRoot":"","sources":["../../src/emitter.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,4BAA4B;AAE5B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAsB,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,IAAI,MAAM,MAAM,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,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9C,MAAM,SAAS,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAa,EAAE,UAAkB;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,KAAK,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,KAAK,IAAI,GAAG,IAAI,IAAI,CAAC;QACrB,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as tsp from '@typespec/compiler';
|
|
2
2
|
import { RustEmitterOptions } from '../lib.js';
|
|
3
3
|
import * as rust from '../codemodel/index.js';
|
|
4
|
+
import { EmitContext } from "@typespec/compiler";
|
|
4
5
|
/** ErrorCode defines the types of adapter errors */
|
|
5
6
|
export type ErrorCode =
|
|
6
7
|
/** the emitter encountered an internal error. this is always a bug in the emitter */
|
|
@@ -47,7 +48,7 @@ export declare class Adapter {
|
|
|
47
48
|
private readonly fieldsMap;
|
|
48
49
|
private constructor();
|
|
49
50
|
/** performs all the steps to convert tcgc to a crate */
|
|
50
|
-
tcgcToCrate(): rust.Crate;
|
|
51
|
+
tcgcToCrate(context: EmitContext<RustEmitterOptions>): rust.Crate;
|
|
51
52
|
/** converts tcgc docs to formatted rust.Docs */
|
|
52
53
|
private adaptDocs;
|
|
53
54
|
/** converts all tcgc types to their Rust type equivalent */
|
|
@@ -233,9 +234,14 @@ export declare class Adapter {
|
|
|
233
234
|
*/
|
|
234
235
|
private adaptPageableMethodReinjectionParams;
|
|
235
236
|
/**
|
|
236
|
-
* converts a tcgc operation parameter into a Rust method parameter
|
|
237
|
+
* converts a tcgc operation parameter into a Rust method parameter.
|
|
238
|
+
* note that when methodParam is present, we must use all applicable
|
|
239
|
+
* values from methodParam as the source of truth. e.g. when overriding
|
|
240
|
+
* a method to make an optional param required, the requiredness will
|
|
241
|
+
* be reflected in the method param, _not_ the operation param.
|
|
237
242
|
*
|
|
238
|
-
* @param
|
|
243
|
+
* @param opParam the tcgc operation parameter to convert
|
|
244
|
+
* @param methodParam the tcgc method parameter associated with opParam
|
|
239
245
|
* @returns a Rust method parameter
|
|
240
246
|
*/
|
|
241
247
|
private adaptMethodParameter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAI1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAG7C,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/tcgcadapter/adapter.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,GAAG,MAAM,oBAAoB,CAAC;AAI1C,OAAO,EAAC,kBAAkB,EAAC,MAAM,WAAW,CAAC;AAG7C,OAAO,KAAK,IAAI,MAAM,uBAAuB,CAAC;AAE9C,OAAO,EAAC,WAAW,EAAW,MAAM,oBAAoB,CAAC;AAEzD,oDAAoD;AACpD,MAAM,MAAM,SAAS;AACnB,qFAAqF;AACrF,eAAe;AAEf,mDAAmD;AACnD,iBAAiB;AAEjB;;;GAGG;AACH,eAAe;AAEf,sEAAsE;AACtE,gBAAgB,CAAC;AAEnB;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,KAAK;IACrC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,gBAAgB,GAAG,OAAO,GAAG,CAAC,QAAQ,CAAC;gBAEhD,IAAI,EAAE,SAAS,E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) 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
|
-
// cspell: ignore addl responseheader subclients lropaging
|
|
5
|
+
// cspell: ignore addl requiredness responseheader subclients lropaging
|
|
6
6
|
import * as tsp from '@typespec/compiler';
|
|
7
7
|
import * as helpers from './helpers.js';
|
|
8
8
|
import * as naming from './naming.js';
|
|
@@ -10,6 +10,7 @@ import * as utils from '../utils/utils.js';
|
|
|
10
10
|
import * as tcgc from '@azure-tools/typespec-client-generator-core';
|
|
11
11
|
import * as rust from '../codemodel/index.js';
|
|
12
12
|
import { FinalStateValue } from "@azure-tools/typespec-azure-core";
|
|
13
|
+
import { NoTarget } from "@typespec/compiler";
|
|
13
14
|
/**
|
|
14
15
|
* AdapterError is thrown when the emitter fails to convert part of the tcgc code
|
|
15
16
|
* model to the emitter code model. this could be due to the emitter not supporting
|
|
@@ -69,8 +70,8 @@ export class Adapter {
|
|
|
69
70
|
this.crate = new rust.Crate(this.options['crate-name'], this.options['crate-version'], serviceType);
|
|
70
71
|
}
|
|
71
72
|
/** performs all the steps to convert tcgc to a crate */
|
|
72
|
-
tcgcToCrate() {
|
|
73
|
-
this.adaptTypes();
|
|
73
|
+
tcgcToCrate(context) {
|
|
74
|
+
this.adaptTypes(context);
|
|
74
75
|
this.adaptClients();
|
|
75
76
|
// marker models don't require serde so exclude them from the check
|
|
76
77
|
if (this.crate.enums.length > 0 || this.crate.models.some(e => e.kind === 'model')) {
|
|
@@ -96,11 +97,17 @@ export class Adapter {
|
|
|
96
97
|
};
|
|
97
98
|
}
|
|
98
99
|
/** converts all tcgc types to their Rust type equivalent */
|
|
99
|
-
adaptTypes() {
|
|
100
|
-
var _a;
|
|
100
|
+
adaptTypes(context) {
|
|
101
101
|
for (const sdkUnion of this.ctx.sdkPackage.unions.filter(u => u.kind === 'union')) {
|
|
102
102
|
if (!sdkUnion.discriminatedOptions) {
|
|
103
|
-
|
|
103
|
+
// When https://github.com/microsoft/typespec/issues/9749 is fixed, we can return to throwing an exception here.
|
|
104
|
+
context.program.reportDiagnostic({
|
|
105
|
+
code: 'UnsupportedTsp',
|
|
106
|
+
severity: 'warning',
|
|
107
|
+
message: `Non-discriminated unions ('${sdkUnion.name}') are not supported. No type will be generated.`,
|
|
108
|
+
target: NoTarget,
|
|
109
|
+
});
|
|
110
|
+
continue;
|
|
104
111
|
}
|
|
105
112
|
const rustUnion = this.getDiscriminatedUnion(sdkUnion);
|
|
106
113
|
this.crate.unions.push(rustUnion);
|
|
@@ -1440,7 +1447,7 @@ export class Adapter {
|
|
|
1440
1447
|
adaptedParam = this.adaptMethodSpreadParameter(param, this.adaptPayloadFormat(opParam.defaultContentType), opParam.type);
|
|
1441
1448
|
}
|
|
1442
1449
|
else {
|
|
1443
|
-
adaptedParam = this.adaptMethodParameter(opParam);
|
|
1450
|
+
adaptedParam = this.adaptMethodParameter(opParam, param);
|
|
1444
1451
|
}
|
|
1445
1452
|
switch (adaptedParam.kind) {
|
|
1446
1453
|
case 'headerScalar':
|
|
@@ -1775,14 +1782,6 @@ export class Adapter {
|
|
|
1775
1782
|
return utils.capitalize(type.kind);
|
|
1776
1783
|
}
|
|
1777
1784
|
};
|
|
1778
|
-
const throwOnUnitType = function (type) {
|
|
1779
|
-
if (type.kind === 'unit') {
|
|
1780
|
-
// this is to filter out unit from ResponseTypes.
|
|
1781
|
-
// methods that return unit should have been skipped by our caller
|
|
1782
|
-
// so we should never hit this (if we do, we have a bug elsewhere).
|
|
1783
|
-
throw new AdapterError('InternalError', `unexpected trait impl kind ${type.kind}`);
|
|
1784
|
-
}
|
|
1785
|
-
};
|
|
1786
1785
|
// response header traits are only ever for marker types and payloads
|
|
1787
1786
|
let implFor;
|
|
1788
1787
|
switch (method.returns.type.kind) {
|
|
@@ -1791,12 +1790,23 @@ export class Adapter {
|
|
|
1791
1790
|
implFor = method.returns.type.type;
|
|
1792
1791
|
break;
|
|
1793
1792
|
case 'response':
|
|
1794
|
-
|
|
1795
|
-
|
|
1793
|
+
switch (method.returns.type.content.kind) {
|
|
1794
|
+
case 'marker':
|
|
1795
|
+
case 'model':
|
|
1796
|
+
implFor = method.returns.type;
|
|
1797
|
+
break;
|
|
1798
|
+
default:
|
|
1799
|
+
throw new AdapterError('InternalError', `unexpected trait impl content kind ${method.returns.type.content.kind}`);
|
|
1800
|
+
}
|
|
1796
1801
|
break;
|
|
1797
1802
|
case 'asyncResponse':
|
|
1798
|
-
|
|
1799
|
-
|
|
1803
|
+
switch (method.returns.type.type.kind) {
|
|
1804
|
+
case 'marker':
|
|
1805
|
+
implFor = method.returns.type;
|
|
1806
|
+
break;
|
|
1807
|
+
default:
|
|
1808
|
+
throw new AdapterError('InternalError', `unexpected trait impl type kind ${method.returns.type.type.kind}`);
|
|
1809
|
+
}
|
|
1800
1810
|
break;
|
|
1801
1811
|
}
|
|
1802
1812
|
const traitName = `${recursiveTypeName(implFor.kind === 'asyncResponse' ? implFor.type : implFor.content)}Headers`;
|
|
@@ -1922,12 +1932,17 @@ export class Adapter {
|
|
|
1922
1932
|
return paramsForReinjection;
|
|
1923
1933
|
}
|
|
1924
1934
|
/**
|
|
1925
|
-
* converts a tcgc operation parameter into a Rust method parameter
|
|
1935
|
+
* converts a tcgc operation parameter into a Rust method parameter.
|
|
1936
|
+
* note that when methodParam is present, we must use all applicable
|
|
1937
|
+
* values from methodParam as the source of truth. e.g. when overriding
|
|
1938
|
+
* a method to make an optional param required, the requiredness will
|
|
1939
|
+
* be reflected in the method param, _not_ the operation param.
|
|
1926
1940
|
*
|
|
1927
|
-
* @param
|
|
1941
|
+
* @param opParam the tcgc operation parameter to convert
|
|
1942
|
+
* @param methodParam the tcgc method parameter associated with opParam
|
|
1928
1943
|
* @returns a Rust method parameter
|
|
1929
1944
|
*/
|
|
1930
|
-
adaptMethodParameter(
|
|
1945
|
+
adaptMethodParameter(opParam, methodParam) {
|
|
1931
1946
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
1932
1947
|
/**
|
|
1933
1948
|
* used to create keys for this.clientMethodParams
|
|
@@ -1939,10 +1954,10 @@ export class Adapter {
|
|
|
1939
1954
|
// in different places across methods (path/query)
|
|
1940
1955
|
return `${param.name}-${param.kind}`;
|
|
1941
1956
|
};
|
|
1942
|
-
const paramLoc =
|
|
1957
|
+
const paramLoc = opParam.onClient ? 'client' : 'method';
|
|
1943
1958
|
// if this is a client method param, check if we've already adapted it
|
|
1944
1959
|
if (paramLoc === 'client') {
|
|
1945
|
-
const clientMethodParam = this.clientMethodParams.get(getClientParamsKey(
|
|
1960
|
+
const clientMethodParam = this.clientMethodParams.get(getClientParamsKey(opParam));
|
|
1946
1961
|
if (clientMethodParam) {
|
|
1947
1962
|
return clientMethodParam;
|
|
1948
1963
|
}
|
|
@@ -1958,40 +1973,41 @@ export class Adapter {
|
|
|
1958
1973
|
}
|
|
1959
1974
|
return param.name;
|
|
1960
1975
|
};
|
|
1961
|
-
const paramName = naming.getEscapedReservedName(utils.snakeCaseName(getCorrespondingClientParamName(
|
|
1962
|
-
|
|
1976
|
+
const paramName = naming.getEscapedReservedName(utils.snakeCaseName(getCorrespondingClientParamName(opParam)), 'param', reservedParams);
|
|
1977
|
+
const paramOptional = methodParam ? methodParam.optional : opParam.optional;
|
|
1978
|
+
let paramType = this.getType(methodParam ? methodParam.type : opParam.type);
|
|
1963
1979
|
// for required header/path/query method string params, we might emit them as borrowed types
|
|
1964
|
-
if (!
|
|
1965
|
-
const borrowedType = this.canBorrowMethodParam(paramType,
|
|
1980
|
+
if (!paramOptional && paramLoc !== 'client' && (opParam.kind === 'header' || opParam.kind === 'path' || opParam.kind === 'query')) {
|
|
1981
|
+
const borrowedType = this.canBorrowMethodParam(paramType, opParam.kind);
|
|
1966
1982
|
if (borrowedType) {
|
|
1967
1983
|
paramType = borrowedType;
|
|
1968
1984
|
}
|
|
1969
1985
|
}
|
|
1970
1986
|
let adaptedParam;
|
|
1971
|
-
switch (
|
|
1987
|
+
switch (opParam.kind) {
|
|
1972
1988
|
case 'body': {
|
|
1973
1989
|
let requestType;
|
|
1974
|
-
if (
|
|
1990
|
+
if (opParam.type.kind === 'bytes' && opParam.type.encode === 'bytes') {
|
|
1975
1991
|
// bytes encoding indicates a streaming binary request
|
|
1976
1992
|
requestType = new rust.Bytes(this.crate);
|
|
1977
1993
|
}
|
|
1978
1994
|
else {
|
|
1979
|
-
requestType = new rust.Payload(this.typeToWireType(paramType), this.adaptPayloadFormat(
|
|
1995
|
+
requestType = new rust.Payload(this.typeToWireType(paramType), this.adaptPayloadFormat(opParam.defaultContentType));
|
|
1980
1996
|
}
|
|
1981
|
-
const requestFormatType = this.adaptPayloadFormatType(
|
|
1982
|
-
adaptedParam = new rust.BodyParameter(paramName, paramLoc,
|
|
1997
|
+
const requestFormatType = this.adaptPayloadFormatType(opParam.defaultContentType);
|
|
1998
|
+
adaptedParam = new rust.BodyParameter(paramName, paramLoc, paramOptional, new rust.RequestContent(this.crate, requestType, requestFormatType));
|
|
1983
1999
|
break;
|
|
1984
2000
|
}
|
|
1985
2001
|
case 'cookie':
|
|
1986
2002
|
// TODO: https://github.com/Azure/typespec-rust/issues/192
|
|
1987
|
-
throw new AdapterError('UnsupportedTsp', 'cookie parameters are not supported', (_a =
|
|
2003
|
+
throw new AdapterError('UnsupportedTsp', 'cookie parameters are not supported', (_a = opParam.__raw) === null || _a === void 0 ? void 0 : _a.node);
|
|
1988
2004
|
case 'header':
|
|
1989
|
-
if (
|
|
2005
|
+
if (opParam.collectionFormat) {
|
|
1990
2006
|
if (paramType.kind !== 'Vec' && !isRefSlice(paramType)) {
|
|
1991
|
-
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for HeaderCollectionParameter`, (_b =
|
|
2007
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for HeaderCollectionParameter`, (_b = opParam.__raw) === null || _b === void 0 ? void 0 : _b.node);
|
|
1992
2008
|
}
|
|
1993
2009
|
let format;
|
|
1994
|
-
switch (
|
|
2010
|
+
switch (opParam.collectionFormat) {
|
|
1995
2011
|
case 'csv':
|
|
1996
2012
|
case 'simple':
|
|
1997
2013
|
format = 'csv';
|
|
@@ -1999,18 +2015,18 @@ export class Adapter {
|
|
|
1999
2015
|
case 'pipes':
|
|
2000
2016
|
case 'ssv':
|
|
2001
2017
|
case 'tsv':
|
|
2002
|
-
format =
|
|
2018
|
+
format = opParam.collectionFormat;
|
|
2003
2019
|
break;
|
|
2004
2020
|
default:
|
|
2005
|
-
throw new AdapterError('InternalError', `unexpected format ${
|
|
2021
|
+
throw new AdapterError('InternalError', `unexpected format ${opParam.collectionFormat} for HeaderCollectionParameter`, (_c = opParam.__raw) === null || _c === void 0 ? void 0 : _c.node);
|
|
2006
2022
|
}
|
|
2007
|
-
adaptedParam = new rust.HeaderCollectionParameter(paramName,
|
|
2023
|
+
adaptedParam = new rust.HeaderCollectionParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, format);
|
|
2008
2024
|
}
|
|
2009
|
-
else if (
|
|
2025
|
+
else if (opParam.serializedName === 'x-ms-meta') {
|
|
2010
2026
|
if (paramType.kind !== 'hashmap' && !isRefHashMap(paramType)) {
|
|
2011
|
-
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for header ${
|
|
2027
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for header ${opParam.serializedName}`, (_d = opParam.__raw) === null || _d === void 0 ? void 0 : _d.node);
|
|
2012
2028
|
}
|
|
2013
|
-
adaptedParam = new rust.HeaderHashMapParameter(paramName,
|
|
2029
|
+
adaptedParam = new rust.HeaderHashMapParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType);
|
|
2014
2030
|
}
|
|
2015
2031
|
else {
|
|
2016
2032
|
paramType = this.typeToWireType(paramType);
|
|
@@ -2021,28 +2037,28 @@ export class Adapter {
|
|
|
2021
2037
|
case 'slice':
|
|
2022
2038
|
case 'str':
|
|
2023
2039
|
case 'Vec':
|
|
2024
|
-
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar header ${
|
|
2040
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar header ${opParam.serializedName}`, (_e = opParam.__raw) === null || _e === void 0 ? void 0 : _e.node);
|
|
2025
2041
|
}
|
|
2026
|
-
adaptedParam = new rust.HeaderScalarParameter(paramName,
|
|
2027
|
-
adaptedParam.isApiVersion =
|
|
2042
|
+
adaptedParam = new rust.HeaderScalarParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType);
|
|
2043
|
+
adaptedParam.isApiVersion = opParam.isApiVersionParam;
|
|
2028
2044
|
}
|
|
2029
2045
|
break;
|
|
2030
2046
|
case 'path':
|
|
2031
2047
|
{
|
|
2032
2048
|
paramType = this.typeToWireType(paramType);
|
|
2033
2049
|
let style = 'simple';
|
|
2034
|
-
const tspStyleString =
|
|
2050
|
+
const tspStyleString = opParam.style;
|
|
2035
2051
|
if (!['simple', 'path', 'label', 'matrix'].includes(tspStyleString)) {
|
|
2036
|
-
throw new AdapterError('InternalError', `unsupported style ${tspStyleString} for parameter ${
|
|
2052
|
+
throw new AdapterError('InternalError', `unsupported style ${tspStyleString} for parameter ${opParam.serializedName}`, (_f = opParam.__raw) === null || _f === void 0 ? void 0 : _f.node);
|
|
2037
2053
|
}
|
|
2038
2054
|
else {
|
|
2039
2055
|
style = tspStyleString;
|
|
2040
2056
|
}
|
|
2041
2057
|
if (isRefSlice(paramType)) {
|
|
2042
|
-
adaptedParam = new rust.PathCollectionParameter(paramName,
|
|
2058
|
+
adaptedParam = new rust.PathCollectionParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, opParam.allowReserved, style, opParam.explode);
|
|
2043
2059
|
}
|
|
2044
2060
|
else if (paramType.kind === 'hashmap' || isRefHashMap(paramType)) {
|
|
2045
|
-
adaptedParam = new rust.PathHashMapParameter(paramName,
|
|
2061
|
+
adaptedParam = new rust.PathHashMapParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, opParam.allowReserved, style, opParam.explode);
|
|
2046
2062
|
}
|
|
2047
2063
|
else {
|
|
2048
2064
|
switch (paramType.kind) {
|
|
@@ -2051,25 +2067,25 @@ export class Adapter {
|
|
|
2051
2067
|
case 'slice':
|
|
2052
2068
|
case 'str':
|
|
2053
2069
|
case 'Vec':
|
|
2054
|
-
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar path ${
|
|
2070
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar path ${opParam.serializedName}`, (_g = opParam.__raw) === null || _g === void 0 ? void 0 : _g.node);
|
|
2055
2071
|
}
|
|
2056
|
-
adaptedParam = new rust.PathScalarParameter(paramName,
|
|
2072
|
+
adaptedParam = new rust.PathScalarParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, opParam.allowReserved, style);
|
|
2057
2073
|
}
|
|
2058
2074
|
}
|
|
2059
2075
|
break;
|
|
2060
2076
|
case 'query':
|
|
2061
2077
|
paramType = this.typeToWireType(paramType);
|
|
2062
2078
|
if (paramType.kind === 'Vec' || isRefSlice(paramType)) {
|
|
2063
|
-
let format =
|
|
2064
|
-
if (
|
|
2065
|
-
format =
|
|
2079
|
+
let format = opParam.explode ? 'multi' : 'csv';
|
|
2080
|
+
if (opParam.collectionFormat) {
|
|
2081
|
+
format = opParam.collectionFormat === 'simple' ? 'csv' : (opParam.collectionFormat === 'form' ? 'multi' : opParam.collectionFormat);
|
|
2066
2082
|
}
|
|
2067
2083
|
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
2068
|
-
adaptedParam = new rust.QueryCollectionParameter(paramName,
|
|
2084
|
+
adaptedParam = new rust.QueryCollectionParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, true, format);
|
|
2069
2085
|
}
|
|
2070
2086
|
else if (paramType.kind === 'hashmap' || isRefHashMap(paramType)) {
|
|
2071
2087
|
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
2072
|
-
adaptedParam = new rust.QueryHashMapParameter(paramName,
|
|
2088
|
+
adaptedParam = new rust.QueryHashMapParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, true, opParam.explode);
|
|
2073
2089
|
}
|
|
2074
2090
|
else {
|
|
2075
2091
|
switch (paramType.kind) {
|
|
@@ -2077,17 +2093,17 @@ export class Adapter {
|
|
|
2077
2093
|
case 'model':
|
|
2078
2094
|
case 'slice':
|
|
2079
2095
|
case 'str':
|
|
2080
|
-
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar query ${
|
|
2096
|
+
throw new AdapterError('InternalError', `unexpected kind ${paramType.kind} for scalar query ${opParam.serializedName}`, (_h = opParam.__raw) === null || _h === void 0 ? void 0 : _h.node);
|
|
2081
2097
|
}
|
|
2082
2098
|
// TODO: hard-coded encoding setting, https://github.com/Azure/typespec-azure/issues/1314
|
|
2083
|
-
adaptedParam = new rust.QueryScalarParameter(paramName,
|
|
2084
|
-
adaptedParam.isApiVersion =
|
|
2099
|
+
adaptedParam = new rust.QueryScalarParameter(paramName, opParam.serializedName, paramLoc, paramOptional, paramType, true);
|
|
2100
|
+
adaptedParam.isApiVersion = opParam.isApiVersionParam;
|
|
2085
2101
|
}
|
|
2086
2102
|
break;
|
|
2087
2103
|
}
|
|
2088
|
-
adaptedParam.docs = this.adaptDocs(
|
|
2104
|
+
adaptedParam.docs = this.adaptDocs(methodParam ? methodParam.summary : opParam.summary, methodParam ? methodParam.doc : opParam.doc);
|
|
2089
2105
|
if (paramLoc === 'client') {
|
|
2090
|
-
this.clientMethodParams.set(getClientParamsKey(
|
|
2106
|
+
this.clientMethodParams.set(getClientParamsKey(opParam), adaptedParam);
|
|
2091
2107
|
}
|
|
2092
2108
|
return adaptedParam;
|
|
2093
2109
|
}
|