From 9a978d0911925549cf934df7d1585f73c3e5f138 Mon Sep 17 00:00:00 2001 From: Dapeng Zhang Date: Sat, 14 Sep 2024 15:01:18 +0800 Subject: [PATCH] [TCGC] update references for #1463 (#1541) Update references after merged #1463 --- ...s-for-recent-changes-2024-8-14-12-27-46.md | 7 ++ docs/howtos/Client Generation/07tcgcTypes.mdx | 91 ++++++++++--------- .../src/interfaces.ts | 2 +- 3 files changed, 58 insertions(+), 42 deletions(-) create mode 100644 .chronus/changes/update-references-for-recent-changes-2024-8-14-12-27-46.md diff --git a/.chronus/changes/update-references-for-recent-changes-2024-8-14-12-27-46.md b/.chronus/changes/update-references-for-recent-changes-2024-8-14-12-27-46.md new file mode 100644 index 0000000000..36a5f6ea92 --- /dev/null +++ b/.chronus/changes/update-references-for-recent-changes-2024-8-14-12-27-46.md @@ -0,0 +1,7 @@ +--- +changeKind: breaking +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +no longer export the `SdkExampleValueBase` interface. This type should have no usage in downstream consumer's code. If there is any usage, please replace it with `SdkExampleValue`. diff --git a/docs/howtos/Client Generation/07tcgcTypes.mdx b/docs/howtos/Client Generation/07tcgcTypes.mdx index 162558a521..d07c432899 100644 --- a/docs/howtos/Client Generation/07tcgcTypes.mdx +++ b/docs/howtos/Client Generation/07tcgcTypes.mdx @@ -1430,11 +1430,20 @@ export interface SdkUnionType extends SdkTypeBase { // determines if the union name was generated or not isGeneratedName: boolean; kind: "union"; - values: SdkType[]; + variantTypes: SdkType[]; crossLanguageDefinitionId: string; } ``` +### SdkTupleType + +```ts +export interface SdkTupleType extends SdkTypeBase { + kind: "tuple"; + valueTypes: SdkType[]; +} +``` + ### SdkModelType ```ts @@ -1502,7 +1511,7 @@ These types are used to represent an example of a service operation. We currently only support HTTP calls to the service. -So, we have `SdkHttpoperationExample` bind to `SdkHttpOperation`, `SdkHttpParameterExample` bind to `SdkHttpParameter`, `SdkHttpResponseExample` bind to `SdkHttpResponse`, and `SdkHttpResponseHeaderExample` bind to `SdkHttpResponseHeader`. +So, we have `SdkHttpoperationExample` bind to `SdkHttpOperation`, `SdkHttpParameterExampleValue` bind to `SdkHttpParameter`, `SdkHttpResponseExampleValue` bind to `SdkHttpResponse`, and `SdkHttpResponseHeaderExampleValue` bind to `SdkHttpResponseHeader`. Each type will have the example value type and its cooresponding definition type. @@ -1517,53 +1526,53 @@ interface SdkExampleBase { export interface SdkHttpOperationExample extends SdkExampleBase { kind: "http"; - parameters: SdkHttpParameterExample[]; - responses: Map; + parameters: SdkHttpParameterExampleValue[]; + responses: Map; } -export interface SdkHttpParameterExample { +export interface SdkHttpParameterExampleValue { parameter: SdkHttpParameter; - value: SdkTypeExample; + value: SdkExampleValue; } -export interface SdkHttpResponseExample { +export interface SdkHttpResponseExampleValue { response: SdkHttpResponse; - headers: SdkHttpResponseHeaderExample[]; - bodyValue?: SdkTypeExample; + headers: SdkHttpResponseHeaderExampleValue[]; + bodyValue?: SdkExampleValue; } -export interface SdkHttpResponseHeaderExample { +export interface SdkHttpResponseHeaderExampleValue { header: SdkServiceResponseHeader; - value: SdkTypeExample; + value: SdkExampleValue; } ``` -### SdkExampleType +### SdkExampleValue These types are used to represent the example value of a type. One definition types will have different example value types. -For `SdkUnionExample`, since it is hard to determine whether the example value should belong to which union variant, we will keep the raw value and leave the work for the emitter. -For `SdkModelExample`, we will help to map the example type to the right subtype for the discriminated type, and we will separate the additional properties value from the property value. +For `SdkUnionExampleValue`, since it is hard to determine whether the example value should belong to which union variant, we will keep the raw value and leave the work for the emitter. +For `SdkModelExampleValue`, we will help to map the example type to the right subtype for the discriminated type, and we will separate the additional properties value from the property value. But for the model with inheritance, we will not break down the type graph, just put all the example value in the child model. ```ts -export type SdkTypeExample = - | SdkStringExample - | SdkNumberExample - | SdkBooleanExample - | SdkNullExample - | SdkAnyExample - | SdkArrayExample - | SdkDictionaryExample - | SdkUnionExample - | SdkModelExample; +export type SdkExampleValue = + | SdkStringExampleValue + | SdkNumberExampleValue + | SdkBooleanExampleValue + | SdkNullExampleValue + | SdkUnknownExampleValue + | SdkArrayExampleValue + | SdkDictionaryExampleValue + | SdkUnionExampleValue + | SdkModelExampleValue; -export interface SdkExampleTypeBase { +interface SdkExampleValueBase { kind: string; type: SdkType; value: unknown; } -export interface SdkStringExample extends SdkExampleTypeBase { +export interface SdkStringExampleValue extends SdkExampleTypeBase { kind: "string"; type: | SdkBuiltInType @@ -1575,7 +1584,7 @@ export interface SdkStringExample extends SdkExampleTypeBase { value: string; } -export interface SdkNumberExample extends SdkExampleTypeBase { +export interface SdkNumberExampleValue extends SdkExampleTypeBase { kind: "number"; type: | SdkBuiltInType @@ -1587,47 +1596,47 @@ export interface SdkNumberExample extends SdkExampleTypeBase { value: number; } -export interface SdkBooleanExample extends SdkExampleTypeBase { +export interface SdkBooleanExampleValue extends SdkExampleTypeBase { kind: "boolean"; type: SdkBuiltInType | SdkConstantType; value: boolean; } -export interface SdkNullExample extends SdkExampleTypeBase { +export interface SdkNullExampleValue extends SdkExampleTypeBase { kind: "null"; type: SdkNullableType; value: null; } -export interface SdkAnyExample extends SdkExampleTypeBase { - kind: "any"; +export interface SdkUnknownExampleValue extends SdkExampleTypeBase { + kind: "unknown"; type: SdkBuiltInType; value: unknown; } -export interface SdkArrayExample extends SdkExampleTypeBase { +export interface SdkArrayExampleValue extends SdkExampleTypeBase { kind: "array"; type: SdkArrayType; - value: SdkTypeExample[]; + value: SdkExampleValue[]; } -export interface SdkDictionaryExample extends SdkExampleTypeBase { +export interface SdkDictionaryExampleValue extends SdkExampleTypeBase { kind: "dict"; type: SdkDictionaryType; - value: Record; + value: Record; } -export interface SdkUnionExample extends SdkExampleTypeBase { +export interface SdkUnionExampleValue extends SdkExampleTypeBase { kind: "union"; type: SdkUnionType; value: unknown; } -export interface SdkModelExample extends SdkExampleTypeBase { +export interface SdkModelExampleValue extends SdkExampleTypeBase { kind: "model"; type: SdkModelType; - value: Record; - additionalPropertiesValue?: Record; + value: Record; + additionalPropertiesValue?: Record; } ``` @@ -1728,7 +1737,7 @@ function serializeServiceOperationExample( function serializeTypeExample( context: PythonSdkContext, - example: SdkTypeExample + example: SdkExampleValue ): PythonSdkTypeExample { switch (example.kind) { case "string": @@ -1751,7 +1760,7 @@ function serializeTypeExample( ...example, type: getPythonSdkType(context, example.type), }; - case "any": + case "unknown": return { ...example, type: getPythonSdkType(context, example.type), diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 45b60574a0..b6753c8b7d 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -731,7 +731,7 @@ export type SdkExampleValue = | SdkUnionExampleValue | SdkModelExampleValue; -export interface SdkExampleValueBase { +interface SdkExampleValueBase { kind: string; type: SdkType; value: unknown;