From 0e4606af6c52f34520c65a685a8f53b06a109dbe Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 24 Jul 2024 13:20:57 +0800 Subject: [PATCH 01/21] wip --- .../lib/decorators.tsp | 17 +++++++++++++++++ .../src/decorators.ts | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index 324590da89..b04920ed68 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -419,3 +419,20 @@ extern dec access( */ #deprecated "@flattenProperty decorator is not recommended to use." extern dec flattenProperty(target: ModelProperty, scope?: valueof string); + +namespace Azure.ClientGenerator.Core.Csharp { + /** + * Whether a model needs the custom JSON converter, this is only used for backward compatibility. + * @param value Whether to generate the model needs the custom JSON converter or not. + * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. + * + * @example + * ```typespec + * @hasJSONConverter(true) + * model MyModel { + * prop: string; + * } + * ``` + */ + extern dec hasJSONConverter(target: Model, value?: valueof boolean, scope?: "csharp"); +} diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 71388e1393..5c5529839e 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -1048,3 +1048,12 @@ export function getClientNameOverride( ): string | undefined { return getScopedDecoratorData(context, clientNameKey, entity, languageScope); } + +const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); +export const $hasJSONConverter: DecoratorFunction = ( + context: DecoratorContext, + entity: Model, + value?: boolean, + scope?: LanguageScopes) => { + setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, value, scope); +} From ddcdc827d1ff787cefecad86db36aa2046202d20 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 24 Jul 2024 15:46:44 +0800 Subject: [PATCH 02/21] wip --- .../lib/csharp.decorators.tsp | 18 +++++++ .../lib/decorators.tsp | 17 ------- .../src/csharp.decorators.ts | 15 ++++++ .../src/decorators.ts | 51 +------------------ .../src/index.ts | 1 + .../src/internal-utils.ts | 43 ++++++++++++++++ .../types/general-decorators-list.test.ts | 19 +++++++ 7 files changed, 97 insertions(+), 67 deletions(-) create mode 100644 packages/typespec-client-generator-core/lib/csharp.decorators.tsp create mode 100644 packages/typespec-client-generator-core/src/csharp.decorators.ts diff --git a/packages/typespec-client-generator-core/lib/csharp.decorators.tsp b/packages/typespec-client-generator-core/lib/csharp.decorators.tsp new file mode 100644 index 0000000000..977f249e09 --- /dev/null +++ b/packages/typespec-client-generator-core/lib/csharp.decorators.tsp @@ -0,0 +1,18 @@ +using TypeSpec.Reflection; + +namespace Azure.ClientGenerator.Core.Csharp; + +/** + * Whether a model needs the custom JSON converter, this is only used for backward compatibility. + * @param value Whether to generate the model needs the custom JSON converter or not. + * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. + * + * @example + * ```typespec + * @hasJSONConverter(true) + * model MyModel { + * prop: string; + * } + * ``` + */ +extern dec hasJSONConverter(target: Model, value?: valueof boolean, scope?: "csharp"); diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index b04920ed68..324590da89 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -419,20 +419,3 @@ extern dec access( */ #deprecated "@flattenProperty decorator is not recommended to use." extern dec flattenProperty(target: ModelProperty, scope?: valueof string); - -namespace Azure.ClientGenerator.Core.Csharp { - /** - * Whether a model needs the custom JSON converter, this is only used for backward compatibility. - * @param value Whether to generate the model needs the custom JSON converter or not. - * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. - * - * @example - * ```typespec - * @hasJSONConverter(true) - * model MyModel { - * prop: string; - * } - * ``` - */ - extern dec hasJSONConverter(target: Model, value?: valueof boolean, scope?: "csharp"); -} diff --git a/packages/typespec-client-generator-core/src/csharp.decorators.ts b/packages/typespec-client-generator-core/src/csharp.decorators.ts new file mode 100644 index 0000000000..270e319387 --- /dev/null +++ b/packages/typespec-client-generator-core/src/csharp.decorators.ts @@ -0,0 +1,15 @@ +import {DecoratorFunction, DecoratorContext, Model} from "@typespec/compiler"; +import {createStateSymbol} from "./lib.js"; +import {setScopedDecoratorData} from "./internal-utils.js"; +import {LanguageScopes} from "./interfaces.js"; + +export const namespace = "Azure.ClientGenerator.Core.Csharp"; + +const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); +export const $hasJSONConverter: DecoratorFunction = ( + context: DecoratorContext, + entity: Model, + value?: boolean, + scope?: LanguageScopes) => { + setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, value, scope); +} diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 5c5529839e..10c260d73d 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -25,7 +25,6 @@ import { isTemplateDeclarationOrInstance, listServices, projectProgram, - validateDecoratorUniqueOnNode, } from "@typespec/compiler"; import { isHeader } from "@typespec/http"; import { buildVersionProjections, getVersions } from "@typespec/versioning"; @@ -56,7 +55,7 @@ import { TCGCContext, UsageFlags, } from "./interfaces.js"; -import { AllScopes, clientNameKey, parseEmitterName } from "./internal-utils.js"; +import { AllScopes, clientNameKey, parseEmitterName, setScopedDecoratorData } from "./internal-utils.js"; import { createStateSymbol, reportDiagnostic } from "./lib.js"; import { getSdkPackage } from "./package.js"; import { getLibraryName } from "./public-utils.js"; @@ -91,45 +90,6 @@ function listScopedDecoratorData(context: TCGCContext, key: symbol): any[] { .flatMap((targetEntry) => targetEntry[context.emitterName] ?? targetEntry[AllScopes]); } -function setScopedDecoratorData( - context: DecoratorContext, - decorator: DecoratorFunction, - key: symbol, - target: Type, - value: unknown, - scope?: LanguageScopes, - transitivity: boolean = false -): boolean { - const targetEntry = context.program.stateMap(key).get(target); - const splitScopes = scope?.split(",").map((s) => s.trim()) || [AllScopes]; - - // If target doesn't exist in decorator map, create a new entry - if (!targetEntry) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, newObject); - return true; - } - - // If target exists, but there's a specified scope and it doesn't exist in the target entry, add mapping of scope and value to target entry - const scopes = Reflect.ownKeys(targetEntry); - if (!scopes.includes(AllScopes) && scope && !splitScopes.some((s) => scopes.includes(s))) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); - return true; - } - // we only want to allow multiple decorators if they each specify a different scope - if (!transitivity) { - validateDecoratorUniqueOnNode(context, target, decorator); - return false; - } - // for transitivity situation, we could allow scope extension - if (!scopes.includes(AllScopes) && !scope) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); - } - return false; -} - const clientKey = createStateSymbol("client"); function isArm(service: Namespace): boolean { @@ -1048,12 +1008,3 @@ export function getClientNameOverride( ): string | undefined { return getScopedDecoratorData(context, clientNameKey, entity, languageScope); } - -const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); -export const $hasJSONConverter: DecoratorFunction = ( - context: DecoratorContext, - entity: Model, - value?: boolean, - scope?: LanguageScopes) => { - setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, value, scope); -} diff --git a/packages/typespec-client-generator-core/src/index.ts b/packages/typespec-client-generator-core/src/index.ts index 132e5c11c2..12ac9791d2 100644 --- a/packages/typespec-client-generator-core/src/index.ts +++ b/packages/typespec-client-generator-core/src/index.ts @@ -1,4 +1,5 @@ export * from "./decorators.js"; +// export { $hasJSONConverter } from "./csharp.decorators.js"; export * from "./interfaces.js"; export * from "./lib.js"; export * from "./public-utils.js"; diff --git a/packages/typespec-client-generator-core/src/internal-utils.ts b/packages/typespec-client-generator-core/src/internal-utils.ts index 151930ee85..a5c38901f6 100644 --- a/packages/typespec-client-generator-core/src/internal-utils.ts +++ b/packages/typespec-client-generator-core/src/internal-utils.ts @@ -2,6 +2,8 @@ import { BooleanLiteral, createDiagnosticCollector, Diagnostic, + DecoratorContext, + DecoratorFunction, getDeprecationDetails, getDoc, getNamespaceFullName, @@ -20,11 +22,13 @@ import { Type, Union, Value, + validateDecoratorUniqueOnNode, } from "@typespec/compiler"; import { HttpOperation, HttpOperationResponseContent, HttpStatusCodeRange } from "@typespec/http"; import { getAddedOnVersions, getRemovedOnVersions, getVersions } from "@typespec/versioning"; import { DecoratorInfo, + LanguageScopes, SdkBuiltInType, SdkClient, SdkEnumType, @@ -526,3 +530,42 @@ export function isJsonContentType(contentType: string): boolean { const regex = new RegExp(/^(application|text)\/(.+\+)?json$/); return regex.test(contentType); } + +export function setScopedDecoratorData( + context: DecoratorContext, + decorator: DecoratorFunction, + key: symbol, + target: Type, + value: unknown, + scope?: LanguageScopes, + transitivity: boolean = false +): boolean { + const targetEntry = context.program.stateMap(key).get(target); + const splitScopes = scope?.split(",").map((s) => s.trim()) || [AllScopes]; + + // If target doesn't exist in decorator map, create a new entry + if (!targetEntry) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, newObject); + return true; + } + + // If target exists, but there's a specified scope and it doesn't exist in the target entry, add mapping of scope and value to target entry + const scopes = Reflect.ownKeys(targetEntry); + if (!scopes.includes(AllScopes) && scope && !splitScopes.some((s) => scopes.includes(s))) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); + return true; + } + // we only want to allow multiple decorators if they each specify a different scope + if (!transitivity) { + validateDecoratorUniqueOnNode(context, target, decorator); + return false; + } + // for transitivity situation, we could allow scope extension + if (!scopes.includes(AllScopes) && !scope) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); + } + return false; +} diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index ddf113dcae..0224768b4e 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -342,4 +342,23 @@ describe("typespec-client-generator-core: general decorators list", () => { ]); }); }); + + describe("csharp only decorator", () => { + it("@hasJSONConverter", async function () { + runner = await createSdkTestRunner({}, + { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.Csharp\\.@hasJSONConverter"] }); + + await runner.compileWithBuiltInService(` + @hasJSONConverter(true) + model A { + id: string; + } + `); + + const models = runner.context.sdkPackage.models; + strictEqual(models.length, 1); + deepStrictEqual(models[0].decorators, [{ name: "TypeSpec.@error", arguments: {} }]); + expectDiagnostics(runner.context.diagnostics, []); + }); + }); }); From a4ba0b31efc8c1eb7850491e1b664754c248f299 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 24 Jul 2024 16:52:24 +0800 Subject: [PATCH 03/21] add changelog and fix format --- .../json-converter-2024-6-24-16-48-41.md | 7 +++++++ .../lib/csharp.decorators.tsp | 9 ++++----- .../src/csharp.decorators.ts | 18 +++++++++--------- .../src/decorators.ts | 9 +++++++-- .../src/internal-utils.ts | 4 ++-- .../test/types/general-decorators-list.test.ts | 16 ++++++++++------ 6 files changed, 39 insertions(+), 24 deletions(-) create mode 100644 .chronus/changes/json-converter-2024-6-24-16-48-41.md diff --git a/.chronus/changes/json-converter-2024-6-24-16-48-41.md b/.chronus/changes/json-converter-2024-6-24-16-48-41.md new file mode 100644 index 0000000000..ea9e8ae947 --- /dev/null +++ b/.chronus/changes/json-converter-2024-6-24-16-48-41.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +Add `@hasJSONConverter` for csharp only to indicate if JSON converter is needed \ No newline at end of file diff --git a/packages/typespec-client-generator-core/lib/csharp.decorators.tsp b/packages/typespec-client-generator-core/lib/csharp.decorators.tsp index 977f249e09..5339a9cde7 100644 --- a/packages/typespec-client-generator-core/lib/csharp.decorators.tsp +++ b/packages/typespec-client-generator-core/lib/csharp.decorators.tsp @@ -1,18 +1,17 @@ -using TypeSpec.Reflection; +namespace Azure.ClientGenerator.Core.CSharp; -namespace Azure.ClientGenerator.Core.Csharp; +using TypeSpec.Reflection; /** * Whether a model needs the custom JSON converter, this is only used for backward compatibility. - * @param value Whether to generate the model needs the custom JSON converter or not. * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. * * @example * ```typespec - * @hasJSONConverter(true) + * @hasJSONConverter * model MyModel { * prop: string; * } * ``` */ -extern dec hasJSONConverter(target: Model, value?: valueof boolean, scope?: "csharp"); +extern dec hasJSONConverter(target: Model, scope?: "csharp"); diff --git a/packages/typespec-client-generator-core/src/csharp.decorators.ts b/packages/typespec-client-generator-core/src/csharp.decorators.ts index 270e319387..cb6801be13 100644 --- a/packages/typespec-client-generator-core/src/csharp.decorators.ts +++ b/packages/typespec-client-generator-core/src/csharp.decorators.ts @@ -1,15 +1,15 @@ -import {DecoratorFunction, DecoratorContext, Model} from "@typespec/compiler"; -import {createStateSymbol} from "./lib.js"; -import {setScopedDecoratorData} from "./internal-utils.js"; -import {LanguageScopes} from "./interfaces.js"; +import { DecoratorContext, DecoratorFunction, Model } from "@typespec/compiler"; +import { LanguageScopes } from "./interfaces.js"; +import { setScopedDecoratorData } from "./internal-utils.js"; +import { createStateSymbol } from "./lib.js"; -export const namespace = "Azure.ClientGenerator.Core.Csharp"; +export const namespace = "Azure.ClientGenerator.Core.CSharp"; const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); export const $hasJSONConverter: DecoratorFunction = ( context: DecoratorContext, entity: Model, - value?: boolean, - scope?: LanguageScopes) => { - setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, value, scope); -} + scope?: LanguageScopes +) => { + setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, true, scope); +}; diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 10c260d73d..52a450b401 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -55,7 +55,12 @@ import { TCGCContext, UsageFlags, } from "./interfaces.js"; -import { AllScopes, clientNameKey, parseEmitterName, setScopedDecoratorData } from "./internal-utils.js"; +import { + AllScopes, + clientNameKey, + parseEmitterName, + setScopedDecoratorData, +} from "./internal-utils.js"; import { createStateSymbol, reportDiagnostic } from "./lib.js"; import { getSdkPackage } from "./package.js"; import { getLibraryName } from "./public-utils.js"; @@ -117,7 +122,7 @@ export const $client: ClientDecorator = ( const service = explicitService?.kind === "Namespace" ? explicitService - : (findClientService(context.program, target) ?? (target as any)); + : findClientService(context.program, target) ?? (target as any); if (!name.endsWith("Client")) { reportDiagnostic(context.program, { code: "client-name", diff --git a/packages/typespec-client-generator-core/src/internal-utils.ts b/packages/typespec-client-generator-core/src/internal-utils.ts index a5c38901f6..7049ac5c0e 100644 --- a/packages/typespec-client-generator-core/src/internal-utils.ts +++ b/packages/typespec-client-generator-core/src/internal-utils.ts @@ -1,9 +1,9 @@ import { BooleanLiteral, createDiagnosticCollector, - Diagnostic, DecoratorContext, DecoratorFunction, + Diagnostic, getDeprecationDetails, getDoc, getNamespaceFullName, @@ -21,8 +21,8 @@ import { StringLiteral, Type, Union, - Value, validateDecoratorUniqueOnNode, + Value, } from "@typespec/compiler"; import { HttpOperation, HttpOperationResponseContent, HttpStatusCodeRange } from "@typespec/http"; import { getAddedOnVersions, getRemovedOnVersions, getVersions } from "@typespec/versioning"; diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 0224768b4e..9e0ffdaa5c 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -342,22 +342,26 @@ describe("typespec-client-generator-core: general decorators list", () => { ]); }); }); - + describe("csharp only decorator", () => { it("@hasJSONConverter", async function () { - runner = await createSdkTestRunner({}, - { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.Csharp\\.@hasJSONConverter"] }); + runner = await createSdkTestRunner( + {}, + { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJSONConverter"] } + ); await runner.compileWithBuiltInService(` - @hasJSONConverter(true) + @hasJSONConverter model A { id: string; } `); - + const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); - deepStrictEqual(models[0].decorators, [{ name: "TypeSpec.@error", arguments: {} }]); + deepStrictEqual(models[0].decorators, [ + { name: "Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJSONConverter", arguments: {} }, + ]); expectDiagnostics(runner.context.diagnostics, []); }); }); From 5668ad7025dd91116ec2ea267c590d3518f77af0 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 10:39:03 +0800 Subject: [PATCH 04/21] set sub-namespace for decorator --- .../Azure.ClientGenerator.Core.CSharp.ts} | 12 +++++++----- .../Azure.ClientGenerator.Core.CSharp.ts-test.ts | 12 ++++++++++++ .../lib/decorators.tsp | 16 ++++++++++++++++ .../src/csharp.decorators.ts | 15 --------------- .../src/decorators.ts | 12 ++++++++++++ .../test/test-host.ts | 1 + .../test/types/general-decorators-list.test.ts | 4 +++- 7 files changed, 51 insertions(+), 21 deletions(-) rename packages/typespec-client-generator-core/{lib/csharp.decorators.tsp => generated-defs/Azure.ClientGenerator.Core.CSharp.ts} (64%) create mode 100644 packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts delete mode 100644 packages/typespec-client-generator-core/src/csharp.decorators.ts diff --git a/packages/typespec-client-generator-core/lib/csharp.decorators.tsp b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts similarity index 64% rename from packages/typespec-client-generator-core/lib/csharp.decorators.tsp rename to packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts index 5339a9cde7..f9181edb2b 100644 --- a/packages/typespec-client-generator-core/lib/csharp.decorators.tsp +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts @@ -1,11 +1,9 @@ -namespace Azure.ClientGenerator.Core.CSharp; - -using TypeSpec.Reflection; +import type { DecoratorContext, Model, Type } from "@typespec/compiler"; /** * Whether a model needs the custom JSON converter, this is only used for backward compatibility. - * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. * + * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. * @example * ```typespec * @hasJSONConverter @@ -14,4 +12,8 @@ using TypeSpec.Reflection; * } * ``` */ -extern dec hasJSONConverter(target: Model, scope?: "csharp"); +export type HasJSONConverterDecorator = ( + context: DecoratorContext, + target: Model, + scope?: Type +) => void; diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts new file mode 100644 index 0000000000..c0af9d9c18 --- /dev/null +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts @@ -0,0 +1,12 @@ +/** An error here would mean that the decorator is not exported or doesn't have the right name. */ +import { $hasJSONConverter } from "@azure-tools/typespec-client-generator-core"; +import type { HasJSONConverterDecorator } from "./Azure.ClientGenerator.Core.CSharp.js"; + +type Decorators = { + $hasJSONConverter: HasJSONConverterDecorator; +}; + +/** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ +const _: Decorators = { + $hasJSONConverter, +}; diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index 324590da89..1c7f7f9b27 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -419,3 +419,19 @@ extern dec access( */ #deprecated "@flattenProperty decorator is not recommended to use." extern dec flattenProperty(target: ModelProperty, scope?: valueof string); + +namespace Azure.ClientGenerator.Core.CSharp { + /** + * Whether a model needs the custom JSON converter, this is only used for backward compatibility. + * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. + * + * @example + * ```typespec + * @hasJSONConverter + * model MyModel { + * prop: string; + * } + * ``` + */ + extern dec hasJSONConverter(target: Model, scope?: "csharp"); +} diff --git a/packages/typespec-client-generator-core/src/csharp.decorators.ts b/packages/typespec-client-generator-core/src/csharp.decorators.ts deleted file mode 100644 index cb6801be13..0000000000 --- a/packages/typespec-client-generator-core/src/csharp.decorators.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { DecoratorContext, DecoratorFunction, Model } from "@typespec/compiler"; -import { LanguageScopes } from "./interfaces.js"; -import { setScopedDecoratorData } from "./internal-utils.js"; -import { createStateSymbol } from "./lib.js"; - -export const namespace = "Azure.ClientGenerator.Core.CSharp"; - -const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); -export const $hasJSONConverter: DecoratorFunction = ( - context: DecoratorContext, - entity: Model, - scope?: LanguageScopes -) => { - setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, true, scope); -}; diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 52a450b401..964647a813 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -25,6 +25,7 @@ import { isTemplateDeclarationOrInstance, listServices, projectProgram, + setTypeSpecNamespace, } from "@typespec/compiler"; import { isHeader } from "@typespec/http"; import { buildVersionProjections, getVersions } from "@typespec/versioning"; @@ -1013,3 +1014,14 @@ export function getClientNameOverride( ): string | undefined { return getScopedDecoratorData(context, clientNameKey, entity, languageScope); } + +const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); +export const $hasJSONConverter: DecoratorFunction = ( + context: DecoratorContext, + entity: Model, + scope?: LanguageScopes +) => { + setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, true, scope); +}; + +setTypeSpecNamespace("CSharp", $hasJSONConverter); diff --git a/packages/typespec-client-generator-core/test/test-host.ts b/packages/typespec-client-generator-core/test/test-host.ts index 2ec027c6c0..75379138ef 100644 --- a/packages/typespec-client-generator-core/test/test-host.ts +++ b/packages/typespec-client-generator-core/test/test-host.ts @@ -75,6 +75,7 @@ export async function createSdkTestRunner( const host = await createSdkTestHost(options); let autoUsings = [ "Azure.ClientGenerator.Core", + "Azure.ClientGenerator.Core.CSharp", "TypeSpec.Rest", "TypeSpec.Http", "TypeSpec.Versioning", diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 9e0ffdaa5c..97eb1b860f 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -355,12 +355,14 @@ describe("typespec-client-generator-core: general decorators list", () => { model A { id: string; } + + op test(): A; `); const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJSONConverter", arguments: {} }, + { name: "Azure.ClientGenerator.Core.CSharp.@hasJSONConverter", arguments: {} }, ]); expectDiagnostics(runner.context.diagnostics, []); }); From 8f35f17f3ea33c9b45c45b76493269f478970906 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 10:49:52 +0800 Subject: [PATCH 05/21] clean up --- .../src/decorators.ts | 49 ++++++++++++++++--- .../src/index.ts | 1 - .../src/internal-utils.ts | 43 ---------------- 3 files changed, 42 insertions(+), 51 deletions(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 964647a813..df487e01ef 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -25,6 +25,7 @@ import { isTemplateDeclarationOrInstance, listServices, projectProgram, + validateDecoratorUniqueOnNode, setTypeSpecNamespace, } from "@typespec/compiler"; import { isHeader } from "@typespec/http"; @@ -56,12 +57,7 @@ import { TCGCContext, UsageFlags, } from "./interfaces.js"; -import { - AllScopes, - clientNameKey, - parseEmitterName, - setScopedDecoratorData, -} from "./internal-utils.js"; +import { AllScopes, clientNameKey, parseEmitterName } from "./internal-utils.js"; import { createStateSymbol, reportDiagnostic } from "./lib.js"; import { getSdkPackage } from "./package.js"; import { getLibraryName } from "./public-utils.js"; @@ -96,6 +92,45 @@ function listScopedDecoratorData(context: TCGCContext, key: symbol): any[] { .flatMap((targetEntry) => targetEntry[context.emitterName] ?? targetEntry[AllScopes]); } +function setScopedDecoratorData( + context: DecoratorContext, + decorator: DecoratorFunction, + key: symbol, + target: Type, + value: unknown, + scope?: LanguageScopes, + transitivity: boolean = false +): boolean { + const targetEntry = context.program.stateMap(key).get(target); + const splitScopes = scope?.split(",").map((s) => s.trim()) || [AllScopes]; + + // If target doesn't exist in decorator map, create a new entry + if (!targetEntry) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, newObject); + return true; + } + + // If target exists, but there's a specified scope and it doesn't exist in the target entry, add mapping of scope and value to target entry + const scopes = Reflect.ownKeys(targetEntry); + if (!scopes.includes(AllScopes) && scope && !splitScopes.some((s) => scopes.includes(s))) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); + return true; + } + // we only want to allow multiple decorators if they each specify a different scope + if (!transitivity) { + validateDecoratorUniqueOnNode(context, target, decorator); + return false; + } + // for transitivity situation, we could allow scope extension + if (!scopes.includes(AllScopes) && !scope) { + const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); + context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); + } + return false; +} + const clientKey = createStateSymbol("client"); function isArm(service: Namespace): boolean { @@ -123,7 +158,7 @@ export const $client: ClientDecorator = ( const service = explicitService?.kind === "Namespace" ? explicitService - : findClientService(context.program, target) ?? (target as any); + : (findClientService(context.program, target) ?? (target as any)); if (!name.endsWith("Client")) { reportDiagnostic(context.program, { code: "client-name", diff --git a/packages/typespec-client-generator-core/src/index.ts b/packages/typespec-client-generator-core/src/index.ts index 12ac9791d2..132e5c11c2 100644 --- a/packages/typespec-client-generator-core/src/index.ts +++ b/packages/typespec-client-generator-core/src/index.ts @@ -1,5 +1,4 @@ export * from "./decorators.js"; -// export { $hasJSONConverter } from "./csharp.decorators.js"; export * from "./interfaces.js"; export * from "./lib.js"; export * from "./public-utils.js"; diff --git a/packages/typespec-client-generator-core/src/internal-utils.ts b/packages/typespec-client-generator-core/src/internal-utils.ts index 7049ac5c0e..151930ee85 100644 --- a/packages/typespec-client-generator-core/src/internal-utils.ts +++ b/packages/typespec-client-generator-core/src/internal-utils.ts @@ -1,8 +1,6 @@ import { BooleanLiteral, createDiagnosticCollector, - DecoratorContext, - DecoratorFunction, Diagnostic, getDeprecationDetails, getDoc, @@ -21,14 +19,12 @@ import { StringLiteral, Type, Union, - validateDecoratorUniqueOnNode, Value, } from "@typespec/compiler"; import { HttpOperation, HttpOperationResponseContent, HttpStatusCodeRange } from "@typespec/http"; import { getAddedOnVersions, getRemovedOnVersions, getVersions } from "@typespec/versioning"; import { DecoratorInfo, - LanguageScopes, SdkBuiltInType, SdkClient, SdkEnumType, @@ -530,42 +526,3 @@ export function isJsonContentType(contentType: string): boolean { const regex = new RegExp(/^(application|text)\/(.+\+)?json$/); return regex.test(contentType); } - -export function setScopedDecoratorData( - context: DecoratorContext, - decorator: DecoratorFunction, - key: symbol, - target: Type, - value: unknown, - scope?: LanguageScopes, - transitivity: boolean = false -): boolean { - const targetEntry = context.program.stateMap(key).get(target); - const splitScopes = scope?.split(",").map((s) => s.trim()) || [AllScopes]; - - // If target doesn't exist in decorator map, create a new entry - if (!targetEntry) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, newObject); - return true; - } - - // If target exists, but there's a specified scope and it doesn't exist in the target entry, add mapping of scope and value to target entry - const scopes = Reflect.ownKeys(targetEntry); - if (!scopes.includes(AllScopes) && scope && !splitScopes.some((s) => scopes.includes(s))) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); - return true; - } - // we only want to allow multiple decorators if they each specify a different scope - if (!transitivity) { - validateDecoratorUniqueOnNode(context, target, decorator); - return false; - } - // for transitivity situation, we could allow scope extension - if (!scopes.includes(AllScopes) && !scope) { - const newObject = Object.fromEntries(splitScopes.map((scope) => [scope, value])); - context.program.stateMap(key).set(target, { ...targetEntry, ...newObject }); - } - return false; -} From 8cb7069ba7cc35aa37c34ad1263be12775185b16 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 11:06:41 +0800 Subject: [PATCH 06/21] fix format --- packages/typespec-autorest/src/openapi.ts | 2 +- packages/typespec-client-generator-core/src/decorators.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 6ff51569a0..73450bca0d 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -1030,7 +1030,7 @@ export async function getOpenAPIForService( const encodedName = resolveEncodedName(program, type, "application/json"); // Pick the value set via `encodedName` or default back to the legacy projection otherwise. // `resolveEncodedName` will return the original name if no @encodedName so we have to do that check - return encodedName === type.name ? (viaProjection ?? type.name) : encodedName; + return encodedName === type.name ? viaProjection ?? type.name : encodedName; } function emitEndpointParameters(methodParams: HttpOperationParameters, visibility: Visibility) { diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index df487e01ef..bcfa75bf62 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -25,8 +25,8 @@ import { isTemplateDeclarationOrInstance, listServices, projectProgram, - validateDecoratorUniqueOnNode, setTypeSpecNamespace, + validateDecoratorUniqueOnNode, } from "@typespec/compiler"; import { isHeader } from "@typespec/http"; import { buildVersionProjections, getVersions } from "@typespec/versioning"; @@ -158,7 +158,7 @@ export const $client: ClientDecorator = ( const service = explicitService?.kind === "Namespace" ? explicitService - : (findClientService(context.program, target) ?? (target as any)); + : findClientService(context.program, target) ?? (target as any); if (!name.endsWith("Client")) { reportDiagnostic(context.program, { code: "client-name", From 6d373152dd8c8c081fa880277561fabefc2cbf72 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 11:57:39 +0800 Subject: [PATCH 07/21] fix format --- packages/typespec-autorest/src/openapi.ts | 2 +- packages/typespec-client-generator-core/src/decorators.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index 73450bca0d..6ff51569a0 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -1030,7 +1030,7 @@ export async function getOpenAPIForService( const encodedName = resolveEncodedName(program, type, "application/json"); // Pick the value set via `encodedName` or default back to the legacy projection otherwise. // `resolveEncodedName` will return the original name if no @encodedName so we have to do that check - return encodedName === type.name ? viaProjection ?? type.name : encodedName; + return encodedName === type.name ? (viaProjection ?? type.name) : encodedName; } function emitEndpointParameters(methodParams: HttpOperationParameters, visibility: Visibility) { diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 9b6b472567..b2e3d86d9f 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -165,7 +165,7 @@ export const $client: ClientDecorator = ( const service = explicitService?.kind === "Namespace" ? explicitService - : findClientService(context.program, target) ?? (target as any); + : (findClientService(context.program, target) ?? (target as any)); if (!name.endsWith("Client")) { reportDiagnostic(context.program, { code: "client-name", From 1d26dfbd1246f010294f7834d0a6c99693586620 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 12:52:41 +0800 Subject: [PATCH 08/21] update doc --- .../reference/decorators.md | 49 +++++++++++-------- .../reference/index.mdx | 6 +++ .../typespec-client-generator-core/README.md | 41 ++++++++++++---- 3 files changed, 66 insertions(+), 30 deletions(-) diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index d1cd81aaf6..9948d77fb9 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -201,10 +201,6 @@ interface MyInterface {} ### `@clientFormat` {#@Azure.ClientGenerator.Core.clientFormat} -:::warning -**Deprecated**: @clientFormat decorator is deprecated. Use `@encode` decorator in `@typespec/compiler` instead. -::: - DEPRECATED: Use `@encode` decorator in `@typespec/compiler` instead. Can be used to explain the client type that the current TYPESPEC @@ -295,10 +291,6 @@ op test: void; ### `@exclude` {#@Azure.ClientGenerator.Core.exclude} -:::warning -**Deprecated**: @exclude decorator is deprecated. Use `@usage` and `@access` decorator instead. -::: - DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to exclude a model from generation for specific languages. By default we generate @@ -329,10 +321,6 @@ model ModelToExclude { ### `@flattenProperty` {#@Azure.ClientGenerator.Core.flattenProperty} -:::warning -**Deprecated**: @flattenProperty decorator is not recommended to use. -::: - Set whether a model property should be flattened or not. ```typespec @@ -361,10 +349,6 @@ model Bar {} ### `@include` {#@Azure.ClientGenerator.Core.include} -:::warning -**Deprecated**: @include decorator is deprecated. Use `@usage` and `@access` decorator instead. -::: - DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to include a model in generation for specific languages. By default we generate @@ -395,10 +379,6 @@ model ModelToInclude { ### `@internal` {#@Azure.ClientGenerator.Core.internal} -:::warning -**Deprecated**: @internal decorator is deprecated. Use `@access` decorator instead. -::: - DEPRECATED: Use `@access` decorator instead. Whether to mark an operation as internal for specific languages, @@ -557,3 +537,32 @@ model Origin { @get op getModel(): Fish; ``` + +## Azure.ClientGenerator.Core.CSharp + +### `@hasJSONConverter` {#@Azure.ClientGenerator.Core.CSharp.hasJSONConverter} + +Whether a model needs the custom JSON converter, this is only used for backward compatibility. + +```typespec +@Azure.ClientGenerator.Core.CSharp.hasJSONConverter(scope?: "csharp") +``` + +#### Target + +`Model` + +#### Parameters + +| Name | Type | Description | +| ----- | ---------- | ------------------------------------------------------------------------------------------------------------ | +| scope | `"csharp"` | The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. | + +#### Examples + +```typespec +@hasJSONConverter +model MyModel { + prop: string; +} +``` diff --git a/docs/libraries/typespec-client-generator-core/reference/index.mdx b/docs/libraries/typespec-client-generator-core/reference/index.mdx index 8f47aef4aa..c3bd55df96 100644 --- a/docs/libraries/typespec-client-generator-core/reference/index.mdx +++ b/docs/libraries/typespec-client-generator-core/reference/index.mdx @@ -51,3 +51,9 @@ npm install --save-peer @azure-tools/typespec-client-generator-core - [`@operationGroup`](./decorators.md#@Azure.ClientGenerator.Core.operationGroup) - [`@protocolAPI`](./decorators.md#@Azure.ClientGenerator.Core.protocolAPI) - [`@usage`](./decorators.md#@Azure.ClientGenerator.Core.usage) + +## Azure.ClientGenerator.Core.CSharp + +### Decorators + +- [`@hasJSONConverter`](./decorators.md#@Azure.ClientGenerator.Core.CSharp.hasJSONConverter) diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index d29f159e2a..37e4b22fbb 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -218,8 +218,6 @@ interface MyInterface {} #### `@clientFormat` -_Deprecated: @clientFormat decorator is deprecated. Use `@encode` decorator in `@typespec/compiler` instead._ - DEPRECATED: Use `@encode` decorator in `@typespec/compiler` instead. Can be used to explain the client type that the current TYPESPEC @@ -310,8 +308,6 @@ op test: void; #### `@exclude` -_Deprecated: @exclude decorator is deprecated. Use `@usage` and `@access` decorator instead._ - DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to exclude a model from generation for specific languages. By default we generate @@ -342,8 +338,6 @@ model ModelToExclude { #### `@flattenProperty` -_Deprecated: @flattenProperty decorator is not recommended to use._ - Set whether a model property should be flattened or not. ```typespec @@ -372,8 +366,6 @@ model Bar {} #### `@include` -_Deprecated: @include decorator is deprecated. Use `@usage` and `@access` decorator instead._ - DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to include a model in generation for specific languages. By default we generate @@ -404,8 +396,6 @@ model ModelToInclude { #### `@internal` -_Deprecated: @internal decorator is deprecated. Use `@access` decorator instead._ - DEPRECATED: Use `@access` decorator instead. Whether to mark an operation as internal for specific languages, @@ -564,3 +554,34 @@ model Origin { @get op getModel(): Fish; ``` + +### Azure.ClientGenerator.Core.CSharp + +- [`@hasJSONConverter`](#@hasjsonconverter) + +#### `@hasJSONConverter` + +Whether a model needs the custom JSON converter, this is only used for backward compatibility. + +```typespec +@Azure.ClientGenerator.Core.CSharp.hasJSONConverter(scope?: "csharp") +``` + +##### Target + +`Model` + +##### Parameters + +| Name | Type | Description | +| ----- | ---------- | ------------------------------------------------------------------------------------------------------------ | +| scope | `"csharp"` | The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. | + +##### Examples + +```typespec +@hasJSONConverter +model MyModel { + prop: string; +} +``` From 4e35b0bb0740d21c9eea8d72ab5f48a898b6ac09 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 14:17:18 +0800 Subject: [PATCH 09/21] regen docs --- .../azure-core/reference/interfaces.md | 28 ------------------- .../reference/data-types.md | 4 --- .../reference/interfaces.md | 16 ----------- 3 files changed, 48 deletions(-) diff --git a/docs/libraries/azure-core/reference/interfaces.md b/docs/libraries/azure-core/reference/interfaces.md index d0bfbeb104..f3a8f10fb0 100644 --- a/docs/libraries/azure-core/reference/interfaces.md +++ b/docs/libraries/azure-core/reference/interfaces.md @@ -338,10 +338,6 @@ op Azure.Core.LongRunningResourceCollectionAction(apiVersion: string): Azure.Cor ### `LongRunningResourceCreateOrReplace` {#Azure.Core.LongRunningResourceCreateOrReplace} -:::warning -**Deprecated**: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -361,10 +357,6 @@ op Azure.Core.LongRunningResourceCreateOrReplace(apiVersion: string, resource: R ### `LongRunningResourceCreateOrUpdate` {#Azure.Core.LongRunningResourceCreateOrUpdate} -:::warning -**Deprecated**: Use `LongRunningResourceCreateOrUpdate` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `LongRunningResourceCreateOrUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -384,10 +376,6 @@ op Azure.Core.LongRunningResourceCreateOrUpdate(apiVersion: string, contentType: ### `LongRunningResourceCreateWithServiceProvidedName` {#Azure.Core.LongRunningResourceCreateWithServiceProvidedName} -:::warning -**Deprecated**: Use `LongRunningResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `LongRunningResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -488,10 +476,6 @@ op Azure.Core.ResourceCollectionAction(apiVersion: string): {} | Azure.Core.Foun ### `ResourceCreateOrReplace` {#Azure.Core.ResourceCreateOrReplace} -:::warning -**Deprecated**: Use `ResourceCreateOrReplace` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `ResourceCreateOrReplace` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -511,10 +495,6 @@ op Azure.Core.ResourceCreateOrReplace(apiVersion: string, resource: Resource): { ### `ResourceCreateOrUpdate` {#Azure.Core.ResourceCreateOrUpdate} -:::warning -**Deprecated**: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `ResourceCreateOrUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -534,10 +514,6 @@ op Azure.Core.ResourceCreateOrUpdate(apiVersion: string, contentType: "applicati ### `ResourceCreateWithServiceProvidedName` {#Azure.Core.ResourceCreateWithServiceProvidedName} -:::warning -**Deprecated**: Use `ResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `ResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -614,10 +590,6 @@ op Azure.Core.ResourceRead(apiVersion: string): {} | Azure.Core.Foundations.Erro ### `ResourceUpdate` {#Azure.Core.ResourceUpdate} -:::warning -**Deprecated**: Use `ResourceUpdate` from a `ResourceOperations` interface instance. -::: - DEPRECATED: Use `ResourceUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index 769f6b7d37..d67893a7b1 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -1694,10 +1694,6 @@ model Azure.ResourceManager.CommonTypes.TrackedResource ### `UserAssignedIdentities` {#Azure.ResourceManager.CommonTypes.UserAssignedIdentities} -:::warning -**Deprecated**: Do not use this model. Instead, use Record directly. Using this model will result in a different client SDK when generated from TypeSpec compared to the Swagger. -::: - The set of user assigned identities associated with the resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. The dictionary values can be empty objects ({}) in requests. ```typespec diff --git a/docs/libraries/azure-resource-manager/reference/interfaces.md b/docs/libraries/azure-resource-manager/reference/interfaces.md index 0fc27525a0..9b424d61f0 100644 --- a/docs/libraries/azure-resource-manager/reference/interfaces.md +++ b/docs/libraries/azure-resource-manager/reference/interfaces.md @@ -247,10 +247,6 @@ op Azure.ResourceManager.ResourceCreateSync.createOrUpdate(provider: "Microsoft. ### `ResourceDeleteAsync` {#Azure.ResourceManager.ResourceDeleteAsync} -:::warning -**Deprecated**: This should be deprecated in a future release -::: - ```typespec interface Azure.ResourceManager.ResourceDeleteAsync ``` @@ -394,10 +390,6 @@ op Azure.ResourceManager.ResourceListBySubscription.listBySubscription(apiVersio ### `ResourceOperations` {#Azure.ResourceManager.ResourceOperations} -:::warning -**Deprecated**: Use Azure.ResourceManager.TrackedResourceOperations instead -::: - ```typespec interface Azure.ResourceManager.ResourceOperations ``` @@ -853,10 +845,6 @@ op Azure.ResourceManager.ArmResourceCreateOrUpdateAsync(provider: "Microsoft.Thi ### `ArmResourceCreateOrUpdateSync` {#Azure.ResourceManager.ArmResourceCreateOrUpdateSync} -:::warning -**Deprecated**: Please use ArmResourceCreateOrReplaceSync instead -::: - DEPRECATED: Please use ArmResourceCreateOrReplaceSync instead ```typespec @@ -875,10 +863,6 @@ op Azure.ResourceManager.ArmResourceCreateOrUpdateSync(provider: "Microsoft.This ### `ArmResourceDeleteAsync` {#Azure.ResourceManager.ArmResourceDeleteAsync} -:::warning -**Deprecated**: Use 'ArmResourceDeleteWithoutOkAsync' instead -::: - ```typespec op Azure.ResourceManager.ArmResourceDeleteAsync(provider: "Microsoft.ThisWillBeReplaced"): Response | Error ``` From 2a8904c080b3942922afa11c59b21ced39d7b0a8 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 30 Jul 2024 14:55:33 +0800 Subject: [PATCH 10/21] update doc --- .../azure-core/reference/interfaces.md | 28 +++++++++++++++++++ .../reference/data-types.md | 4 +++ .../reference/interfaces.md | 16 +++++++++++ .../reference/decorators.md | 20 +++++++++++++ .../typespec-client-generator-core/README.md | 10 +++++++ 5 files changed, 78 insertions(+) diff --git a/docs/libraries/azure-core/reference/interfaces.md b/docs/libraries/azure-core/reference/interfaces.md index f3a8f10fb0..d0bfbeb104 100644 --- a/docs/libraries/azure-core/reference/interfaces.md +++ b/docs/libraries/azure-core/reference/interfaces.md @@ -338,6 +338,10 @@ op Azure.Core.LongRunningResourceCollectionAction(apiVersion: string): Azure.Cor ### `LongRunningResourceCreateOrReplace` {#Azure.Core.LongRunningResourceCreateOrReplace} +:::warning +**Deprecated**: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -357,6 +361,10 @@ op Azure.Core.LongRunningResourceCreateOrReplace(apiVersion: string, resource: R ### `LongRunningResourceCreateOrUpdate` {#Azure.Core.LongRunningResourceCreateOrUpdate} +:::warning +**Deprecated**: Use `LongRunningResourceCreateOrUpdate` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `LongRunningResourceCreateOrUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -376,6 +384,10 @@ op Azure.Core.LongRunningResourceCreateOrUpdate(apiVersion: string, contentType: ### `LongRunningResourceCreateWithServiceProvidedName` {#Azure.Core.LongRunningResourceCreateWithServiceProvidedName} +:::warning +**Deprecated**: Use `LongRunningResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `LongRunningResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -476,6 +488,10 @@ op Azure.Core.ResourceCollectionAction(apiVersion: string): {} | Azure.Core.Foun ### `ResourceCreateOrReplace` {#Azure.Core.ResourceCreateOrReplace} +:::warning +**Deprecated**: Use `ResourceCreateOrReplace` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `ResourceCreateOrReplace` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -495,6 +511,10 @@ op Azure.Core.ResourceCreateOrReplace(apiVersion: string, resource: Resource): { ### `ResourceCreateOrUpdate` {#Azure.Core.ResourceCreateOrUpdate} +:::warning +**Deprecated**: Use `LongRunningResourceCreateOrReplace` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `ResourceCreateOrUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -514,6 +534,10 @@ op Azure.Core.ResourceCreateOrUpdate(apiVersion: string, contentType: "applicati ### `ResourceCreateWithServiceProvidedName` {#Azure.Core.ResourceCreateWithServiceProvidedName} +:::warning +**Deprecated**: Use `ResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `ResourceCreateWithServiceProvidedName` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. @@ -590,6 +614,10 @@ op Azure.Core.ResourceRead(apiVersion: string): {} | Azure.Core.Foundations.Erro ### `ResourceUpdate` {#Azure.Core.ResourceUpdate} +:::warning +**Deprecated**: Use `ResourceUpdate` from a `ResourceOperations` interface instance. +::: + DEPRECATED: Use `ResourceUpdate` from a `ResourceOperations` interface instance. This can be done by instantiating your own version with the traits you want `alias Operations = Azure.Core.ResourceOperations;`. See https://azure.github.io/typespec-azure/docs/getstarted/azure-core/step05#defining-the-operation-interface for details on how to use. diff --git a/docs/libraries/azure-resource-manager/reference/data-types.md b/docs/libraries/azure-resource-manager/reference/data-types.md index d67893a7b1..769f6b7d37 100644 --- a/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/docs/libraries/azure-resource-manager/reference/data-types.md @@ -1694,6 +1694,10 @@ model Azure.ResourceManager.CommonTypes.TrackedResource ### `UserAssignedIdentities` {#Azure.ResourceManager.CommonTypes.UserAssignedIdentities} +:::warning +**Deprecated**: Do not use this model. Instead, use Record directly. Using this model will result in a different client SDK when generated from TypeSpec compared to the Swagger. +::: + The set of user assigned identities associated with the resource. The userAssignedIdentities dictionary keys will be ARM resource ids in the form: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}. The dictionary values can be empty objects ({}) in requests. ```typespec diff --git a/docs/libraries/azure-resource-manager/reference/interfaces.md b/docs/libraries/azure-resource-manager/reference/interfaces.md index 9b424d61f0..0fc27525a0 100644 --- a/docs/libraries/azure-resource-manager/reference/interfaces.md +++ b/docs/libraries/azure-resource-manager/reference/interfaces.md @@ -247,6 +247,10 @@ op Azure.ResourceManager.ResourceCreateSync.createOrUpdate(provider: "Microsoft. ### `ResourceDeleteAsync` {#Azure.ResourceManager.ResourceDeleteAsync} +:::warning +**Deprecated**: This should be deprecated in a future release +::: + ```typespec interface Azure.ResourceManager.ResourceDeleteAsync ``` @@ -390,6 +394,10 @@ op Azure.ResourceManager.ResourceListBySubscription.listBySubscription(apiVersio ### `ResourceOperations` {#Azure.ResourceManager.ResourceOperations} +:::warning +**Deprecated**: Use Azure.ResourceManager.TrackedResourceOperations instead +::: + ```typespec interface Azure.ResourceManager.ResourceOperations ``` @@ -845,6 +853,10 @@ op Azure.ResourceManager.ArmResourceCreateOrUpdateAsync(provider: "Microsoft.Thi ### `ArmResourceCreateOrUpdateSync` {#Azure.ResourceManager.ArmResourceCreateOrUpdateSync} +:::warning +**Deprecated**: Please use ArmResourceCreateOrReplaceSync instead +::: + DEPRECATED: Please use ArmResourceCreateOrReplaceSync instead ```typespec @@ -863,6 +875,10 @@ op Azure.ResourceManager.ArmResourceCreateOrUpdateSync(provider: "Microsoft.This ### `ArmResourceDeleteAsync` {#Azure.ResourceManager.ArmResourceDeleteAsync} +:::warning +**Deprecated**: Use 'ArmResourceDeleteWithoutOkAsync' instead +::: + ```typespec op Azure.ResourceManager.ArmResourceDeleteAsync(provider: "Microsoft.ThisWillBeReplaced"): Response | Error ``` diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index 9948d77fb9..291d34b046 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -201,6 +201,10 @@ interface MyInterface {} ### `@clientFormat` {#@Azure.ClientGenerator.Core.clientFormat} +:::warning +**Deprecated**: @clientFormat decorator is deprecated. Use `@encode` decorator in `@typespec/compiler` instead. +::: + DEPRECATED: Use `@encode` decorator in `@typespec/compiler` instead. Can be used to explain the client type that the current TYPESPEC @@ -291,6 +295,10 @@ op test: void; ### `@exclude` {#@Azure.ClientGenerator.Core.exclude} +:::warning +**Deprecated**: @exclude decorator is deprecated. Use `@usage` and `@access` decorator instead. +::: + DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to exclude a model from generation for specific languages. By default we generate @@ -321,6 +329,10 @@ model ModelToExclude { ### `@flattenProperty` {#@Azure.ClientGenerator.Core.flattenProperty} +:::warning +**Deprecated**: @flattenProperty decorator is not recommended to use. +::: + Set whether a model property should be flattened or not. ```typespec @@ -349,6 +361,10 @@ model Bar {} ### `@include` {#@Azure.ClientGenerator.Core.include} +:::warning +**Deprecated**: @include decorator is deprecated. Use `@usage` and `@access` decorator instead. +::: + DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to include a model in generation for specific languages. By default we generate @@ -379,6 +395,10 @@ model ModelToInclude { ### `@internal` {#@Azure.ClientGenerator.Core.internal} +:::warning +**Deprecated**: @internal decorator is deprecated. Use `@access` decorator instead. +::: + DEPRECATED: Use `@access` decorator instead. Whether to mark an operation as internal for specific languages, diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index 37e4b22fbb..06765a9587 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -218,6 +218,8 @@ interface MyInterface {} #### `@clientFormat` +_Deprecated: @clientFormat decorator is deprecated. Use `@encode` decorator in `@typespec/compiler` instead._ + DEPRECATED: Use `@encode` decorator in `@typespec/compiler` instead. Can be used to explain the client type that the current TYPESPEC @@ -308,6 +310,8 @@ op test: void; #### `@exclude` +_Deprecated: @exclude decorator is deprecated. Use `@usage` and `@access` decorator instead._ + DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to exclude a model from generation for specific languages. By default we generate @@ -338,6 +342,8 @@ model ModelToExclude { #### `@flattenProperty` +_Deprecated: @flattenProperty decorator is not recommended to use._ + Set whether a model property should be flattened or not. ```typespec @@ -366,6 +372,8 @@ model Bar {} #### `@include` +_Deprecated: @include decorator is deprecated. Use `@usage` and `@access` decorator instead._ + DEPRECATED: Use `@usage` and `@access` decorator instead. Whether to include a model in generation for specific languages. By default we generate @@ -396,6 +404,8 @@ model ModelToInclude { #### `@internal` +_Deprecated: @internal decorator is deprecated. Use `@access` decorator instead._ + DEPRECATED: Use `@access` decorator instead. Whether to mark an operation as internal for specific languages, From bdec73d6d00388c5c5c244465abbf2dbce7e0238 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 31 Jul 2024 11:28:32 +0800 Subject: [PATCH 11/21] rename to hasJsonConverter --- .chronus/changes/json-converter-2024-6-24-16-48-41.md | 2 +- .../reference/decorators.md | 6 +++--- .../typespec-client-generator-core/reference/index.mdx | 2 +- packages/typespec-client-generator-core/README.md | 8 ++++---- .../generated-defs/Azure.ClientGenerator.Core.CSharp.ts | 4 ++-- .../Azure.ClientGenerator.Core.CSharp.ts-test.ts | 8 ++++---- .../typespec-client-generator-core/lib/decorators.tsp | 4 ++-- packages/typespec-client-generator-core/src/decorators.ts | 8 ++++---- .../test/types/general-decorators-list.test.ts | 8 ++++---- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/.chronus/changes/json-converter-2024-6-24-16-48-41.md b/.chronus/changes/json-converter-2024-6-24-16-48-41.md index ea9e8ae947..0fea7df5b8 100644 --- a/.chronus/changes/json-converter-2024-6-24-16-48-41.md +++ b/.chronus/changes/json-converter-2024-6-24-16-48-41.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-client-generator-core" --- -Add `@hasJSONConverter` for csharp only to indicate if JSON converter is needed \ No newline at end of file +Add `@hasJsonConverter` for csharp only to indicate if JSON converter is needed diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index 291d34b046..8c863c31a3 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -560,12 +560,12 @@ op getModel(): Fish; ## Azure.ClientGenerator.Core.CSharp -### `@hasJSONConverter` {#@Azure.ClientGenerator.Core.CSharp.hasJSONConverter} +### `@hasJsonConverter` {#@Azure.ClientGenerator.Core.CSharp.hasJsonConverter} Whether a model needs the custom JSON converter, this is only used for backward compatibility. ```typespec -@Azure.ClientGenerator.Core.CSharp.hasJSONConverter(scope?: "csharp") +@Azure.ClientGenerator.Core.CSharp.hasJsonConverter(scope?: "csharp") ``` #### Target @@ -581,7 +581,7 @@ Whether a model needs the custom JSON converter, this is only used for backward #### Examples ```typespec -@hasJSONConverter +@hasJsonConverter model MyModel { prop: string; } diff --git a/docs/libraries/typespec-client-generator-core/reference/index.mdx b/docs/libraries/typespec-client-generator-core/reference/index.mdx index c3bd55df96..368b12eb0b 100644 --- a/docs/libraries/typespec-client-generator-core/reference/index.mdx +++ b/docs/libraries/typespec-client-generator-core/reference/index.mdx @@ -56,4 +56,4 @@ npm install --save-peer @azure-tools/typespec-client-generator-core ### Decorators -- [`@hasJSONConverter`](./decorators.md#@Azure.ClientGenerator.Core.CSharp.hasJSONConverter) +- [`@hasJsonConverter`](./decorators.md#@Azure.ClientGenerator.Core.CSharp.hasJsonConverter) diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index 06765a9587..9145c70f9b 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -567,14 +567,14 @@ op getModel(): Fish; ### Azure.ClientGenerator.Core.CSharp -- [`@hasJSONConverter`](#@hasjsonconverter) +- [`@hasJsonConverter`](#@hasjsonconverter) -#### `@hasJSONConverter` +#### `@hasJsonConverter` Whether a model needs the custom JSON converter, this is only used for backward compatibility. ```typespec -@Azure.ClientGenerator.Core.CSharp.hasJSONConverter(scope?: "csharp") +@Azure.ClientGenerator.Core.CSharp.hasJsonConverter(scope?: "csharp") ``` ##### Target @@ -590,7 +590,7 @@ Whether a model needs the custom JSON converter, this is only used for backward ##### Examples ```typespec -@hasJSONConverter +@hasJsonConverter model MyModel { prop: string; } diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts index f9181edb2b..3061464103 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts @@ -6,13 +6,13 @@ import type { DecoratorContext, Model, Type } from "@typespec/compiler"; * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. * @example * ```typespec - * @hasJSONConverter + * @hasJsonConverter * model MyModel { * prop: string; * } * ``` */ -export type HasJSONConverterDecorator = ( +export type HasJsonConverterDecorator = ( context: DecoratorContext, target: Model, scope?: Type diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts index c0af9d9c18..926c0bb356 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts @@ -1,12 +1,12 @@ /** An error here would mean that the decorator is not exported or doesn't have the right name. */ -import { $hasJSONConverter } from "@azure-tools/typespec-client-generator-core"; -import type { HasJSONConverterDecorator } from "./Azure.ClientGenerator.Core.CSharp.js"; +import { $hasJsonConverter } from "@azure-tools/typespec-client-generator-core"; +import type { HasJsonConverterDecorator } from "./Azure.ClientGenerator.Core.CSharp.js"; type Decorators = { - $hasJSONConverter: HasJSONConverterDecorator; + $hasJsonConverter: HasJsonConverterDecorator; }; /** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ const _: Decorators = { - $hasJSONConverter, + $hasJsonConverter, }; diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index 1c7f7f9b27..a3ce09f66c 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -427,11 +427,11 @@ namespace Azure.ClientGenerator.Core.CSharp { * * @example * ```typespec - * @hasJSONConverter + * @hasJsonConverter * model MyModel { * prop: string; * } * ``` */ - extern dec hasJSONConverter(target: Model, scope?: "csharp"); + extern dec hasJsonConverter(target: Model, scope?: "csharp"); } diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index b2e3d86d9f..daa9c5af39 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -1058,13 +1058,13 @@ export function getClientNameOverride( return getScopedDecoratorData(context, clientNameKey, entity, languageScope); } -const hasJSONConverterKey = createStateSymbol("hasJSONConverterKey"); -export const $hasJSONConverter: DecoratorFunction = ( +const hasJsonConverterKey = createStateSymbol("hasJsonConverterKey"); +export const $hasJsonConverter: DecoratorFunction = ( context: DecoratorContext, entity: Model, scope?: LanguageScopes ) => { - setScopedDecoratorData(context, $hasJSONConverter, hasJSONConverterKey, entity, true, scope); + setScopedDecoratorData(context, $hasJsonConverter, hasJsonConverterKey, entity, true, scope); }; -setTypeSpecNamespace("CSharp", $hasJSONConverter); +setTypeSpecNamespace("CSharp", $hasJsonConverter); diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 600470b198..850d13fe7c 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -329,14 +329,14 @@ describe("typespec-client-generator-core: general decorators list", () => { }); describe("csharp only decorator", () => { - it("@hasJSONConverter", async function () { + it("@hasJsonConverter", async function () { runner = await createSdkTestRunner( {}, - { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJSONConverter"] } + { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJsonConverter"] } ); await runner.compileWithBuiltInService(` - @hasJSONConverter + @hasJsonConverter model A { id: string; } @@ -347,7 +347,7 @@ describe("typespec-client-generator-core: general decorators list", () => { const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure.ClientGenerator.Core.CSharp.@hasJSONConverter", arguments: {} }, + { name: "Azure.ClientGenerator.Core.CSharp.@hasJsonConverter", arguments: {} }, ]); expectDiagnostics(runner.context.diagnostics, []); }); From e278c4f6c2ce8d3567684f9f58b98e5360e647ad Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 31 Jul 2024 14:50:07 +0800 Subject: [PATCH 12/21] update namespace --- packages/typespec-client-generator-core/lib/decorators.tsp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index a3ce09f66c..2368696610 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -420,7 +420,7 @@ extern dec access( #deprecated "@flattenProperty decorator is not recommended to use." extern dec flattenProperty(target: ModelProperty, scope?: valueof string); -namespace Azure.ClientGenerator.Core.CSharp { +namespace CSharp { /** * Whether a model needs the custom JSON converter, this is only used for backward compatibility. * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. From f9ffd8b21ccfa1ba310e4e29ff6576b51c484e41 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 1 Aug 2024 07:23:40 +0800 Subject: [PATCH 13/21] remove scope and implementation --- .../reference/decorators.md | 8 +++----- packages/typespec-client-generator-core/README.md | 8 +++----- .../typespec-client-generator-core/lib/decorators.tsp | 5 ++--- packages/typespec-client-generator-core/src/decorators.ts | 8 ++------ 4 files changed, 10 insertions(+), 19 deletions(-) diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index 8c863c31a3..5f991c77c9 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -562,10 +562,10 @@ op getModel(): Fish; ### `@hasJsonConverter` {#@Azure.ClientGenerator.Core.CSharp.hasJsonConverter} -Whether a model needs the custom JSON converter, this is only used for backward compatibility. +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. ```typespec -@Azure.ClientGenerator.Core.CSharp.hasJsonConverter(scope?: "csharp") +@Azure.ClientGenerator.Core.CSharp.hasJsonConverter ``` #### Target @@ -574,9 +574,7 @@ Whether a model needs the custom JSON converter, this is only used for backward #### Parameters -| Name | Type | Description | -| ----- | ---------- | ------------------------------------------------------------------------------------------------------------ | -| scope | `"csharp"` | The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. | +None #### Examples diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index 9145c70f9b..1a91443615 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -571,10 +571,10 @@ op getModel(): Fish; #### `@hasJsonConverter` -Whether a model needs the custom JSON converter, this is only used for backward compatibility. +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. ```typespec -@Azure.ClientGenerator.Core.CSharp.hasJsonConverter(scope?: "csharp") +@Azure.ClientGenerator.Core.CSharp.hasJsonConverter ``` ##### Target @@ -583,9 +583,7 @@ Whether a model needs the custom JSON converter, this is only used for backward ##### Parameters -| Name | Type | Description | -| ----- | ---------- | ------------------------------------------------------------------------------------------------------------ | -| scope | `"csharp"` | The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. | +None ##### Examples diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index 2368696610..478a7dac38 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -422,8 +422,7 @@ extern dec flattenProperty(target: ModelProperty, scope?: valueof string); namespace CSharp { /** - * Whether a model needs the custom JSON converter, this is only used for backward compatibility. - * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. + * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. * * @example * ```typespec @@ -433,5 +432,5 @@ namespace CSharp { * } * ``` */ - extern dec hasJsonConverter(target: Model, scope?: "csharp"); + extern dec hasJsonConverter(target: Model); } diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index daa9c5af39..ac2c9c78f2 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -1058,13 +1058,9 @@ export function getClientNameOverride( return getScopedDecoratorData(context, clientNameKey, entity, languageScope); } -const hasJsonConverterKey = createStateSymbol("hasJsonConverterKey"); export const $hasJsonConverter: DecoratorFunction = ( context: DecoratorContext, - entity: Model, - scope?: LanguageScopes -) => { - setScopedDecoratorData(context, $hasJsonConverter, hasJsonConverterKey, entity, true, scope); -}; + entity: Model +) => {}; setTypeSpecNamespace("CSharp", $hasJsonConverter); From 4e37acd06af0cb69f9b6e7b2be0f9e1a22898e8d Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 1 Aug 2024 07:44:19 +0800 Subject: [PATCH 14/21] regen --- .../Azure.ClientGenerator.Core.CSharp.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts index 3061464103..3f589bdbef 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts @@ -1,9 +1,8 @@ -import type { DecoratorContext, Model, Type } from "@typespec/compiler"; +import type { DecoratorContext, Model } from "@typespec/compiler"; /** - * Whether a model needs the custom JSON converter, this is only used for backward compatibility. + * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. * - * @param scope The language scope you want this decorator to apply to. If not specified, will only apply to csharp emitter. * @example * ```typespec * @hasJsonConverter @@ -12,8 +11,4 @@ import type { DecoratorContext, Model, Type } from "@typespec/compiler"; * } * ``` */ -export type HasJsonConverterDecorator = ( - context: DecoratorContext, - target: Model, - scope?: Type -) => void; +export type HasJsonConverterDecorator = (context: DecoratorContext, target: Model) => void; From c558a6e121723df3fdf5b82ecb9a2c73c6770724 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Aug 2024 10:42:43 +0800 Subject: [PATCH 15/21] move decorator to root namespace --- .../Azure.ClientGenerator.Core.CSharp.ts | 14 ---------- ...ure.ClientGenerator.Core.CSharp.ts-test.ts | 12 --------- .../Azure.ClientGenerator.Core.ts | 18 +++++++++++++ .../Azure.ClientGenerator.Core.ts-test.ts | 4 +++ .../lib/decorators.tsp | 27 +++++++++---------- .../src/decorators.ts | 3 --- .../types/general-decorators-list.test.ts | 2 +- 7 files changed, 36 insertions(+), 44 deletions(-) delete mode 100644 packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts delete mode 100644 packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts deleted file mode 100644 index 3f589bdbef..0000000000 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { DecoratorContext, Model } from "@typespec/compiler"; - -/** - * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - * - * @example - * ```typespec - * @hasJsonConverter - * model MyModel { - * prop: string; - * } - * ``` - */ -export type HasJsonConverterDecorator = (context: DecoratorContext, target: Model) => void; diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts deleted file mode 100644 index 926c0bb356..0000000000 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.CSharp.ts-test.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** An error here would mean that the decorator is not exported or doesn't have the right name. */ -import { $hasJsonConverter } from "@azure-tools/typespec-client-generator-core"; -import type { HasJsonConverterDecorator } from "./Azure.ClientGenerator.Core.CSharp.js"; - -type Decorators = { - $hasJsonConverter: HasJsonConverterDecorator; -}; - -/** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ -const _: Decorators = { - $hasJsonConverter, -}; diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts index fdbb9f9126..c0b473e054 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts @@ -483,3 +483,21 @@ export type OverrideDecorator = ( override: Operation, scope?: string ) => void; + +/** + * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + * + * @param scope The language scope you want this decorator to apply to. If not specified, will apply to all language emitters + * @example + * ```typespec + * @hasJsonConverter + * model MyModel { + * prop: string; + * } + * ``` + */ +export type HasJsonConverterDecorator = ( + context: DecoratorContext, + target: Model, + scope?: string +) => void; diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts index 1fe5974bec..31b4e423fe 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts @@ -7,6 +7,7 @@ import { $convenientAPI, $exclude, $flattenProperty, + $hasJsonConverter, $include, $internal, $operationGroup, @@ -22,6 +23,7 @@ import type { ConvenientAPIDecorator, ExcludeDecorator, FlattenPropertyDecorator, + HasJsonConverterDecorator, IncludeDecorator, InternalDecorator, OperationGroupDecorator, @@ -44,6 +46,7 @@ type Decorators = { $access: AccessDecorator; $flattenProperty: FlattenPropertyDecorator; $override: OverrideDecorator; + $hasJsonConverter: HasJsonConverterDecorator; }; /** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ @@ -61,4 +64,5 @@ const _: Decorators = { $access, $flattenProperty, $override, + $hasJsonConverter, }; diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index 37dd94e0b0..b74427bf2f 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -468,17 +468,16 @@ extern dec flattenProperty(target: ModelProperty, scope?: valueof string); */ extern dec override(original: Operation, override: Operation, scope?: valueof string); -namespace CSharp { - /** - * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - * - * @example - * ```typespec - * @hasJsonConverter - * model MyModel { - * prop: string; - * } - * ``` - */ - extern dec hasJsonConverter(target: Model); -} +/** + * Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + * @param scope The language scope you want this decorator to apply to. If not specified, will apply to all language emitters + * + * @example + * ```typespec + * @hasJsonConverter + * model MyModel { + * prop: string; + * } + * ``` + */ +extern dec hasJsonConverter(target: Model, scope?: valueof string); diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 45cb821e8b..b2fb666acb 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -27,7 +27,6 @@ import { isTemplateDeclarationOrInstance, listServices, projectProgram, - setTypeSpecNamespace, validateDecoratorUniqueOnNode, } from "@typespec/compiler"; import { isHeader } from "@typespec/http"; @@ -1141,5 +1140,3 @@ export const $hasJsonConverter: DecoratorFunction = ( context: DecoratorContext, entity: Model ) => {}; - -setTypeSpecNamespace("CSharp", $hasJsonConverter); diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index bb0b0c7cfe..748b5a79d7 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -336,7 +336,7 @@ describe("typespec-client-generator-core: general decorators list", () => { ); await runner.compileWithBuiltInService(` - @hasJsonConverter + @hasJsonConverter("csharp") model A { id: string; } From a4d3e0ea16c70783409043905b5df1e4abdbf7d1 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Aug 2024 10:57:18 +0800 Subject: [PATCH 16/21] fix test --- packages/typespec-client-generator-core/test/test-host.ts | 1 - .../test/types/general-decorators-list.test.ts | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/typespec-client-generator-core/test/test-host.ts b/packages/typespec-client-generator-core/test/test-host.ts index 5f36842d17..e8980de81b 100644 --- a/packages/typespec-client-generator-core/test/test-host.ts +++ b/packages/typespec-client-generator-core/test/test-host.ts @@ -77,7 +77,6 @@ export async function createSdkTestRunner( const host = await createSdkTestHost(options); let autoUsings = [ "Azure.ClientGenerator.Core", - "Azure.ClientGenerator.Core.CSharp", "TypeSpec.Rest", "TypeSpec.Http", "TypeSpec.Versioning", diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 748b5a79d7..8bc8b1ae6a 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -332,7 +332,7 @@ describe("typespec-client-generator-core: general decorators list", () => { it("@hasJsonConverter", async function () { runner = await createSdkTestRunner( {}, - { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.CSharp\\.@hasJsonConverter"] } + { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@hasJsonConverter"] } ); await runner.compileWithBuiltInService(` @@ -347,7 +347,7 @@ describe("typespec-client-generator-core: general decorators list", () => { const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure.ClientGenerator.Core.CSharp.@hasJsonConverter", arguments: {} }, + { name: "Azure.ClientGenerator.Core.@hasJsonConverter", arguments: {"scope": "csharp"} }, ]); expectDiagnostics(runner.context.diagnostics, []); }); From bf009581fded0c453c486317b6f22f5ef484b3cc Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Aug 2024 10:59:41 +0800 Subject: [PATCH 17/21] fix format --- .../test/types/general-decorators-list.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 8bc8b1ae6a..67f405d98d 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -347,7 +347,7 @@ describe("typespec-client-generator-core: general decorators list", () => { const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure.ClientGenerator.Core.@hasJsonConverter", arguments: {"scope": "csharp"} }, + { name: "Azure.ClientGenerator.Core.@hasJsonConverter", arguments: { scope: "csharp" } }, ]); expectDiagnostics(runner.context.diagnostics, []); }); From e796bd4794ed46f840942ecf439e87192e430df6 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Aug 2024 11:03:51 +0800 Subject: [PATCH 18/21] regen docs --- .../reference/decorators.md | 54 +++++++++--------- .../reference/index.mdx | 7 +-- .../typespec-client-generator-core/README.md | 57 +++++++++---------- 3 files changed, 56 insertions(+), 62 deletions(-) diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index 0d903d4123..7a67da0920 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -359,6 +359,33 @@ model Foo { model Bar {} ``` +### `@hasJsonConverter` {#@Azure.ClientGenerator.Core.hasJsonConverter} + +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + +```typespec +@Azure.ClientGenerator.Core.hasJsonConverter(scope?: valueof string) +``` + +#### Target + +`Model` + +#### Parameters + +| Name | Type | Description | +| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | +| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | + +#### Examples + +```typespec +@hasJsonConverter +model MyModel { + prop: string; +} +``` + ### `@include` {#@Azure.ClientGenerator.Core.include} :::warning @@ -617,30 +644,3 @@ model Origin { @get op getModel(): Fish; ``` - -## Azure.ClientGenerator.Core.CSharp - -### `@hasJsonConverter` {#@Azure.ClientGenerator.Core.CSharp.hasJsonConverter} - -Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - -```typespec -@Azure.ClientGenerator.Core.CSharp.hasJsonConverter -``` - -#### Target - -`Model` - -#### Parameters - -None - -#### Examples - -```typespec -@hasJsonConverter -model MyModel { - prop: string; -} -``` diff --git a/docs/libraries/typespec-client-generator-core/reference/index.mdx b/docs/libraries/typespec-client-generator-core/reference/index.mdx index 84acb609c0..0bf23adc9d 100644 --- a/docs/libraries/typespec-client-generator-core/reference/index.mdx +++ b/docs/libraries/typespec-client-generator-core/reference/index.mdx @@ -46,15 +46,10 @@ npm install --save-peer @azure-tools/typespec-client-generator-core - [`@convenientAPI`](./decorators.md#@Azure.ClientGenerator.Core.convenientAPI) - [`@exclude`](./decorators.md#@Azure.ClientGenerator.Core.exclude) - [`@flattenProperty`](./decorators.md#@Azure.ClientGenerator.Core.flattenProperty) +- [`@hasJsonConverter`](./decorators.md#@Azure.ClientGenerator.Core.hasJsonConverter) - [`@include`](./decorators.md#@Azure.ClientGenerator.Core.include) - [`@internal`](./decorators.md#@Azure.ClientGenerator.Core.internal) - [`@operationGroup`](./decorators.md#@Azure.ClientGenerator.Core.operationGroup) - [`@override`](./decorators.md#@Azure.ClientGenerator.Core.override) - [`@protocolAPI`](./decorators.md#@Azure.ClientGenerator.Core.protocolAPI) - [`@usage`](./decorators.md#@Azure.ClientGenerator.Core.usage) - -## Azure.ClientGenerator.Core.CSharp - -### Decorators - -- [`@hasJsonConverter`](./decorators.md#@Azure.ClientGenerator.Core.CSharp.hasJsonConverter) diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index b3ebc9aeae..8542eee08d 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -19,6 +19,7 @@ npm install @azure-tools/typespec-client-generator-core - [`@convenientAPI`](#@convenientapi) - [`@exclude`](#@exclude) - [`@flattenProperty`](#@flattenproperty) +- [`@hasJsonConverter`](#@hasjsonconverter) - [`@include`](#@include) - [`@internal`](#@internal) - [`@operationGroup`](#@operationgroup) @@ -371,6 +372,33 @@ model Foo { model Bar {} ``` +#### `@hasJsonConverter` + +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + +```typespec +@Azure.ClientGenerator.Core.hasJsonConverter(scope?: valueof string) +``` + +##### Target + +`Model` + +##### Parameters + +| Name | Type | Description | +| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | +| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | + +##### Examples + +```typespec +@hasJsonConverter +model MyModel { + prop: string; +} +``` + #### `@include` _Deprecated: @include decorator is deprecated. Use `@usage` and `@access` decorator instead._ @@ -625,32 +653,3 @@ model Origin { @get op getModel(): Fish; ``` - -### Azure.ClientGenerator.Core.CSharp - -- [`@hasJsonConverter`](#@hasjsonconverter) - -#### `@hasJsonConverter` - -Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - -```typespec -@Azure.ClientGenerator.Core.CSharp.hasJsonConverter -``` - -##### Target - -`Model` - -##### Parameters - -None - -##### Examples - -```typespec -@hasJsonConverter -model MyModel { - prop: string; -} -``` From 1c499e77e12d2d01f3feadb04eb031c62cf6e838 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Thu, 8 Aug 2024 14:36:49 +0800 Subject: [PATCH 19/21] add scope to implementation --- packages/typespec-client-generator-core/src/decorators.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index b2fb666acb..2409028a83 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -1138,5 +1138,6 @@ export function getOverriddenClientMethod( export const $hasJsonConverter: DecoratorFunction = ( context: DecoratorContext, - entity: Model + entity: Model, + scope?: LanguageScopes ) => {}; From 4e0c38be3c1ad6e8501c5c298ea0b513ae46d1ca Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 9 Aug 2024 10:29:35 +0800 Subject: [PATCH 20/21] rename to useSystemTextJsonConverter --- .../reference/decorators.md | 54 +++++++++--------- .../reference/index.mdx | 2 +- .../typespec-client-generator-core/README.md | 56 +++++++++---------- .../Azure.ClientGenerator.Core.ts | 4 +- .../Azure.ClientGenerator.Core.ts-test.ts | 8 +-- .../lib/decorators.tsp | 4 +- .../src/decorators.ts | 2 +- .../types/general-decorators-list.test.ts | 8 +-- 8 files changed, 69 insertions(+), 69 deletions(-) diff --git a/docs/libraries/typespec-client-generator-core/reference/decorators.md b/docs/libraries/typespec-client-generator-core/reference/decorators.md index 7a67da0920..374487dcdb 100644 --- a/docs/libraries/typespec-client-generator-core/reference/decorators.md +++ b/docs/libraries/typespec-client-generator-core/reference/decorators.md @@ -359,33 +359,6 @@ model Foo { model Bar {} ``` -### `@hasJsonConverter` {#@Azure.ClientGenerator.Core.hasJsonConverter} - -Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - -```typespec -@Azure.ClientGenerator.Core.hasJsonConverter(scope?: valueof string) -``` - -#### Target - -`Model` - -#### Parameters - -| Name | Type | Description | -| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | -| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | - -#### Examples - -```typespec -@hasJsonConverter -model MyModel { - prop: string; -} -``` - ### `@include` {#@Azure.ClientGenerator.Core.include} :::warning @@ -644,3 +617,30 @@ model Origin { @get op getModel(): Fish; ``` + +### `@useSystemTextJsonConverter` {#@Azure.ClientGenerator.Core.useSystemTextJsonConverter} + +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + +```typespec +@Azure.ClientGenerator.Core.useSystemTextJsonConverter(scope?: valueof string) +``` + +#### Target + +`Model` + +#### Parameters + +| Name | Type | Description | +| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | +| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | + +#### Examples + +```typespec +@useSystemTextJsonConverter +model MyModel { + prop: string; +} +``` diff --git a/docs/libraries/typespec-client-generator-core/reference/index.mdx b/docs/libraries/typespec-client-generator-core/reference/index.mdx index 0bf23adc9d..d504e45c31 100644 --- a/docs/libraries/typespec-client-generator-core/reference/index.mdx +++ b/docs/libraries/typespec-client-generator-core/reference/index.mdx @@ -46,10 +46,10 @@ npm install --save-peer @azure-tools/typespec-client-generator-core - [`@convenientAPI`](./decorators.md#@Azure.ClientGenerator.Core.convenientAPI) - [`@exclude`](./decorators.md#@Azure.ClientGenerator.Core.exclude) - [`@flattenProperty`](./decorators.md#@Azure.ClientGenerator.Core.flattenProperty) -- [`@hasJsonConverter`](./decorators.md#@Azure.ClientGenerator.Core.hasJsonConverter) - [`@include`](./decorators.md#@Azure.ClientGenerator.Core.include) - [`@internal`](./decorators.md#@Azure.ClientGenerator.Core.internal) - [`@operationGroup`](./decorators.md#@Azure.ClientGenerator.Core.operationGroup) - [`@override`](./decorators.md#@Azure.ClientGenerator.Core.override) - [`@protocolAPI`](./decorators.md#@Azure.ClientGenerator.Core.protocolAPI) - [`@usage`](./decorators.md#@Azure.ClientGenerator.Core.usage) +- [`@useSystemTextJsonConverter`](./decorators.md#@Azure.ClientGenerator.Core.useSystemTextJsonConverter) diff --git a/packages/typespec-client-generator-core/README.md b/packages/typespec-client-generator-core/README.md index 8542eee08d..479eb2cf9a 100644 --- a/packages/typespec-client-generator-core/README.md +++ b/packages/typespec-client-generator-core/README.md @@ -19,13 +19,13 @@ npm install @azure-tools/typespec-client-generator-core - [`@convenientAPI`](#@convenientapi) - [`@exclude`](#@exclude) - [`@flattenProperty`](#@flattenproperty) -- [`@hasJsonConverter`](#@hasjsonconverter) - [`@include`](#@include) - [`@internal`](#@internal) - [`@operationGroup`](#@operationgroup) - [`@override`](#@override) - [`@protocolAPI`](#@protocolapi) - [`@usage`](#@usage) +- [`@useSystemTextJsonConverter`](#@usesystemtextjsonconverter) #### `@access` @@ -372,33 +372,6 @@ model Foo { model Bar {} ``` -#### `@hasJsonConverter` - -Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. - -```typespec -@Azure.ClientGenerator.Core.hasJsonConverter(scope?: valueof string) -``` - -##### Target - -`Model` - -##### Parameters - -| Name | Type | Description | -| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | -| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | - -##### Examples - -```typespec -@hasJsonConverter -model MyModel { - prop: string; -} -``` - #### `@include` _Deprecated: @include decorator is deprecated. Use `@usage` and `@access` decorator instead._ @@ -653,3 +626,30 @@ model Origin { @get op getModel(): Fish; ``` + +#### `@useSystemTextJsonConverter` + +Whether a model needs the custom JSON converter, this is only used for backward compatibility for csharp. + +```typespec +@Azure.ClientGenerator.Core.useSystemTextJsonConverter(scope?: valueof string) +``` + +##### Target + +`Model` + +##### Parameters + +| Name | Type | Description | +| ----- | ---------------- | ------------------------------------------------------------------------------------------------------------- | +| scope | `valueof string` | The language scope you want this decorator to apply to. If not specified, will apply to all language emitters | + +##### Examples + +```typespec +@useSystemTextJsonConverter +model MyModel { + prop: string; +} +``` diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts index c0b473e054..7e83c78e80 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts @@ -490,13 +490,13 @@ export type OverrideDecorator = ( * @param scope The language scope you want this decorator to apply to. If not specified, will apply to all language emitters * @example * ```typespec - * @hasJsonConverter + * @useSystemTextJsonConverter * model MyModel { * prop: string; * } * ``` */ -export type HasJsonConverterDecorator = ( +export type UseSystemTextJsonConverterDecorator = ( context: DecoratorContext, target: Model, scope?: string diff --git a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts index 31b4e423fe..08aefaa0d8 100644 --- a/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts +++ b/packages/typespec-client-generator-core/generated-defs/Azure.ClientGenerator.Core.ts-test.ts @@ -7,13 +7,13 @@ import { $convenientAPI, $exclude, $flattenProperty, - $hasJsonConverter, $include, $internal, $operationGroup, $override, $protocolAPI, $usage, + $useSystemTextJsonConverter, } from "@azure-tools/typespec-client-generator-core"; import type { AccessDecorator, @@ -23,13 +23,13 @@ import type { ConvenientAPIDecorator, ExcludeDecorator, FlattenPropertyDecorator, - HasJsonConverterDecorator, IncludeDecorator, InternalDecorator, OperationGroupDecorator, OverrideDecorator, ProtocolAPIDecorator, UsageDecorator, + UseSystemTextJsonConverterDecorator, } from "./Azure.ClientGenerator.Core.js"; type Decorators = { @@ -46,7 +46,7 @@ type Decorators = { $access: AccessDecorator; $flattenProperty: FlattenPropertyDecorator; $override: OverrideDecorator; - $hasJsonConverter: HasJsonConverterDecorator; + $useSystemTextJsonConverter: UseSystemTextJsonConverterDecorator; }; /** An error here would mean that the exported decorator is not using the same signature. Make sure to have export const $decName: DecNameDecorator = (...) => ... */ @@ -64,5 +64,5 @@ const _: Decorators = { $access, $flattenProperty, $override, - $hasJsonConverter, + $useSystemTextJsonConverter, }; diff --git a/packages/typespec-client-generator-core/lib/decorators.tsp b/packages/typespec-client-generator-core/lib/decorators.tsp index b74427bf2f..46f1560311 100644 --- a/packages/typespec-client-generator-core/lib/decorators.tsp +++ b/packages/typespec-client-generator-core/lib/decorators.tsp @@ -474,10 +474,10 @@ extern dec override(original: Operation, override: Operation, scope?: valueof st * * @example * ```typespec - * @hasJsonConverter + * @useSystemTextJsonConverter * model MyModel { * prop: string; * } * ``` */ -extern dec hasJsonConverter(target: Model, scope?: valueof string); +extern dec useSystemTextJsonConverter(target: Model, scope?: valueof string); diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 2409028a83..296c5a56cd 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -1136,7 +1136,7 @@ export function getOverriddenClientMethod( return getScopedDecoratorData(context, overrideKey, entity); } -export const $hasJsonConverter: DecoratorFunction = ( +export const $useSystemTextJsonConverter: DecoratorFunction = ( context: DecoratorContext, entity: Model, scope?: LanguageScopes diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index 67f405d98d..c2aa73c5c3 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -329,14 +329,14 @@ describe("typespec-client-generator-core: general decorators list", () => { }); describe("csharp only decorator", () => { - it("@hasJsonConverter", async function () { + it("@useSystemTextJsonConverter", async function () { runner = await createSdkTestRunner( {}, - { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@hasJsonConverter"] } + { additionalDecorators: ["Azure\\.ClientGenerator\\.Core\\.@useSystemTextJsonConverter"] } ); await runner.compileWithBuiltInService(` - @hasJsonConverter("csharp") + @useSystemTextJsonConverter("csharp") model A { id: string; } @@ -347,7 +347,7 @@ describe("typespec-client-generator-core: general decorators list", () => { const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure.ClientGenerator.Core.@hasJsonConverter", arguments: { scope: "csharp" } }, + { name: "Azure.ClientGenerator.Core.@useSystemTextJsonConverter", arguments: { scope: "csharp" } }, ]); expectDiagnostics(runner.context.diagnostics, []); }); From 1fd1583aa6415cf44cda7b0d4168077b71e9a7ca Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Fri, 9 Aug 2024 10:37:25 +0800 Subject: [PATCH 21/21] fix format --- .../test/types/general-decorators-list.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts index c2aa73c5c3..8608236957 100644 --- a/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts +++ b/packages/typespec-client-generator-core/test/types/general-decorators-list.test.ts @@ -347,7 +347,10 @@ describe("typespec-client-generator-core: general decorators list", () => { const models = runner.context.sdkPackage.models; strictEqual(models.length, 1); deepStrictEqual(models[0].decorators, [ - { name: "Azure.ClientGenerator.Core.@useSystemTextJsonConverter", arguments: { scope: "csharp" } }, + { + name: "Azure.ClientGenerator.Core.@useSystemTextJsonConverter", + arguments: { scope: "csharp" }, + }, ]); expectDiagnostics(runner.context.diagnostics, []); });