From c0e3ab66cbfea47935822538984b6042687ba12d Mon Sep 17 00:00:00 2001 From: tadelesh Date: Fri, 26 Apr 2024 10:53:07 +0800 Subject: [PATCH 1/8] prevent tcgc versioning projection --- packages/typespec-autorest/src/openapi.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 8e0b963484..ab517007af 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -163,6 +163,8 @@ const defaultOptions = { export async function $onEmit(context: EmitContext) { const resolvedOptions = { ...defaultOptions, ...context.options }; + // set api-version to all to prevent tcgc versioning projection + (context.options as any)["api-version"] = "all"; const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest"); const armTypesDir = interpolatePath( resolvedOptions["arm-types-dir"] ?? "{project-root}/../../common-types/resource-management", From 4e11568d4349449c937b21a4071f9887db087f5a Mon Sep 17 00:00:00 2001 From: tadelesh Date: Fri, 26 Apr 2024 10:55:02 +0800 Subject: [PATCH 2/8] changelog --- .chronus/changes/autorest_update-2024-3-26-10-54-52.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/autorest_update-2024-3-26-10-54-52.md diff --git a/.chronus/changes/autorest_update-2024-3-26-10-54-52.md b/.chronus/changes/autorest_update-2024-3-26-10-54-52.md new file mode 100644 index 0000000000..e29ab28821 --- /dev/null +++ b/.chronus/changes/autorest_update-2024-3-26-10-54-52.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-autorest" +--- + +prevent tcgc versioning projection \ No newline at end of file From a7c1e98805a3f5501b833206602cbd4a7cf6af69 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 29 Apr 2024 17:51:10 -0400 Subject: [PATCH 3/8] allow overriding of version behavior --- packages/typespec-autorest/src/openapi.ts | 1 - .../src/decorators.ts | 13 ++++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index ab517007af..7dc43bd433 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -164,7 +164,6 @@ const defaultOptions = { export async function $onEmit(context: EmitContext) { const resolvedOptions = { ...defaultOptions, ...context.options }; // set api-version to all to prevent tcgc versioning projection - (context.options as any)["api-version"] = "all"; const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest"); const armTypesDir = interpolatePath( resolvedOptions["arm-types-dir"] ?? "{project-root}/../../common-types/resource-management", diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 89cdf9e2b7..b64235b302 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -571,16 +571,27 @@ export function listOperationsInOperationGroup( return operations; } +interface CreateSdkContextOptions { + ignoreVersioning?: boolean; +} + export function createSdkContext< TOptions extends Record = SdkEmitterOptions, TServiceOperation extends SdkServiceOperation = SdkHttpOperation, ->(context: EmitContext, emitterName?: string): SdkContext { +>( + context: EmitContext, + emitterName?: string, + options?: CreateSdkContextOptions +): SdkContext { const diagnostics = createDiagnosticCollector(); const protocolOptions = true; // context.program.getLibraryOptions("generate-protocol-methods"); const convenienceOptions = true; // context.program.getLibraryOptions("generate-convenience-methods"); const generateProtocolMethods = context.options["generate-protocol-methods"] ?? protocolOptions; const generateConvenienceMethods = context.options["generate-convenience-methods"] ?? convenienceOptions; + if (options?.ignoreVersioning === false) { + context.options["api-version"] ?? "all"; + } const sdkContext: SdkContext = { program: context.program, emitContext: context, From fe111e3c35ea4214d44ff0269b9783863263de8b Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 30 Apr 2024 11:45:19 -0400 Subject: [PATCH 4/8] input timothee's comments --- packages/typespec-client-generator-core/src/decorators.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index b64235b302..10bdce29d2 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -572,7 +572,7 @@ export function listOperationsInOperationGroup( } interface CreateSdkContextOptions { - ignoreVersioning?: boolean; + readonly versionStrategy?: "ignore"; } export function createSdkContext< @@ -589,8 +589,8 @@ export function createSdkContext< const generateProtocolMethods = context.options["generate-protocol-methods"] ?? protocolOptions; const generateConvenienceMethods = context.options["generate-convenience-methods"] ?? convenienceOptions; - if (options?.ignoreVersioning === false) { - context.options["api-version"] ?? "all"; + if (options?.versionStrategy === "ignore") { + (context.options as any)["api-version"] = context.options["api-version"] ?? "all"; } const sdkContext: SdkContext = { program: context.program, From 4b1292519899aa67f81da11b2e2719f1a6d3b65d Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 30 Apr 2024 11:46:10 -0400 Subject: [PATCH 5/8] add changeset --- .chronus/changes/autorest_update-2024-3-30-11-46-5.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/autorest_update-2024-3-30-11-46-5.md diff --git a/.chronus/changes/autorest_update-2024-3-30-11-46-5.md b/.chronus/changes/autorest_update-2024-3-30-11-46-5.md new file mode 100644 index 0000000000..0c2ca38de2 --- /dev/null +++ b/.chronus/changes/autorest_update-2024-3-30-11-46-5.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +allow callers of createSdkContext to ignore default version projection \ No newline at end of file From 6870e53c39bd38219a3bd9a02389d9949ca33423 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 6 May 2024 15:15:44 +0800 Subject: [PATCH 6/8] add option --- packages/typespec-autorest/src/emit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-autorest/src/emit.ts b/packages/typespec-autorest/src/emit.ts index 4e6840fee8..8ebff4070e 100644 --- a/packages/typespec-autorest/src/emit.ts +++ b/packages/typespec-autorest/src/emit.ts @@ -71,7 +71,7 @@ export async function $onEmit(context: EmitContext) { const tracer = getTracer(context.program); tracer.trace("options", JSON.stringify(options, null, 2)); - const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest"); + const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest", { versionStrategy: "ignore" }); await emitAllServiceAtAllVersions(context.program, tcgcSdkContext, options); } From 95360c75194c597e32c0ab3b873b6b3c8c6e9cfa Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 6 May 2024 15:24:16 +0800 Subject: [PATCH 7/8] format --- packages/typespec-autorest/src/emit.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/typespec-autorest/src/emit.ts b/packages/typespec-autorest/src/emit.ts index 8ebff4070e..40e34c700d 100644 --- a/packages/typespec-autorest/src/emit.ts +++ b/packages/typespec-autorest/src/emit.ts @@ -71,7 +71,9 @@ export async function $onEmit(context: EmitContext) { const tracer = getTracer(context.program); tracer.trace("options", JSON.stringify(options, null, 2)); - const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest", { versionStrategy: "ignore" }); + const tcgcSdkContext = createSdkContext(context, "@azure-tools/typespec-autorest", { + versionStrategy: "ignore", + }); await emitAllServiceAtAllVersions(context.program, tcgcSdkContext, options); } From 02815b63b5f5a0b1855d39f11f63319609374fe8 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Mon, 6 May 2024 15:52:18 +0800 Subject: [PATCH 8/8] refine logic --- packages/typespec-client-generator-core/src/decorators.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 10bdce29d2..91d1988709 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -589,9 +589,6 @@ export function createSdkContext< const generateProtocolMethods = context.options["generate-protocol-methods"] ?? protocolOptions; const generateConvenienceMethods = context.options["generate-convenience-methods"] ?? convenienceOptions; - if (options?.versionStrategy === "ignore") { - (context.options as any)["api-version"] = context.options["api-version"] ?? "all"; - } const sdkContext: SdkContext = { program: context.program, emitContext: context, @@ -605,7 +602,7 @@ export function createSdkContext< packageName: context.options["package-name"], flattenUnionAsEnum: context.options["flatten-union-as-enum"] ?? true, diagnostics: diagnostics.diagnostics, - apiVersion: context.options["api-version"], + apiVersion: options?.versionStrategy === "ignore" ? "all" : context.options["api-version"], originalProgram: context.program, }; sdkContext.experimental_sdkPackage = getSdkPackage(sdkContext);