Skip to content

Commit 08bc8a9

Browse files
Copilotv-jiaodi
andauthored
chore: bump TypeSpec dependencies to latest stable (#3932)
* Initial plan * chore: bump TypeSpec dependencies to latest stable versions Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/22197519-3d49-42b1-a2e8-d788d9cb720c Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * fix: apply clientDefaultValue to model property serialization and regenerate client-default-value Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/af5c506e-4c1d-477a-a573-1f145eddb32a Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> * update --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com> Co-authored-by: Jiao Di (MSFT) <v-jiaodi@microsoft.com>
1 parent 0148c04 commit 08bc8a9

4 files changed

Lines changed: 126 additions & 89 deletions

File tree

packages/typespec-test/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
"@typespec/openapi": "^1.11.0",
88
"@azure-tools/typespec-autorest": "^0.67.0",
99
"@typespec/openapi3": "^1.11.0",
10-
"@azure-tools/typespec-azure-core": "^0.67.0",
11-
"@azure-tools/typespec-client-generator-core": "^0.67.2",
10+
"@azure-tools/typespec-azure-core": "^0.67.1",
11+
"@azure-tools/typespec-client-generator-core": "^0.67.3",
1212
"@azure-tools/typespec-azure-resource-manager": "^0.67.1",
1313
"@azure-tools/typespec-azure-rulesets": "^0.67.0",
1414
"@typespec/compiler": "^1.11.0",

packages/typespec-ts/package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,15 @@
6565
"license": "MIT",
6666
"devDependencies": {
6767
"@azure-rest/core-client": "^2.3.1",
68-
"@typespec/http-specs": "0.1.0-alpha.36-dev.3",
69-
"@typespec/spector": "0.1.0-alpha.25-dev.5",
70-
"@typespec/spec-api": "0.1.0-alpha.14-dev.4",
68+
"@typespec/http-specs": "0.1.0-alpha.37-dev.3",
69+
"@typespec/spector": "0.1.0-dev.4",
70+
"@typespec/spec-api": "0.1.0-dev.3",
7171
"@typespec/tspd": "0.74.1",
72-
"@azure-tools/azure-http-specs": "0.1.0-alpha.40-dev.4",
72+
"@azure-tools/azure-http-specs": "0.1.0-alpha.40-dev.6",
7373
"@azure-tools/typespec-autorest": "^0.67.0",
74-
"@azure-tools/typespec-azure-core": "^0.67.0",
74+
"@azure-tools/typespec-azure-core": "^0.67.1",
7575
"@azure-tools/typespec-azure-resource-manager": "^0.67.1",
76-
"@azure-tools/typespec-client-generator-core": "^0.67.2",
76+
"@azure-tools/typespec-client-generator-core": "^0.67.3",
7777
"@azure/abort-controller": "^2.1.2",
7878
"@azure/core-auth": "^1.6.0",
7979
"@azure/core-lro": "^3.1.0",
@@ -110,8 +110,8 @@
110110
"js-yaml": "^4.1.0"
111111
},
112112
"peerDependencies": {
113-
"@azure-tools/typespec-azure-core": "^0.67.0",
114-
"@azure-tools/typespec-client-generator-core": "^0.67.2",
113+
"@azure-tools/typespec-azure-core": "^0.67.1",
114+
"@azure-tools/typespec-client-generator-core": "^0.67.3",
115115
"@typespec/compiler": "^1.11.0",
116116
"@typespec/http": "^1.11.0",
117117
"@typespec/rest": "^0.81.0",

packages/typespec-ts/src/modular/helpers/operationHelpers.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2318,12 +2318,20 @@ export function getSerializationExpression(
23182318
skipDiscriminatedUnionSuffix: false
23192319
}
23202320
);
2321+
2322+
// Apply clientDefaultValue for model properties that have one
2323+
const defaultValueSuffix =
2324+
property.clientDefaultValue !== undefined &&
2325+
isDefaultValueTypeMatch(property, property.clientDefaultValue)
2326+
? ` ?? ${formatDefaultValue(property.clientDefaultValue)}`
2327+
: "";
2328+
23212329
if (serializeFunctionName) {
2322-
return `${nullOrUndefinedPrefix}${serializeFunctionName}(${propertyFullName})`;
2330+
return `${nullOrUndefinedPrefix}${serializeFunctionName}(${propertyFullName})${defaultValueSuffix}`;
23232331
} else if (isAzureCoreErrorType(context.program, property.type.__raw)) {
2324-
return `${nullOrUndefinedPrefix}${propertyFullName}`;
2332+
return `${nullOrUndefinedPrefix}${propertyFullName}${defaultValueSuffix}`;
23252333
} else {
2326-
return serializeRequestValue(
2334+
const baseExpr = serializeRequestValue(
23272335
context,
23282336
property.type,
23292337
propertyFullName,
@@ -2332,6 +2340,7 @@ export function getSerializationExpression(
23322340
getPropertySerializedName(property),
23332341
propertyPath === "" ? true : false
23342342
);
2343+
return `${baseExpr}${defaultValueSuffix}`;
23352344
}
23362345
}
23372346

@@ -2880,11 +2889,11 @@ export function getAllAncestors(type: SdkType): SdkType[] {
28802889
}
28812890

28822891
/**
2883-
* Checks if a clientDefaultValue type matches the parameter type.
2884-
* Returns true if the default value type is compatible with the parameter type.
2892+
* Checks if a clientDefaultValue type matches a parameter or model property type.
2893+
* Returns true if the default value type is compatible with the target type.
28852894
*/
28862895
function isDefaultValueTypeMatch(
2887-
param: SdkHttpParameter | SdkBodyParameter,
2896+
param: SdkHttpParameter | SdkBodyParameter | SdkModelPropertyType,
28882897
defaultValue: unknown
28892898
): boolean {
28902899
const defaultType = typeof defaultValue;

0 commit comments

Comments
 (0)