Skip to content

Commit f44fc31

Browse files
author
Pan Shao
committed
interface name change
1 parent b6d8df9 commit f44fc31

File tree

25 files changed

+116
-100
lines changed

25 files changed

+116
-100
lines changed

packages/extensions/openapi-to-typespec/src/transforms/transform-arm-resources.ts

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Operation, Parameter, Property, SchemaType } from "@autorest/codemodel";
22
import _ from "lodash";
3-
import pluralize, { singular } from "pluralize";
3+
import { singular } from "pluralize";
44
import { getSession } from "../autorest-session";
55
import { getDataTypes } from "../data-types";
66
import {
@@ -49,6 +49,7 @@ import {
4949
import { getFullyQualifiedName, getTemplateResponses, NamesOfResponseTemplate } from "../utils/type-mapping";
5050
import { getTypespecType, isTypespecType, transformObjectProperty } from "./transform-object";
5151
import { transformParameter } from "./transform-operations";
52+
import { getTSPOperationGroupName } from "../utils/operation-group";
5253

5354
const logger = () => getLogger("transform-arm-resources");
5455

@@ -893,35 +894,6 @@ function getOtherProperties(
893894
return otherProperties;
894895
}
895896

896-
const operationGroupNameCache: Map<ArmResource, string> = new Map<ArmResource, string>();
897-
export function getTSPOperationGroupName(resourceMetadata: ArmResource): string {
898-
if (operationGroupNameCache.has(resourceMetadata)) return operationGroupNameCache.get(resourceMetadata)!;
899-
900-
// Try pluralizing the resource name first
901-
let operationGroupName = pluralize(resourceMetadata.SwaggerModelName);
902-
if (operationGroupName !== resourceMetadata.SwaggerModelName && !isExistingOperationGroupName(operationGroupName)) {
903-
operationGroupNameCache.set(resourceMetadata, operationGroupName);
904-
} else {
905-
// Try operationId then
906-
operationGroupName = resourceMetadata.GetOperation!.OperationID.split("_")[0];
907-
if (operationGroupName !== resourceMetadata.SwaggerModelName && !isExistingOperationGroupName(operationGroupName)) {
908-
operationGroupNameCache.set(resourceMetadata, operationGroupName);
909-
} else {
910-
operationGroupName = `${resourceMetadata.SwaggerModelName}OperationGroup`;
911-
operationGroupNameCache.set(resourceMetadata, operationGroupName);
912-
}
913-
}
914-
return operationGroupName;
915-
}
916-
917-
function isExistingOperationGroupName(operationGroupName: string): boolean {
918-
const codeModel = getSession().model;
919-
return (
920-
codeModel.schemas.objects?.find((o) => o.language.default.name === operationGroupName) !== undefined ||
921-
Array.from(operationGroupNameCache.values()).find((v) => v === operationGroupName) !== undefined
922-
);
923-
}
924-
925897
function getBodyDecorators(
926898
bodyParam: Parameter | undefined,
927899
tspOperationGroupName: string,

packages/extensions/openapi-to-typespec/src/transforms/transform-operations.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ import { getLogger } from "../utils/logger";
3030
import { getLanguageMetadata } from "../utils/metadata";
3131
import { generateAdditionalProperties, generateTemplateModel } from "../utils/model-generation";
3232
import { transformSchemaResponse } from "../utils/response";
33-
import { isArraySchema, isConstantSchema, isResponseSchema } from "../utils/schemas";
33+
import { isConstantSchema, isResponseSchema } from "../utils/schemas";
3434
import { getSuppressionWithCode, SuppressionCode } from "../utils/suppressions";
3535
import { getDefaultValue } from "../utils/values";
36+
import { getTSPNonResourceOperationGroupName } from "../utils/operation-group";
3637

3738
export function transformOperationGroup(
3839
{ language, operations }: OperationGroup,
3940
codeModel: CodeModel,
4041
): TypespecOperationGroup {
41-
const name = language.default.name ? `${language.default.name}Operations` : "";
42+
const name = language.default.name ? getTSPNonResourceOperationGroupName(language.default.name) : "";
4243
const doc = language.default.description;
4344
const ops = operations.reduce<(TypespecOperation | TspArmProviderActionOperation)[]>((acc, op) => {
4445
acc = [...acc, ...transformOperation(op, codeModel, name)];
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import pluralize from "pluralize";
2+
import { ArmResource } from "./resource-discovery";
3+
import { getSession } from "../autorest-session";
4+
import { getOptions } from "../options";
5+
6+
const operationGroupNameCache: Map<ArmResource, string> = new Map<ArmResource, string>();
7+
export function getTSPOperationGroupName(resourceMetadata: ArmResource): string {
8+
if (operationGroupNameCache.has(resourceMetadata)) return operationGroupNameCache.get(resourceMetadata)!;
9+
10+
// Try pluralizing the resource name first
11+
let operationGroupName = pluralize(resourceMetadata.SwaggerModelName);
12+
if (operationGroupName !== resourceMetadata.SwaggerModelName && !isExistingOperationGroupName(operationGroupName)) {
13+
operationGroupNameCache.set(resourceMetadata, operationGroupName);
14+
} else {
15+
// Try operationId then
16+
operationGroupName = resourceMetadata.GetOperation!.OperationID.split("_")[0];
17+
if (operationGroupName !== resourceMetadata.SwaggerModelName && !isExistingOperationGroupName(operationGroupName)) {
18+
operationGroupNameCache.set(resourceMetadata, operationGroupName);
19+
} else {
20+
operationGroupName = `${resourceMetadata.SwaggerModelName}OperationGroup`;
21+
operationGroupNameCache.set(resourceMetadata, operationGroupName);
22+
}
23+
}
24+
return operationGroupName;
25+
}
26+
27+
function isExistingOperationGroupName(operationGroupName: string): boolean {
28+
const codeModel = getSession().model;
29+
return (
30+
codeModel.schemas.objects?.find((o) => o.language.default.name === operationGroupName) !== undefined ||
31+
Array.from(operationGroupNameCache.values()).find((v) => v === operationGroupName) !== undefined
32+
);
33+
}
34+
35+
export function getTSPNonResourceOperationGroupName(name: string): string {
36+
const operationGroupName = `${name}OperationGroup`;
37+
if (!isExistingOperationGroupName(operationGroupName)) {
38+
return operationGroupName;
39+
}
40+
41+
// Arm resource operation group name cannot be ended with "Operations"
42+
return getOptions().isArm ? `${name}NonResourceOperationGroup` : `${name}Operations`;
43+
}

packages/extensions/openapi-to-typespec/test/analyzeText/tsp-output/routes.tsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ using TypeSpec.OpenAPI;
99

1010
namespace Azure.Language.Authoring;
1111

12-
interface TextAnalysisAuthoringOperations {
12+
interface TextAnalysisAuthoringOperationGroup {
1313
/**
1414
* Lists the existing projects.
1515
*/

packages/extensions/openapi-to-typespec/test/arm-agrifood/tsp-output/routes.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Microsoft.AgFoodPlatform;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface CheckNameAvailabilityOperations {
17+
interface CheckNameAvailabilityOperationGroup {
1818
/**
1919
* Checks the name availability of the resource with requested resource name.
2020
*/
@@ -30,7 +30,7 @@ interface CheckNameAvailabilityOperations {
3030
}
3131

3232
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
33-
interface OperationResultsOperations {
33+
interface OperationResultsOperationGroup {
3434
/**
3535
* Get operationResults for a Data Manager For Agriculture resource.
3636
*/

packages/extensions/openapi-to-typespec/test/arm-alertsmanagement/tsp-output/routes.tsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Azure.ResourceManager.AlertsManagement;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface AlertsOperations {
17+
interface AlertsOperationGroup {
1818
/**
1919
* List alerts meta data information based on value of identifier parameter.
2020
*/

packages/extensions/openapi-to-typespec/test/arm-analysisservices/tsp-output/routes.tsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Azure.ResourceManager.Analysis;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface ServersOperations {
17+
interface ServersOperationGroup {
1818
/**
1919
* Lists eligible SKUs for Analysis Services resource provider.
2020
*/

packages/extensions/openapi-to-typespec/test/arm-apimanagement/tsp-output/routes.tsp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Azure.ResourceManager.ApiManagement;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface ApiExportOperations {
17+
interface ApiExportOperationGroup {
1818
/**
1919
* Gets the details of the API specified by its identifier in the format specified to the Storage Blob with SAS Key valid for 5 minutes.
2020
*/
@@ -61,7 +61,7 @@ interface ApiExportOperations {
6161
}
6262

6363
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
64-
interface DeletedServicesOperations {
64+
interface DeletedServicesOperationGroup {
6565
/**
6666
* Lists all soft-deleted services available for undelete for the given subscription.
6767
*/
@@ -78,7 +78,7 @@ interface DeletedServicesOperations {
7878
}
7979

8080
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
81-
interface ApiManagementServiceOperations {
81+
interface ApiManagementServiceOperationGroup {
8282
/**
8383
* Checks availability and correctness of a name for an API Management service.
8484
*/
@@ -105,7 +105,7 @@ interface ApiManagementServiceOperations {
105105
}
106106

107107
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
108-
interface ApiManagementSkusOperations {
108+
interface ApiManagementSkusOperationGroup {
109109
/**
110110
* Gets the list of Microsoft.ApiManagement SKUs available for your Subscription.
111111
*/

packages/extensions/openapi-to-typespec/test/arm-authorization/tsp-output/routes.tsp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Azure.ResourceManager.Authorization;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface ClassicAdministratorsOperations {
17+
interface ClassicAdministratorsOperationGroup {
1818
/**
1919
* Gets service administrator, account administrator, and co-administrators for the subscription.
2020
*/
@@ -31,7 +31,7 @@ interface ClassicAdministratorsOperations {
3131
}
3232

3333
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
34-
interface GlobalAdministratorOperations {
34+
interface GlobalAdministratorOperationGroup {
3535
/**
3636
* Elevates access for a Global Administrator.
3737
*/
@@ -42,7 +42,7 @@ interface GlobalAdministratorOperations {
4242
}
4343

4444
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
45-
interface AzurePermissionsForResourceGroupOperations {
45+
interface AzurePermissionsForResourceGroupOperationGroup {
4646
/**
4747
* Gets all permissions the caller has for a resource group.
4848
*/
@@ -58,7 +58,7 @@ interface AzurePermissionsForResourceGroupOperations {
5858
}
5959

6060
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
61-
interface AzurePermissionsForResourceOperations {
61+
interface AzurePermissionsForResourceOperationGroup {
6262
/**
6363
* Gets all permissions the caller has for a resource.
6464
*/
@@ -99,7 +99,7 @@ interface AzurePermissionsForResourceOperations {
9999
}
100100

101101
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
102-
interface EligibleChildResourcesOperations {
102+
interface EligibleChildResourcesOperationGroup {
103103
/**
104104
* Get the child resources of a resource on which user has eligible access
105105
*/

packages/extensions/openapi-to-typespec/test/arm-compute/tsp-output/routes.tsp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ using TypeSpec.OpenAPI;
1414
namespace Microsoft.Compute;
1515

1616
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
17-
interface UsageOperations {
17+
interface UsageOperationGroup {
1818
/**
1919
* Gets, for the specified location, the current compute resource usage information as well as the limits for compute resources under the subscription.
2020
*/
@@ -31,7 +31,7 @@ interface UsageOperations {
3131
}
3232

3333
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
34-
interface VirtualMachineSizesOperations {
34+
interface VirtualMachineSizesOperationGroup {
3535
/**
3636
* This API is deprecated. Use [Resources Skus](https://docs.microsoft.com/rest/api/compute/resourceskus/list)
3737
*/
@@ -48,7 +48,7 @@ interface VirtualMachineSizesOperations {
4848
}
4949

5050
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
51-
interface VirtualMachineScaleSetsOperations {
51+
interface VirtualMachineScaleSetsOperationGroup {
5252
/**
5353
* Gets all the VM scale sets under the specified subscription for the specified location.
5454
*/
@@ -65,7 +65,7 @@ interface VirtualMachineScaleSetsOperations {
6565
}
6666

6767
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
68-
interface VirtualMachinesOperations {
68+
interface VirtualMachinesOperationGroup {
6969
/**
7070
* Gets all the virtual machines under the specified subscription for the specified location.
7171
*/
@@ -82,7 +82,7 @@ interface VirtualMachinesOperations {
8282
}
8383

8484
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
85-
interface VirtualMachineImagesOperations {
85+
interface VirtualMachineImagesOperationGroup {
8686
/**
8787
* Gets a virtual machine image.
8888
*/
@@ -268,7 +268,7 @@ interface VirtualMachineImagesOperations {
268268
}
269269

270270
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
271-
interface VirtualMachineImagesEdgeZoneOperations {
271+
interface VirtualMachineImagesEdgeZoneOperationGroup {
272272
/**
273273
* Gets a virtual machine image in an edge zone.
274274
*/
@@ -472,7 +472,7 @@ interface VirtualMachineImagesEdgeZoneOperations {
472472
}
473473

474474
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
475-
interface LogAnalyticsOperations {
475+
interface LogAnalyticsOperationGroup {
476476
/**
477477
* Export logs that show Api requests made by this subscription in the given time window to show throttling activities.
478478
*/
@@ -508,7 +508,7 @@ interface LogAnalyticsOperations {
508508
}
509509

510510
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
511-
interface VirtualMachineRunCommandsOperations {
511+
interface VirtualMachineRunCommandsOperationGroup {
512512
/**
513513
* Lists all available run commands for a subscription in a location.
514514
*/
@@ -550,7 +550,7 @@ interface VirtualMachineRunCommandsOperations {
550550
}
551551

552552
#suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" "For backward compatibility"
553-
interface ResourceSkusOperations {
553+
interface ResourceSkusOperationGroup {
554554
/**
555555
* Gets the list of Microsoft.Compute SKUs available for your Subscription.
556556
*/

0 commit comments

Comments
 (0)