Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ import {
armResourceListName,
armResourceReadName,
armResourceUpdateName,
armResourceWithParameter,
extensionResourceOperationName,
legacyExtensionResourceOperationName,
legacyResourceOperationName,
builtInResourceOperationName,
nonResourceMethodMetadata,
parentResourceName,
readsResourceName,
Expand Down Expand Up @@ -356,6 +358,64 @@ function parseResourceOperation(
];
}
return undefined;
case builtInResourceOperationName:
switch (decorator.args[2].jsValue) {
case "read":
return [
ResourceOperationKind.Get,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
case "createOrUpdate":
return [
ResourceOperationKind.Create,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
case "update":
return [
ResourceOperationKind.Update,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
case "delete":
return [
ResourceOperationKind.Delete,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
case "list":
return [
ResourceOperationKind.List,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
case "action":
return [
ResourceOperationKind.Action,
getResourceModelIdCore(
sdkContext,
decorator.args[1].value as Model,
decorator.definition?.name
)
];
}
return undefined;
}
}
return undefined;
Expand Down Expand Up @@ -437,7 +497,7 @@ function traverseClient<T extends { children?: T[] }>(client: T, clients: T[]) {
function getAllResourceModels(codeModel: CodeModel): InputModelType[] {
const resourceModels: InputModelType[] = [];
for (const model of codeModel.models) {
if (model.decorators?.some((d) => d.name == armResourceInternal)) {
if (model.decorators?.some((d) => d.name == armResourceInternal || d.name == armResourceWithParameter)) {
resourceModels.push(model);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ const armResourceUpdateRegex = "Azure\\.ResourceManager\\.@armResourceUpdate";
export const extensionResourceOperationName = "@extensionResourceOperation";
export const legacyExtensionResourceOperationName = "@legacyExtensionResourceOperation";
export const legacyResourceOperationName = "@legacyResourceOperation";
export const builtInResourceOperationName = "@builtInResourceOperation";

export const armResourceWithParameter =
"Azure.ResourceManager.Private.@armResourceWithParameter";
const armResourceWithParameterRegex =
"Azure\\.ResourceManager\\.Private\\.@armResourceWithParameter";

export const armResourceInternal =
"Azure.ResourceManager.Private.@armResourceInternal";
Expand Down Expand Up @@ -114,6 +120,7 @@ export const azureSDKContextOptions: CreateSdkContextOptions = {
resourceGroupResourceRegex,
singletonRegex,
subscriptionResourceRegex,
tenantResourceRegex
tenantResourceRegex,
armResourceWithParameterRegex,
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ private void DoPreVisitPropertyNameRenaming(InputProperty property, PropertyProv
// TODO: we will remove this manual updated when https://github.com/microsoft/typespec/issues/8079 is resolved
if (method.EnclosingType is MrwSerializationTypeDefinition serializationTypeDefinition && _deserializationRename.TryGetValue(serializationTypeDefinition, out var newName) && method.Signature.Name.StartsWith("Deserialize"))
{
// If the enclosing type name ends with "Data" (added by ResourceVisitor), ensure the method name also includes "Data"
if (serializationTypeDefinition.Name.EndsWith("Data") && !newName.EndsWith("Data"))
{
newName += "Data";
}
method.Signature.Update(name: newName);
}

Expand All @@ -224,6 +229,11 @@ private void DoPreVisitPropertyNameRenaming(InputProperty property, PropertyProv
&& statement.Expression is KeywordExpression keyword && keyword.Keyword == "return"
&& keyword.Expression is InvokeMethodExpression invokeMethod)
{
// If the enclosing type name ends with "Data" (added by ResourceVisitor), ensure the method name also includes "Data"
if (serializationTypeDefinition.Name.EndsWith("Data") && !newName.EndsWith("Data"))
{
newName += "Data";
}
invokeMethod.Update(methodName: newName);
}
return base.VisitExpressionStatement(statement, method);
Expand All @@ -242,6 +252,11 @@ private void DoPreVisitPropertyNameRenaming(InputProperty property, PropertyProv
&& keywordExpression.Keyword == "return"
&& keywordExpression.Expression is InvokeMethodExpression invokeMethod)
{
// If the enclosing type name ends with "Data" (added by ResourceVisitor), ensure the method name also includes "Data"
if (serializationTypeDefinition.Name.EndsWith("Data") && !newName.EndsWith("Data"))
{
newName += "Data";
}
invokeMethod.Update(methodName: newName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,57 @@ model StartRequest {
*/
startVm?: boolean;
}
@parentResource(StorageSyncService)
model PrivateEndpointConnection is PrivateEndpointConnectionResource;
alias PrivateEndpointOperations = Azure.ResourceManager.PrivateEndpoints<PrivateEndpointConnection>;

@armResourceOperations
interface PrivateEndpointConnections {
/**
* Gets the specified private endpoint connection associated with the storage sync service.
*/
get is PrivateEndpointOperations.Read<
StorageSyncService,
>;

/**
* Update the state of specified private endpoint connection associated with the storage sync service.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
@Azure.Core.useFinalStateVia("location")
create is PrivateEndpointOperations.CreateOrUpdateAsync<
StorageSyncService,
Response = ArmResourceUpdatedResponse<PrivateEndpointConnection> | (ArmAcceptedLroResponse<LroHeaders = ArmCombinedLroHeaders<FinalResult = PrivateEndpointConnection> &
Azure.Core.Foundations.RetryAfterHeader> & {
@header("x-ms-correlation-request-id")
@doc("correlation request id")
correlationRequestId?: string;

@header("x-ms-request-id")
@doc("Request id")
requestId?: string;
}),
>;
}

model StorageSyncService
is Azure.ResourceManager.TrackedResource<StorageSyncServiceProperties> {
...ResourceNameParameter<
Resource = StorageSyncService,
KeyName = "storageSyncServiceName",
SegmentName = "storageSyncServices",
NamePattern = ""
>;
...Azure.ResourceManager.ManagedServiceIdentityProperty;
}

model StorageSyncServiceProperties {
/** The storage sync service location. */
storageSyncServiceLocation: string;
}

@armResourceOperations
interface StorageSyncServices {
/** Gets the specified storage sync service. */
get is ArmResourceRead<StorageSyncService>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,29 @@ using Azure.ResourceManager;
})
@versioned(Versions)
@armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5)
namespace MgmtTypeSpec;
namespace MgmtTypeSpec {

interface Operations extends Azure.ResourceManager.Operations {}
interface Operations extends Azure.ResourceManager.Operations {}

/** The available API versions. */
enum Versions {
v2024_05_01: "2024-05-01",
}
/** The available API versions. */
enum Versions {
v2024_05_01: "2024-05-01",
}

@@clientLocation(Bars.get, "Bar");
@@clientLocation(Bars.update, "Bar");

@@clientLocation(Bars.get, "Bar");
@@clientLocation(Bars.update, "Bar");
#suppress "deprecated"
@@Azure.ClientGenerator.Core.Legacy.flattenProperty(BarSettingsResource.flattenedNestedProperty);
@@Azure.ClientGenerator.Core.Legacy.flattenProperty(Foo.properties);

#suppress "deprecated"
@@Azure.ClientGenerator.Core.Legacy.flattenProperty(BarSettingsResource.flattenedNestedProperty);
@@Azure.ClientGenerator.Core.Legacy.flattenProperty(Foo.properties);
@@alternateType(FooProperties.something, Azure.ResourceManager.Foundations.ManagedServiceIdentity, "csharp");
@@clientName(Employees.listByParent, "GetEmployees", "csharp");
@@alternateType(ZooAddressListListResult.value, Azure.ResourceManager.Models.SubResource[], "csharp");
@@alternateType(Azure.ResourceManager.CommonTypes.PrivateEndpointConnectionProperties.privateEndpoint, Azure.ResourceManager.Models.SubResource, "csharp");
}

@@alternateType(FooProperties.something, Azure.ResourceManager.Foundations.ManagedServiceIdentity, "csharp");
@@clientName(Employees.listByParent, "GetEmployees", "csharp");
// We define this model here to test if the generated code would be replaced by Azure.ResourceManager.Models.SubResource via alternateType
namespace Azure.ResourceManager.Models {
model SubResource { }
}
Loading