Skip to content

Commit

Permalink
Uptake SDK configuration to converter (#5023)
Browse files Browse the repository at this point in the history
Co-authored-by: Pan Shao <[email protected]>
  • Loading branch information
pshao25 and Pan Shao authored Sep 26, 2024
1 parent cdf589f commit c6ab5f6
Show file tree
Hide file tree
Showing 26 changed files with 998 additions and 356 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@autorest/openapi-to-typespec",
"comment": "Uptake SDK configuration to converter",
"type": "patch"
}
],
"packageName": "@autorest/openapi-to-typespec"
}
4 changes: 3 additions & 1 deletion packages/extensions/openapi-to-typespec/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export async function processConverter(host: AutorestExtensionHost) {
let metadata = undefined;
if (isArm) {
// await host.writeFile({ filename: "codeModel.yaml", content: serialize(codeModel, codeModelSchema) });
metadata = parseMetadata(codeModel);
metadata = parseMetadata(codeModel, session.configuration);
// metadata.RenameMapping = session.configuration["rename-mapping"];
// metadata.OverrideOperationName = session.configuration["override-operation-name"];
await host.writeFile({ filename: "resources.json", content: JSON.stringify(metadata, null, 2) });
pretransformArmResources(codeModel, metadata);
pretransformRename(codeModel, metadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export function getResourceDataSchema(set: OperationSet): string | undefined {
return undefined;
}

export function setResourceDataSchema(set: OperationSet, resourceDataName: string): void {
resourceDataSchemaCache.set(set, resourceDataName);
}

function checkEvenSegments(path: string): boolean {
const index = path.lastIndexOf(ProvidersSegment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import {
setParentOfOtherOperation,
setParentOfResourceCollectionOperation,
} from "./find-parent";
import { findOperation, getResourceDataSchema, OperationSet, populateSingletonRequestPath } from "./operation-set";
import {
findOperation,
getResourceDataSchema,
OperationSet,
populateSingletonRequestPath,
setResourceDataSchema,
} from "./operation-set";
import { getPagingItemType, isTrackedResource } from "./resource-equivalent";
import { getResourceKey, getResourceKeySegment, getResourceType, isScopedPath, isSingleton } from "./utils";

const logger = () => getLogger("parse-metadata");

export function parseMetadata(codeModel: CodeModel): Metadata {
export function parseMetadata(codeModel: CodeModel, configuration: Record<string, any>): Metadata {
const operationSets: { [path: string]: OperationSet } = {};
const operations = codeModel.operationGroups.flatMap((og) => og.operations);
for (const operation of operations) {
Expand All @@ -32,7 +38,17 @@ export function parseMetadata(codeModel: CodeModel): Metadata {
const operationSetsByResourceDataSchemaName: { [name: string]: OperationSet[] } = {};
for (const key in operationSets) {
const operationSet = operationSets[key];
const resourceSchemaName = getResourceDataSchema(operationSet);
let resourceSchemaName = getResourceDataSchema(operationSet);
if (resourceSchemaName === undefined) {
const resourceDataConfiguration = configuration["request-path-to-resource-data"] as Record<string, string>;
const configuredName = resourceDataConfiguration
? resourceDataConfiguration[operationSet.RequestPath]
: undefined;
if (configuredName && codeModel.schemas.objects?.find((o) => o.language.default.name === configuredName)) {
resourceSchemaName = configuredName;
setResourceDataSchema(operationSet, resourceSchemaName);
}
}
if (resourceSchemaName !== undefined) {
populateSingletonRequestPath(operationSet);
if (resourceSchemaName in operationSetsByResourceDataSchemaName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3130,6 +3130,292 @@
"IsExtensionResource": false,
"IsSingletonResource": false
},
"SharedGallery": {
"Name": "SharedGallery",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}",
"Method": "GET",
"OperationID": "SharedGalleries_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a shared gallery by subscription id or tenant id."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [
{
"Name": "GetAll",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries",
"Method": "GET",
"OperationID": "SharedGalleries_List",
"IsLongRunning": false,
"PagingMetadata": {
"Method": "List",
"ItemName": "value",
"NextLinkName": "nextLink"
},
"Description": "List shared galleries by subscription id or tenant id."
}
],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"SubscriptionResource"
],
"SwaggerModelName": "SharedGallery",
"ResourceType": "Microsoft.Compute/locations/sharedGalleries",
"ResourceKey": "galleryUniqueName",
"ResourceKeySegment": "sharedGalleries",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": true,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"SharedGalleryImage": {
"Name": "SharedGalleryImage",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}",
"Method": "GET",
"OperationID": "SharedGalleryImages_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a shared gallery image by subscription id or tenant id."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [
{
"Name": "GetAll",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images",
"Method": "GET",
"OperationID": "SharedGalleryImages_List",
"IsLongRunning": false,
"PagingMetadata": {
"Method": "List",
"ItemName": "value",
"NextLinkName": "nextLink"
},
"Description": "List shared gallery images by subscription id or tenant id."
}
],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"SharedGallery"
],
"SwaggerModelName": "SharedGalleryImage",
"ResourceType": "Microsoft.Compute/locations/sharedGalleries/images",
"ResourceKey": "galleryImageName",
"ResourceKeySegment": "images",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": false,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"SharedGalleryImageVersion": {
"Name": "SharedGalleryImageVersion",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions/{galleryImageVersionName}",
"Method": "GET",
"OperationID": "SharedGalleryImageVersions_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a shared gallery image version by subscription id or tenant id."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [
{
"Name": "GetAll",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/sharedGalleries/{galleryUniqueName}/images/{galleryImageName}/versions",
"Method": "GET",
"OperationID": "SharedGalleryImageVersions_List",
"IsLongRunning": false,
"PagingMetadata": {
"Method": "List",
"ItemName": "value",
"NextLinkName": "nextLink"
},
"Description": "List shared gallery image versions by subscription id or tenant id."
}
],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"SharedGalleryImage"
],
"SwaggerModelName": "SharedGalleryImageVersion",
"ResourceType": "Microsoft.Compute/locations/sharedGalleries/images/versions",
"ResourceKey": "galleryImageVersionName",
"ResourceKeySegment": "versions",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": false,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"CommunityGallery": {
"Name": "CommunityGallery",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/communityGalleries/{publicGalleryName}",
"Method": "GET",
"OperationID": "CommunityGalleries_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a community gallery by gallery public name."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"SubscriptionResource"
],
"SwaggerModelName": "CommunityGallery",
"ResourceType": "Microsoft.Compute/locations/communityGalleries",
"ResourceKey": "publicGalleryName",
"ResourceKeySegment": "communityGalleries",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": true,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"CommunityGalleryImage": {
"Name": "CommunityGalleryImage",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/communityGalleries/{publicGalleryName}/images/{galleryImageName}",
"Method": "GET",
"OperationID": "CommunityGalleryImages_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a community gallery image."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [
{
"Name": "GetAll",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/communityGalleries/{publicGalleryName}/images",
"Method": "GET",
"OperationID": "CommunityGalleryImages_List",
"IsLongRunning": false,
"PagingMetadata": {
"Method": "List",
"ItemName": "value",
"NextLinkName": "nextLink"
},
"Description": "List community gallery images inside a gallery."
}
],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"CommunityGallery"
],
"SwaggerModelName": "CommunityGalleryImage",
"ResourceType": "Microsoft.Compute/locations/communityGalleries/images",
"ResourceKey": "galleryImageName",
"ResourceKeySegment": "images",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": false,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"CommunityGalleryImageVersion": {
"Name": "CommunityGalleryImageVersion",
"GetOperations": [
{
"Name": "Get",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/communityGalleries/{publicGalleryName}/images/{galleryImageName}/versions/{galleryImageVersionName}",
"Method": "GET",
"OperationID": "CommunityGalleryImageVersions_Get",
"IsLongRunning": false,
"PagingMetadata": null,
"Description": "Get a community gallery image version."
}
],
"CreateOperations": [],
"UpdateOperations": [],
"DeleteOperations": [],
"ListOperations": [
{
"Name": "GetAll",
"Path": "/subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/communityGalleries/{publicGalleryName}/images/{galleryImageName}/versions",
"Method": "GET",
"OperationID": "CommunityGalleryImageVersions_List",
"IsLongRunning": false,
"PagingMetadata": {
"Method": "List",
"ItemName": "value",
"NextLinkName": "nextLink"
},
"Description": "List community gallery image versions inside an image."
}
],
"OperationsFromResourceGroupExtension": [],
"OperationsFromSubscriptionExtension": [],
"OperationsFromManagementGroupExtension": [],
"OperationsFromTenantExtension": [],
"OtherOperations": [],
"Parents": [
"CommunityGalleryImage"
],
"SwaggerModelName": "CommunityGalleryImageVersion",
"ResourceType": "Microsoft.Compute/locations/communityGalleries/images/versions",
"ResourceKey": "galleryImageVersionName",
"ResourceKeySegment": "versions",
"IsTrackedResource": false,
"IsTenantResource": false,
"IsSubscriptionResource": false,
"IsManagementGroupResource": false,
"IsExtensionResource": false,
"IsSingletonResource": false
},
"RoleInstance": {
"Name": "RoleInstance",
"GetOperations": [
Expand Down
Loading

0 comments on commit c6ab5f6

Please sign in to comment.