Skip to content

Commit

Permalink
tsp, path allowReserved (#2904)
Browse files Browse the repository at this point in the history
* tsp, path allowReserved

* update for tsp-client 0.19.0
  • Loading branch information
weidongxu-microsoft authored Aug 9, 2024
1 parent 5adcdad commit 23a18d1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
2 changes: 1 addition & 1 deletion eng/sdk/sync_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def update_emitter(package_json_path: str, use_dev_package: bool):
logging.error('Failed to locate the dev package.')

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


def get_generated_folder_from_artifact(module_path: str, artifact: str, type: str) -> str:
Expand Down
48 changes: 25 additions & 23 deletions typespec-extension/src/code-model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ import {
getHttpOperationWithCache,
getWireName,
isApiVersion,
isInternal,
isSdkBuiltInKind,
isSdkIntKind,
listClients,
Expand Down Expand Up @@ -116,10 +115,8 @@ import {
Visibility,
getAuthentication,
getHeaderFieldName,
getHeaderFieldOptions,
getPathParamName,
getQueryParamName,
getQueryParamOptions,
getServers,
getStatusCodeDescription,
isHeader,
Expand Down Expand Up @@ -306,6 +303,7 @@ export class CodeModelBuilder {
},
},
extensions: {
// TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
"x-ms-skip-url-encoding": schema instanceof UriSchema,
},
// // make the logic same as TCGC, which takes the server-side default of host as client-side default
Expand Down Expand Up @@ -401,14 +399,12 @@ export class CodeModelBuilder {
return !this.options["flavor"] || this.options["flavor"].toLocaleLowerCase() === "azure";
}

private isInternal(context: SdkContext, operation: Operation): boolean {
private isInternal(operation: Operation): boolean {
const access = getAccess(operation);
if (access) {
return access === "internal";
} else {
// TODO: deprecate "internal"
// eslint-disable-next-line deprecation/deprecation
return isInternal(context, operation);
return false;
}
}

Expand Down Expand Up @@ -759,7 +755,7 @@ export class CodeModelBuilder {
this.sdkContext,
operation,
);
codeModelOperation.internalApi = this.isInternal(this.sdkContext, operation);
codeModelOperation.internalApi = this.isInternal(operation);

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

// skip-url-encoding
let extensions: { [id: string]: any } | undefined = undefined;
// skip-url-encoding
if (param.type === "path") {
if (param.allowReserved) {
extensions = extensions ?? {};
extensions["x-ms-skip-url-encoding"] = true;
}
}
// TODO: deprecate this logic of string/url for x-ms-skip-url-encoding
if (
(param.type === "query" || param.type === "path") &&
param.param.type.kind === "Scalar" &&
schema instanceof UriSchema
) {
extensions = { "x-ms-skip-url-encoding": true };
extensions = extensions ?? {};
extensions["x-ms-skip-url-encoding"] = true;
}

if (this.supportsAdvancedVersioning()) {
Expand All @@ -1096,9 +1100,8 @@ export class CodeModelBuilder {
let explode = undefined;
if (param.param.type.kind === "Model" && isArrayModelType(this.program, param.param.type)) {
if (param.type === "query") {
const queryParamOptions = getQueryParamOptions(this.program, param.param);
// eslint-disable-next-line deprecation/deprecation
const queryParamFormat = queryParamOptions?.format;
const queryParamFormat = param?.format;
if (queryParamFormat) {
switch (queryParamFormat) {
case "csv":
Expand Down Expand Up @@ -1128,17 +1131,16 @@ export class CodeModelBuilder {
}
}
} else if (param.type === "header") {
const headerFieldOptions = getHeaderFieldOptions(this.program, param.param);
switch (headerFieldOptions?.format) {
case "csv":
style = SerializationStyle.Simple;
break;

default:
if (headerFieldOptions?.format) {
this.logWarning(`Unrecognized header parameter format: '${headerFieldOptions?.format}'.`);
}
break;
if (param.format) {
switch (param.format) {
case "csv":
style = SerializationStyle.Simple;
break;

default:
this.logWarning(`Unrecognized header parameter format: '${param.format}'.`);
break;
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions typespec-tests/tsp/server.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ namespace Cadl.ContosoServer {
name: "Contoso.Sub.ContosoClient",
service: Cadl.ContosoServer,
})
@route("/contoso/{group}")
@route("/contoso/")
interface ServerOp {
get(@path group: url): OkResponse | NoContentResponse;
get(@path(#{ allowReserved: true }) group: string): OkResponse | NoContentResponse;
}
}

0 comments on commit 23a18d1

Please sign in to comment.