Skip to content

Commit

Permalink
Backmerge/release/september 2024 2024 09 19 (#1564)
Browse files Browse the repository at this point in the history
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Wei Hu <huwe@microsoft.com>
Co-authored-by: Dapeng Zhang <dapzhang@microsoft.com>
Co-authored-by: iscai-msft <43154838+iscai-msft@users.noreply.github.com>
Co-authored-by: iscai-msft <isabellavcai@gmail.com>
  • Loading branch information
7 people authored Sep 19, 2024
1 parent 2b288d0 commit 744b327
Show file tree
Hide file tree
Showing 33 changed files with 916 additions and 625 deletions.
99 changes: 55 additions & 44 deletions docs/howtos/Client Generation/07tcgcTypes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -911,8 +911,8 @@ export interface SdkHttpOperation {
bodyParam: SdkBodyParameter;
// mapping of status codes to SdkHttpResponse for valid responses
// HttpStatusCodeRange can represent either a single status code or a range.
responses: Map<HttpStatusCodeRange, SdkHttpResponse>;
exceptions: Map<HttpStatusCodeRange, SdkHttpResponse>;
responses: SdkHttpResponse[];
exceptions: SdkHttpResponse[];
examples?: SdkHttpOperationExample[];
}
```
Expand Down Expand Up @@ -1277,6 +1277,7 @@ interface HttpStatusCodeRange {

export interface SdkHttpResponse {
kind: "http";
statusCodes: number | HttpStatusCodeRange | "*";
headers: SdkServiceResponseHeader[];
apiVersions: string[];
type?: SdkType;
Expand Down Expand Up @@ -1315,7 +1316,7 @@ There is a one-to-one mapping between the TypeSpec scalar kinds and the `SdkBuil
```ts
export interface SdkBuiltInType extends SdkTypeBase {
kind: SdkBuiltInKinds;
encode: string;
encode?: string;
name: string;
baseType?: SdkBuiltInType;
crossLanguageDefinitionId: string;
Expand Down Expand Up @@ -1430,11 +1431,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 +1512,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 +1527,54 @@ interface SdkExampleBase {

export interface SdkHttpOperationExample extends SdkExampleBase {
kind: "http";
parameters: SdkHttpParameterExample[];
responses: Map<number, SdkHttpResponseExample>;
parameters: SdkHttpParameterExampleValue[];
responses: 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;
statusCode: number;
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 +1586,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 +1598,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 +1739,7 @@ function serializeServiceOperationExample(

function serializeTypeExample(
context: PythonSdkContext<SdkHttpOperation>,
example: SdkTypeExample,
example: SdkExampleValue,
): PythonSdkTypeExample {
switch (example.kind) {
case "string":
Expand All @@ -1751,7 +1762,7 @@ function serializeTypeExample(
...example,
type: getPythonSdkType(context, example.type),
};
case "any":
case "unknown":
return {
...example,
type: getPythonSdkType(context, example.type),
Expand Down
39 changes: 39 additions & 0 deletions packages/typespec-client-generator-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Change Log - @azure-tools/typespec-client-generator-core

## 0.46.1

### Bug Fixes

- [#1491](https://github.com/Azure/typespec-azure/pull/1491) Fix naming logic for anonymous model wrapped by `HttpPart`
- [#1542](https://github.com/Azure/typespec-azure/pull/1542) Fix `subscriptionId` for ARM SDK
- [#1558](https://github.com/Azure/typespec-azure/pull/1558) Handle orphan types in nested namespaces
- [#1554](https://github.com/Azure/typespec-azure/pull/1554) Fix `onClient` setting for client initialization parameters applied to an interface

### Breaking Changes

- [#1540](https://github.com/Azure/typespec-azure/pull/1540)
1. The type of `responses` and `exceptions` in `SdkHttpOperation` changed from `Map<number | HttpStatusCodeRange | "*", SdkHttpResponse>` to `SdkHttpResponse[]`.
2. The type of `responses` in `SdkHttpOperationExample` changed from `Map<number, SdkHttpResponseExampleValue>` to `SdkHttpResponseExampleValue[]`.
3. `SdkHttpResponse` adds a new property `statusCodes` to store its corresponding status code or status code range.
Migration hints:
The type changed from map to array, and the key of the map is moved as a new property of the value type. For example, for code like this:
```
for (const [statusCodes, response] of operation.responses)
```
you could do the same in this way:
```
for (const response of operation.responses)
{
const statusCodes = response.statusCodes;
}
```
- [#1463](https://github.com/Azure/typespec-azure/pull/1463)
1. The kind for `unknown` renamed from `any` to `unknown`.
2. The `values` property in `SdkUnionType` renamed to `variantTypes`.
3. The `values` property in `SdkTupleType` renamed to `valueTypes`.
4. The example types for parameter, response and `SdkType` has been renamed to `XXXExampleValue` to emphasize that they are values instead of the example itself.
5. The `@format` decorator is no longer able to change the type of the property.
- [#1539](https://github.com/Azure/typespec-azure/pull/1539)
1. change `encode` in `SdkBuiltInType` to optional.
2. no longer use the value of `kind` as `encode` when there is no encode on this type.
- [#1541](https://github.com/Azure/typespec-azure/pull/1541) 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`.


## 0.46.0

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/typespec-client-generator-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@azure-tools/typespec-client-generator-core",
"version": "0.46.0",
"version": "0.46.1",
"author": "Microsoft Corporation",
"description": "TypeSpec Data Plane Generation library",
"homepage": "https://azure.github.io/typespec-azure",
Expand Down
Loading

0 comments on commit 744b327

Please sign in to comment.