Skip to content

Commit

Permalink
[TCGC] update references for #1463 (#1541)
Browse files Browse the repository at this point in the history
Update references after merged #1463
  • Loading branch information
ArcturusZhang committed Sep 14, 2024
1 parent 7c7f170 commit 9a978d0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -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`.
91 changes: 50 additions & 41 deletions docs/howtos/Client Generation/07tcgcTypes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.

Expand All @@ -1517,53 +1526,53 @@ interface SdkExampleBase {

export interface SdkHttpOperationExample extends SdkExampleBase {
kind: "http";
parameters: SdkHttpParameterExample[];
responses: Map<number, SdkHttpResponseExample>;
parameters: SdkHttpParameterExampleValue[];
responses: Map<number, SdkHttpResponseExampleValue>;
}

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
Expand All @@ -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
Expand All @@ -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<string, SdkTypeExample>;
value: Record<string, SdkExampleValue>;
}

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<string, SdkTypeExample>;
additionalPropertiesValue?: Record<string, SdkTypeExample>;
value: Record<string, SdkExampleValue>;
additionalPropertiesValue?: Record<string, SdkExampleValue>;
}
```

Expand Down Expand Up @@ -1728,7 +1737,7 @@ function serializeServiceOperationExample(

function serializeTypeExample(
context: PythonSdkContext<SdkHttpOperation>,
example: SdkTypeExample
example: SdkExampleValue
): PythonSdkTypeExample {
switch (example.kind) {
case "string":
Expand All @@ -1751,7 +1760,7 @@ function serializeTypeExample(
...example,
type: getPythonSdkType(context, example.type),
};
case "any":
case "unknown":
return {
...example,
type: getPythonSdkType(context, example.type),
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export type SdkExampleValue =
| SdkUnionExampleValue
| SdkModelExampleValue;

export interface SdkExampleValueBase {
interface SdkExampleValueBase {
kind: string;
type: SdkType;
value: unknown;
Expand Down

0 comments on commit 9a978d0

Please sign in to comment.