diff --git a/packages/extensions/openapi-to-typespec/src/resource/find-parent.ts b/packages/extensions/openapi-to-typespec/src/resource/find-parent.ts index 2fc98f6fbe..833c1693bf 100644 --- a/packages/extensions/openapi-to-typespec/src/resource/find-parent.ts +++ b/packages/extensions/openapi-to-typespec/src/resource/find-parent.ts @@ -30,7 +30,6 @@ export function setParentOfResourceCollectionOperation( if (itemType === undefined) return false; // then check if its path is a prefix of which resource's operationSet - // if there are multiple resources that share the same prefix of request path, we choose the shortest one const requestScopeType = getScopeResourceType(requestPath); const candidates: OperationSet[] = []; for (const operationSet of operationSets) { @@ -50,6 +49,7 @@ export function setParentOfResourceCollectionOperation( candidates.push(operationSet); } + // if there are multiple resources that share the same prefix of request path, we choose the shortest one if (candidates.length === 0) return false; const bestOne = candidates.sort((a, b) => b.RequestPath.split("/").length - a.RequestPath.split("/").length)[0]; diff --git a/packages/extensions/openapi-to-typespec/src/resource/parse-metadata.ts b/packages/extensions/openapi-to-typespec/src/resource/parse-metadata.ts index 21fb3c216b..bc88ce3636 100644 --- a/packages/extensions/openapi-to-typespec/src/resource/parse-metadata.ts +++ b/packages/extensions/openapi-to-typespec/src/resource/parse-metadata.ts @@ -70,9 +70,9 @@ export function parseMetadata(codeModel: CodeModel): Metadata { for (const resourceSchemaName in operationSetsByResourceDataSchemaName) { const operationSets = operationSetsByResourceDataSchemaName[resourceSchemaName]; if (operationSets.length > 1) { - throw `We cannot support multi path with same model.\nResource schema name: ${resourceSchemaName}.\nPath:\n${operationSets + console.warn(`We cannot support multi path with same model. Some operations will be lost. \nResource schema name: ${resourceSchemaName}.\nPath:\n${operationSets .map((o) => o.RequestPath) - .join("\n")}`; + .join("\n")}`); } resources[resourceSchemaName] = buildResource( resourceSchemaName, diff --git a/packages/extensions/openapi-to-typespec/src/resource/utils.ts b/packages/extensions/openapi-to-typespec/src/resource/utils.ts index dcd1def49d..7060df0518 100644 --- a/packages/extensions/openapi-to-typespec/src/resource/utils.ts +++ b/packages/extensions/openapi-to-typespec/src/resource/utils.ts @@ -19,7 +19,7 @@ export function getResourceType(path: string): string { if (pathToLower.startsWith(ResourceGroupScopePrefix.toLowerCase())) return "Microsoft.Resources/resourceGroups"; if (pathToLower.startsWith(SubscriptionScopePrefix.toLowerCase())) return "Microsoft.Resources/subscriptions"; if (pathToLower.startsWith(TenantScopePrefix.toLowerCase())) return "Microsoft.Resources/tenants"; - throw `Path ${path} doesn't have resouce type`; + throw `Path ${path} doesn't have resource type`; } return path @@ -45,7 +45,7 @@ export function getScopePath(path: string): string { const pathToLower = path.toLowerCase(); const index = pathToLower.lastIndexOf(ProvidersSegment); - if (index === 0 && pathToLower.startsWith(ManagementGroupScopePrefix.toLowerCase())) return ManagementGroupPath; + if (pathToLower.startsWith(ManagementGroupScopePrefix.toLowerCase())) return ManagementGroupPath; if (index >= 0) return path.slice(0, index); if (pathToLower.startsWith(ResourceGroupScopePrefix.toLowerCase())) return ResourceGroupPath; if (pathToLower.startsWith(SubscriptionScopePrefix.toLowerCase())) return SubscriptionPath; diff --git a/packages/extensions/openapi-to-typespec/test/arm-networkanalytics/tsp-output/DataProductsCatalog.tsp b/packages/extensions/openapi-to-typespec/test/arm-networkanalytics/tsp-output/DataProductsCatalog.tsp index c1371b5368..1520870b96 100644 --- a/packages/extensions/openapi-to-typespec/test/arm-networkanalytics/tsp-output/DataProductsCatalog.tsp +++ b/packages/extensions/openapi-to-typespec/test/arm-networkanalytics/tsp-output/DataProductsCatalog.tsp @@ -40,11 +40,6 @@ interface DataProductsCatalogs { * List data catalog by subscription. */ listBySubscription is ArmListBySubscription; - - /** - * List data catalog by resource group. - */ - listByResourceGroup is ArmResourceListByParent; } @@doc(DataProductsCatalog.name, ""); diff --git a/packages/extensions/openapi-to-typespec/test/arm-storage/swagger-output/swagger.json b/packages/extensions/openapi-to-typespec/test/arm-storage/swagger-output/swagger.json index b9be7c1c68..3301a6218e 100644 --- a/packages/extensions/openapi-to-typespec/test/arm-storage/swagger-output/swagger.json +++ b/packages/extensions/openapi-to-typespec/test/arm-storage/swagger-output/swagger.json @@ -129,10 +129,7 @@ }, "/subscriptions/{subscriptionId}/providers/Microsoft.Storage/checkNameAvailability": { "post": { - "operationId": "StorageAccounts_CheckNameAvailability", - "tags": [ - "StorageAccounts" - ], + "operationId": "StorageAccountsOperations_CheckNameAvailability", "description": "Checks that the storage account name is valid and is not already in use.", "parameters": [ { @@ -142,9 +139,9 @@ "$ref": "../../common-types/resource-management/v3/types.json#/parameters/SubscriptionIdParameter" }, { - "name": "body", + "name": "accountName", "in": "body", - "description": "The CheckAvailability request", + "description": "The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.", "required": true, "schema": { "$ref": "#/definitions/StorageAccountCheckNameAvailabilityParameters" @@ -153,7 +150,7 @@ ], "responses": { "200": { - "description": "The request has succeeded.", + "description": "Azure operation completed successfully.", "schema": { "$ref": "#/definitions/CheckNameAvailabilityResult" } @@ -164,20 +161,12 @@ "$ref": "../../common-types/resource-management/v3/types.json#/definitions/ErrorResponse" } } - }, - "x-ms-examples": { - "StorageAccountCheckNameAvailability": { - "$ref": "./examples/StorageAccounts_CheckNameAvailability.json" - } } } }, - "/subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/deletedAccounts": { + "/subscriptions/{subscriptionId}/providers/Microsoft.Storage/deletedAccounts": { "get": { - "operationId": "DeletedAccounts_List", - "tags": [ - "DeletedAccounts" - ], + "operationId": "DeletedAccountsOperations_List", "description": "Lists deleted accounts under the subscription.", "parameters": [ { @@ -185,9 +174,6 @@ }, { "$ref": "../../common-types/resource-management/v3/types.json#/parameters/SubscriptionIdParameter" - }, - { - "$ref": "../../common-types/resource-management/v3/types.json#/parameters/LocationParameter" } ], "responses": { @@ -204,11 +190,6 @@ } } }, - "x-ms-examples": { - "DeletedAccountList": { - "$ref": "./examples/DeletedAccounts_List.json" - } - }, "x-ms-pageable": { "nextLinkName": "nextLink" } @@ -3086,7 +3067,7 @@ } } }, - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies/default": { + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/inventoryPolicies/{blobInventoryPolicyName}": { "get": { "operationId": "BlobInventoryPolicies_Get", "tags": [ @@ -3111,6 +3092,26 @@ "type": "string", "minLength": 3, "maxLength": 24 + }, + { + "name": "blobInventoryPolicyName", + "in": "path", + "description": "The name of the storage account blob inventory policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "BlobInventoryPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } } ], "responses": { @@ -3158,6 +3159,26 @@ "minLength": 3, "maxLength": 24 }, + { + "name": "blobInventoryPolicyName", + "in": "path", + "description": "The name of the storage account blob inventory policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "BlobInventoryPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } + }, { "name": "properties", "in": "body", @@ -3225,6 +3246,26 @@ "type": "string", "minLength": 3, "maxLength": 24 + }, + { + "name": "blobInventoryPolicyName", + "in": "path", + "description": "The name of the storage account blob inventory policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "BlobInventoryPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } } ], "responses": { @@ -3776,7 +3817,7 @@ } } }, - "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/managementPolicies/default": { + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}/managementPolicies/{managementPolicyName}": { "get": { "operationId": "ManagementPolicies_Get", "tags": [ @@ -3801,6 +3842,26 @@ "type": "string", "minLength": 3, "maxLength": 24 + }, + { + "name": "managementPolicyName", + "in": "path", + "description": "The name of the Storage Account Management Policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "ManagementPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } } ], "responses": { @@ -3848,6 +3909,26 @@ "minLength": 3, "maxLength": 24 }, + { + "name": "managementPolicyName", + "in": "path", + "description": "The name of the Storage Account Management Policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "ManagementPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } + }, { "name": "properties", "in": "body", @@ -3930,6 +4011,26 @@ "type": "string", "minLength": 3, "maxLength": 24 + }, + { + "name": "managementPolicyName", + "in": "path", + "description": "The name of the Storage Account Management Policy. It should always be 'default'", + "required": true, + "type": "string", + "enum": [ + "default" + ], + "x-ms-enum": { + "name": "ManagementPolicyName", + "modelAsString": true, + "values": [ + { + "name": "default", + "value": "default" + } + ] + } } ], "responses": { @@ -6659,7 +6760,7 @@ }, "DeletedAccountListResult": { "type": "object", - "description": "The response of a DeletedAccount list operation.", + "description": "The response from the List Deleted Accounts operation.", "properties": { "value": { "type": "array",