Skip to content

Commit 7822426

Browse files
authored
Bump TypeSpec to 1.6.0 (#53971)
1 parent 67fb5e5 commit 7822426

26 files changed

+423
-351
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,6 @@
486486
<PropertyGroup>
487487
<TestProxyVersion>1.0.0-dev.20250930.1</TestProxyVersion>
488488
<UnbrandedGeneratorVersion>1.0.0-alpha.20251113.2</UnbrandedGeneratorVersion>
489-
<AzureGeneratorVersion>1.0.0-alpha.20251113.1</AzureGeneratorVersion>
489+
<AzureGeneratorVersion>1.0.0-alpha.20251114.1</AzureGeneratorVersion>
490490
</PropertyGroup>
491491
</Project>

eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts

Lines changed: 111 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
armResourceListName,
3636
armResourceReadName,
3737
armResourceUpdateName,
38+
extensionResourceOperationName,
3839
nonResourceMethodMetadata,
3940
parentResourceName,
4041
resourceGroupResource,
@@ -155,9 +156,9 @@ export async function updateClients(
155156
for (const [modelId, metadata] of resourceModelToMetadataMap) {
156157
// TODO: handle the case where there is no parentResourceId but resourceIdPattern is missing
157158
if (metadata.resourceIdPattern === "" && metadata.parentResourceModelId) {
158-
resourceModelToMetadataMap.get(metadata.parentResourceModelId)?.methods.push(
159-
...metadata.methods
160-
);
159+
resourceModelToMetadataMap
160+
.get(metadata.parentResourceModelId)
161+
?.methods.push(...metadata.methods);
161162
resourceModelToMetadataMap.delete(modelId);
162163
}
163164
}
@@ -193,36 +194,95 @@ function parseResourceOperation(
193194
): [ResourceOperationKind, string | undefined] | undefined {
194195
const decorators = serviceMethod?.__raw?.decorators;
195196
for (const decorator of decorators ?? []) {
196-
if (decorator.definition?.name === armResourceReadName) {
197-
return [
198-
ResourceOperationKind.Get,
199-
getResourceModelId(sdkContext, decorator)
200-
];
201-
} else if (decorator.definition?.name == armResourceCreateOrUpdateName) {
202-
return [
203-
ResourceOperationKind.Create,
204-
getResourceModelId(sdkContext, decorator)
205-
];
206-
} else if (decorator.definition?.name == armResourceUpdateName) {
207-
return [
208-
ResourceOperationKind.Update,
209-
getResourceModelId(sdkContext, decorator)
210-
];
211-
} else if (decorator.definition?.name == armResourceDeleteName) {
212-
return [
213-
ResourceOperationKind.Delete,
214-
getResourceModelId(sdkContext, decorator)
215-
];
216-
} else if (decorator.definition?.name == armResourceListName) {
217-
return [
218-
ResourceOperationKind.List,
219-
getResourceModelId(sdkContext, decorator)
220-
];
221-
} else if (decorator.definition?.name == armResourceActionName) {
222-
return [
223-
ResourceOperationKind.Action,
224-
getResourceModelId(sdkContext, decorator)
225-
];
197+
switch (decorator.definition?.name) {
198+
case armResourceReadName:
199+
return [
200+
ResourceOperationKind.Get,
201+
getResourceModelId(sdkContext, decorator)
202+
];
203+
case armResourceCreateOrUpdateName:
204+
return [
205+
ResourceOperationKind.Create,
206+
getResourceModelId(sdkContext, decorator)
207+
];
208+
case armResourceUpdateName:
209+
return [
210+
ResourceOperationKind.Update,
211+
getResourceModelId(sdkContext, decorator)
212+
];
213+
case armResourceDeleteName:
214+
return [
215+
ResourceOperationKind.Delete,
216+
getResourceModelId(sdkContext, decorator)
217+
];
218+
case armResourceListName:
219+
return [
220+
ResourceOperationKind.List,
221+
getResourceModelId(sdkContext, decorator)
222+
];
223+
case armResourceActionName:
224+
return [
225+
ResourceOperationKind.Action,
226+
getResourceModelId(sdkContext, decorator)
227+
];
228+
case extensionResourceOperationName:
229+
switch (decorator.args[2].jsValue) {
230+
case "read":
231+
return [
232+
ResourceOperationKind.Get,
233+
getResourceModelIdCore(
234+
sdkContext,
235+
decorator.args[1].value as Model,
236+
decorator.definition?.name
237+
)
238+
];
239+
case "createOrUpdate":
240+
return [
241+
ResourceOperationKind.Create,
242+
getResourceModelIdCore(
243+
sdkContext,
244+
decorator.args[1].value as Model,
245+
decorator.definition?.name
246+
)
247+
];
248+
case "update":
249+
return [
250+
ResourceOperationKind.Update,
251+
getResourceModelIdCore(
252+
sdkContext,
253+
decorator.args[1].value as Model,
254+
decorator.definition?.name
255+
)
256+
];
257+
case "delete":
258+
return [
259+
ResourceOperationKind.Delete,
260+
getResourceModelIdCore(
261+
sdkContext,
262+
decorator.args[1].value as Model,
263+
decorator.definition?.name
264+
)
265+
];
266+
case "list":
267+
return [
268+
ResourceOperationKind.List,
269+
getResourceModelIdCore(
270+
sdkContext,
271+
decorator.args[1].value as Model,
272+
decorator.definition?.name
273+
)
274+
];
275+
case "action":
276+
return [
277+
ResourceOperationKind.Action,
278+
getResourceModelIdCore(
279+
sdkContext,
280+
decorator.args[1].value as Model,
281+
decorator.definition?.name
282+
)
283+
];
284+
}
285+
return undefined;
226286
}
227287
}
228288
return undefined;
@@ -244,18 +304,27 @@ function getResourceModelId(
244304
decorator?: DecoratorApplication
245305
): string | undefined {
246306
if (!decorator) return undefined;
247-
const model = getClientType(
307+
return getResourceModelIdCore(
248308
sdkContext,
249-
decorator.args[0].value as Model
250-
) as SdkModelType;
309+
decorator.args[0].value as Model,
310+
decorator.definition?.name
311+
);
312+
}
313+
314+
function getResourceModelIdCore(
315+
sdkContext: CSharpEmitterContext,
316+
decoratorModel: Model,
317+
decoratorName?: string
318+
): string | undefined {
319+
const model = getClientType(sdkContext, decoratorModel) as SdkModelType;
251320
if (model) {
252321
return model.crossLanguageDefinitionId;
253322
} else {
254323
sdkContext.logger.reportDiagnostic({
255324
code: "general-error",
256325
messageId: "default",
257326
format: {
258-
message: `Resource model not found for decorator ${decorator.decorator.name}`
327+
message: `Resource model not found for decorator ${decoratorName}`
259328
},
260329
target: NoTarget
261330
});
@@ -369,7 +438,11 @@ function getOperationScope(path: string): ResourceScope {
369438
return ResourceScope.ResourceGroup;
370439
} else if (path.startsWith("/subscriptions/{subscriptionId}/")) {
371440
return ResourceScope.Subscription;
372-
} else if (path.startsWith("/providers/Microsoft.Management/managementGroups/{managementGroupId}/")) {
441+
} else if (
442+
path.startsWith(
443+
"/providers/Microsoft.Management/managementGroups/{managementGroupId}/"
444+
)
445+
) {
373446
return ResourceScope.ManagementGroup;
374447
}
375448
return ResourceScope.Tenant; // all the templates work as if there is a tenant decorator when there is no such decorator

eng/packages/http-client-csharp-mgmt/emitter/src/resource-metadata.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const ResourceGroupScopePrefix =
55
"/subscriptions/{subscriptionId}/resourceGroups";
66
const SubscriptionScopePrefix = "/subscriptions";
77
const TenantScopePrefix = "/tenants";
8-
const ManagementGroupScopePrefix = "/providers/Microsoft.Management/managementGroups";
8+
const ManagementGroupScopePrefix =
9+
"/providers/Microsoft.Management/managementGroups";
910
const Providers = "/providers";
1011

1112
export function calculateResourceTypeFromPath(path: string): string {
@@ -46,7 +47,7 @@ export interface ResourceMetadata {
4647
methods: ResourceMethod[];
4748
resourceScope: ResourceScope;
4849
parentResourceId?: string;
49-
parentResourceModelId? : string;
50+
parentResourceModelId?: string;
5051
singletonResourceName?: string;
5152
resourceName: string;
5253
}

eng/packages/http-client-csharp-mgmt/emitter/src/sdk-context-options.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export const armResourceUpdate = "Azure.ResourceManager.@armResourceUpdate";
5454
export const armResourceUpdateName = "@armResourceUpdate";
5555
const armResourceUpdateRegex = "Azure\\.ResourceManager\\.@armResourceUpdate";
5656

57+
export const extensionResourceOperationName = "@extensionResourceOperation";
58+
5759
export const armResourceInternal =
5860
"Azure.ResourceManager.Private.@armResourceInternal";
5961
export const armResourceInternalName = "@armResourceInternal";

eng/packages/http-client-csharp-mgmt/emitter/test/resource-detection.test.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,32 +1097,45 @@ interface Employees {
10971097
const sdkContext = await createCSharpSdkContext(context);
10981098
const root = createModel(sdkContext);
10991099
updateClients(root, sdkContext);
1100-
1101-
const employeeClient = getAllClients(root).find((c) => c.name === "Employees");
1100+
1101+
const employeeClient = getAllClients(root).find(
1102+
(c) => c.name === "Employees"
1103+
);
11021104
ok(employeeClient);
1103-
const employeeParentClient = getAllClients(root).find((c) => c.name === "EmployeeParents");
1105+
const employeeParentClient = getAllClients(root).find(
1106+
(c) => c.name === "EmployeeParents"
1107+
);
11041108
ok(employeeParentClient);
1105-
1109+
11061110
const employeeModel = root.models.find((m) => m.name === "Employee");
11071111
ok(employeeModel);
1108-
const employeeParentModel = root.models.find((m) => m.name === "EmployeeParent");
1112+
const employeeParentModel = root.models.find(
1113+
(m) => m.name === "EmployeeParent"
1114+
);
11091115
ok(employeeParentModel);
1110-
1111-
const listByParentMethod = employeeClient.methods.find((m) => m.name === "listByParent");
1116+
1117+
const listByParentMethod = employeeClient.methods.find(
1118+
(m) => m.name === "listByParent"
1119+
);
11121120
ok(listByParentMethod);
1113-
const getMethod = employeeParentClient.methods.find((m) => m.name === "get");
1121+
const getMethod = employeeParentClient.methods.find(
1122+
(m) => m.name === "get"
1123+
);
11141124
ok(getMethod);
11151125

11161126
// Validate Employee resource metadata should be null (no CRUD operations)
11171127
const employeeResourceMetadataDecorator = employeeModel.decorators?.find(
11181128
(d) => d.name === resourceMetadata
11191129
);
1120-
strictEqual(employeeResourceMetadataDecorator, undefined, "Employee should not have resource metadata decorator without CRUD operations");
1130+
strictEqual(
1131+
employeeResourceMetadataDecorator,
1132+
undefined,
1133+
"Employee should not have resource metadata decorator without CRUD operations"
1134+
);
11211135

11221136
// Validate EmployeeParent resource metadata
1123-
const parentResourceMetadataDecorator = employeeParentModel.decorators?.find(
1124-
(d) => d.name === resourceMetadata
1125-
);
1137+
const parentResourceMetadataDecorator =
1138+
employeeParentModel.decorators?.find((d) => d.name === resourceMetadata);
11261139
ok(parentResourceMetadataDecorator);
11271140
ok(parentResourceMetadataDecorator.arguments);
11281141
strictEqual(
@@ -1137,14 +1150,21 @@ interface Employees {
11371150
parentResourceMetadataDecorator.arguments.resourceScope,
11381151
"ResourceGroup"
11391152
);
1140-
strictEqual(parentResourceMetadataDecorator.arguments.parentResourceId, undefined);
1141-
strictEqual(parentResourceMetadataDecorator.arguments.resourceName, "EmployeeParent");
1153+
strictEqual(
1154+
parentResourceMetadataDecorator.arguments.parentResourceId,
1155+
undefined
1156+
);
1157+
strictEqual(
1158+
parentResourceMetadataDecorator.arguments.resourceName,
1159+
"EmployeeParent"
1160+
);
11421161
strictEqual(parentResourceMetadataDecorator.arguments.methods.length, 2);
11431162

11441163
// Validate EmployeeParent listByParent method
1145-
const listByParentEntry = parentResourceMetadataDecorator.arguments.methods.find(
1146-
(m: any) => m.methodId === listByParentMethod.crossLanguageDefinitionId
1147-
);
1164+
const listByParentEntry =
1165+
parentResourceMetadataDecorator.arguments.methods.find(
1166+
(m: any) => m.methodId === listByParentMethod.crossLanguageDefinitionId
1167+
);
11481168
ok(listByParentEntry);
11491169
});
11501170

@@ -1181,10 +1201,12 @@ interface Employees {
11811201
const sdkContext = await createCSharpSdkContext(context);
11821202
const root = createModel(sdkContext);
11831203
updateClients(root, sdkContext);
1184-
1185-
const employeeClient = getAllClients(root).find((c) => c.name === "Employees");
1204+
1205+
const employeeClient = getAllClients(root).find(
1206+
(c) => c.name === "Employees"
1207+
);
11861208
ok(employeeClient);
1187-
1209+
11881210
const employeeModel = root.models.find((m) => m.name === "Employee");
11891211
ok(employeeModel);
11901212

0 commit comments

Comments
 (0)