Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan Shao committed Sep 5, 2024
1 parent 848bac4 commit e6e7f66
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/extensions/openapi-to-typespec/src/resource/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ interface DataProductsCatalogs {
* List data catalog by subscription.
*/
listBySubscription is ArmListBySubscription<DataProductsCatalog>;

/**
* List data catalog by resource group.
*/
listByResourceGroup is ArmResourceListByParent<DataProductsCatalog>;
}

@@doc(DataProductsCatalog.name, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand All @@ -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"
Expand All @@ -153,7 +150,7 @@
],
"responses": {
"200": {
"description": "The request has succeeded.",
"description": "Azure operation completed successfully.",
"schema": {
"$ref": "#/definitions/CheckNameAvailabilityResult"
}
Expand All @@ -164,30 +161,19 @@
"$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": [
{
"$ref": "../../common-types/resource-management/v3/types.json#/parameters/ApiVersionParameter"
},
{
"$ref": "../../common-types/resource-management/v3/types.json#/parameters/SubscriptionIdParameter"
},
{
"$ref": "../../common-types/resource-management/v3/types.json#/parameters/LocationParameter"
}
],
"responses": {
Expand All @@ -204,11 +190,6 @@
}
}
},
"x-ms-examples": {
"DeletedAccountList": {
"$ref": "./examples/DeletedAccounts_List.json"
}
},
"x-ms-pageable": {
"nextLinkName": "nextLink"
}
Expand Down Expand Up @@ -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": [
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": [
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit e6e7f66

Please sign in to comment.