Skip to content

Commit 23a18d1

Browse files
tsp, path allowReserved (#2904)
* tsp, path allowReserved * update for tsp-client 0.19.0
1 parent 5adcdad commit 23a18d1

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

eng/sdk/sync_sdk.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def update_emitter(package_json_path: str, use_dev_package: bool):
7777
logging.error('Failed to locate the dev package.')
7878

7979
logging.info('Update emitter-package-lock.json')
80-
subprocess.check_call(['tsp-client', '--generate-lock-file'], cwd=sdk_root)
80+
subprocess.check_call(['tsp-client', 'generate-lock-file'], cwd=sdk_root)
8181

8282

8383
def get_generated_folder_from_artifact(module_path: str, artifact: str, type: str) -> str:

typespec-extension/src/code-model-builder.ts

+25-23
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ import {
6767
getHttpOperationWithCache,
6868
getWireName,
6969
isApiVersion,
70-
isInternal,
7170
isSdkBuiltInKind,
7271
isSdkIntKind,
7372
listClients,
@@ -116,10 +115,8 @@ import {
116115
Visibility,
117116
getAuthentication,
118117
getHeaderFieldName,
119-
getHeaderFieldOptions,
120118
getPathParamName,
121119
getQueryParamName,
122-
getQueryParamOptions,
123120
getServers,
124121
getStatusCodeDescription,
125122
isHeader,
@@ -306,6 +303,7 @@ export class CodeModelBuilder {
306303
},
307304
},
308305
extensions: {
306+
// TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
309307
"x-ms-skip-url-encoding": schema instanceof UriSchema,
310308
},
311309
// // make the logic same as TCGC, which takes the server-side default of host as client-side default
@@ -401,14 +399,12 @@ export class CodeModelBuilder {
401399
return !this.options["flavor"] || this.options["flavor"].toLocaleLowerCase() === "azure";
402400
}
403401

404-
private isInternal(context: SdkContext, operation: Operation): boolean {
402+
private isInternal(operation: Operation): boolean {
405403
const access = getAccess(operation);
406404
if (access) {
407405
return access === "internal";
408406
} else {
409-
// TODO: deprecate "internal"
410-
// eslint-disable-next-line deprecation/deprecation
411-
return isInternal(context, operation);
407+
return false;
412408
}
413409
}
414410

@@ -759,7 +755,7 @@ export class CodeModelBuilder {
759755
this.sdkContext,
760756
operation,
761757
);
762-
codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
758+
codeModelOperation.internalApi = this.isInternal(operation);
763759

764760
const convenienceApiName = this.getConvenienceApiName(operation);
765761
let generateConvenienceApi: boolean = Boolean(convenienceApiName);
@@ -1072,14 +1068,22 @@ export class CodeModelBuilder {
10721068
schema = this.processSchemaFromSdkType(sdkType, param.param.name);
10731069
}
10741070

1075-
// skip-url-encoding
10761071
let extensions: { [id: string]: any } | undefined = undefined;
1072+
// skip-url-encoding
1073+
if (param.type === "path") {
1074+
if (param.allowReserved) {
1075+
extensions = extensions ?? {};
1076+
extensions["x-ms-skip-url-encoding"] = true;
1077+
}
1078+
}
1079+
// TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
10771080
if (
10781081
(param.type === "query" || param.type === "path") &&
10791082
param.param.type.kind === "Scalar" &&
10801083
schema instanceof UriSchema
10811084
) {
1082-
extensions = { "x-ms-skip-url-encoding": true };
1085+
extensions = extensions ?? {};
1086+
extensions["x-ms-skip-url-encoding"] = true;
10831087
}
10841088

10851089
if (this.supportsAdvancedVersioning()) {
@@ -1096,9 +1100,8 @@ export class CodeModelBuilder {
10961100
let explode = undefined;
10971101
if (param.param.type.kind === "Model" && isArrayModelType(this.program, param.param.type)) {
10981102
if (param.type === "query") {
1099-
const queryParamOptions = getQueryParamOptions(this.program, param.param);
11001103
// eslint-disable-next-line deprecation/deprecation
1101-
const queryParamFormat = queryParamOptions?.format;
1104+
const queryParamFormat = param?.format;
11021105
if (queryParamFormat) {
11031106
switch (queryParamFormat) {
11041107
case "csv":
@@ -1128,17 +1131,16 @@ export class CodeModelBuilder {
11281131
}
11291132
}
11301133
} else if (param.type === "header") {
1131-
const headerFieldOptions = getHeaderFieldOptions(this.program, param.param);
1132-
switch (headerFieldOptions?.format) {
1133-
case "csv":
1134-
style = SerializationStyle.Simple;
1135-
break;
1136-
1137-
default:
1138-
if (headerFieldOptions?.format) {
1139-
this.logWarning(`Unrecognized header parameter format: '${headerFieldOptions?.format}'.`);
1140-
}
1141-
break;
1134+
if (param.format) {
1135+
switch (param.format) {
1136+
case "csv":
1137+
style = SerializationStyle.Simple;
1138+
break;
1139+
1140+
default:
1141+
this.logWarning(`Unrecognized header parameter format: '${param.format}'.`);
1142+
break;
1143+
}
11421144
}
11431145
}
11441146
}

typespec-tests/tsp/server.tsp

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ namespace Cadl.ContosoServer {
5959
name: "Contoso.Sub.ContosoClient",
6060
service: Cadl.ContosoServer,
6161
})
62-
@route("/contoso/{group}")
62+
@route("/contoso/")
6363
interface ServerOp {
64-
get(@path group: url): OkResponse | NoContentResponse;
64+
get(@path(#{ allowReserved: true }) group: string): OkResponse | NoContentResponse;
6565
}
6666
}

0 commit comments

Comments
 (0)