Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -79,6 +79,18 @@ export type ArmUpdateProviderNamespaceDecorator = (
target: Operation,
) => void;

/**
*
*
*
* @param resource Resource model
*/
export type AssignUniqueProviderNameValueDecorator = (
context: DecoratorContext,
target: ModelProperty,
resource: Model,
) => void;

/**
* This decorator is used to identify Azure Resource Manager resource types and extract their
* metadata. It is *not* meant to be used directly by a spec author, it instead
Expand Down Expand Up @@ -170,6 +182,7 @@ export type AzureResourceManagerPrivateDecorators = {
assignProviderNameValue: AssignProviderNameValueDecorator;
azureResourceBase: AzureResourceBaseDecorator;
armUpdateProviderNamespace: ArmUpdateProviderNamespaceDecorator;
assignUniqueProviderNameValue: AssignUniqueProviderNameValueDecorator;
armResourceInternal: ArmResourceInternalDecorator;
defaultResourceKeySegmentName: DefaultResourceKeySegmentNameDecorator;
enforceConstraint: EnforceConstraintDecorator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface LegacyOperations<
@autoRoute
@doc("Create a {name}", Resource)
@armResourceCreateOrUpdate(Resource)
@Private.armUpdateProviderNamespace
@Azure.Core.Foundations.Private.defaultFinalStateVia(#["location", "azure-async-operation"])
@put
CreateOrUpdateAsync<
Expand Down Expand Up @@ -62,6 +63,7 @@ interface LegacyOperations<
@autoRoute
@doc("Create a {name}", Resource)
@armResourceCreateOrUpdate(Resource)
@Private.armUpdateProviderNamespace
@put
CreateOrUpdateSync<
Resource extends Foundations.SimpleResource,
Expand All @@ -87,6 +89,7 @@ interface LegacyOperations<
@autoRoute
@doc("Update a {name}", Resource)
@armResourceUpdate(Resource)
@Private.armUpdateProviderNamespace
@patch(#{ implicitOptionality: false })
CustomPatchAsync<
Resource extends Foundations.SimpleResource,
Expand Down Expand Up @@ -121,6 +124,7 @@ interface LegacyOperations<
@autoRoute
@doc("Update a {name}", Resource)
@armResourceUpdate(Resource)
@Private.armUpdateProviderNamespace
@patch(#{ implicitOptionality: false })
CustomPatchSync<
Resource extends Foundations.SimpleResource,
Expand All @@ -147,6 +151,7 @@ interface LegacyOperations<
@doc("Delete a {name}", Resource)
@delete
@deletesResource(Resource)
@Private.armUpdateProviderNamespace
@armResourceDelete(Resource)
DeleteWithoutOkAsync<
Resource extends Foundations.SimpleResource,
Expand All @@ -168,6 +173,7 @@ interface LegacyOperations<
@delete
@deletesResource(Resource)
@armResourceDelete(Resource)
@Private.armUpdateProviderNamespace
DeleteSync<
Resource extends Foundations.SimpleResource,
Parameters extends {} = {},
Expand All @@ -185,6 +191,7 @@ interface LegacyOperations<
@get
@readsResource(Resource)
@armResourceRead(Resource)
@Private.armUpdateProviderNamespace
Read<
Resource extends Foundations.SimpleResource,
Parameters extends {} = {},
Expand All @@ -199,6 +206,7 @@ interface LegacyOperations<
*/
@autoRoute
@doc("Check for the existence of a {name}", Resource)
@Private.armUpdateProviderNamespace
@head
CheckExistence<
Resource extends Foundations.SimpleResource,
Expand All @@ -222,6 +230,7 @@ interface LegacyOperations<
@listsResource(Resource)
@segmentOf(Resource)
@armResourceList(Resource)
@Private.armUpdateProviderNamespace
List<
Resource extends Foundations.SimpleResource,
Parameters extends {} = {},
Expand All @@ -241,6 +250,7 @@ interface LegacyOperations<
@armResourceAction(Resource)
@Private.enforceConstraint(Resource, Foundations.Resource)
@post
@Private.armUpdateProviderNamespace
@returnsDoc("Azure operation completed successfully.")
ActionSync<
Resource extends Foundations.SimpleResource,
Expand Down Expand Up @@ -273,6 +283,7 @@ interface LegacyOperations<
@autoRoute
@armResourceAction(Resource)
@Private.enforceConstraint(Resource, Foundations.Resource)
@Private.armUpdateProviderNamespace
@post
@returnsDoc("Azure operation completed successfully.")
ActionAsync<
Expand Down Expand Up @@ -302,13 +313,21 @@ interface LegacyOperations<
): Response | ErrorType;
}
/**
* @dev Get the provider namespace key-value pair
* @dev DEPRECATED: Use ProviderParameter instead. Get the provider namespace key-value pair
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not #deprected?

* @template Resource Optional. The resource to get the provider namespace for.
*/
model Provider<Resource extends {} = TenantActionScope> {
...ProviderNamespace<Resource>;
}

/**
* @dev Get the provider namespace key-value pair
* @template Resource The resource to get the provider namespace for.
*/
model ProviderParameter<Resource extends {}> {
...ProviderNamespace<Resource>;
}

/**
* A long-running resource update using a custom PATCH payload (Asynchronous)
* @template Resource the resource being patched
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ model TargetParameters<Resource extends {}> {
model ExtensionProviderNamespace<Resource extends {}> {
@path
@segment("providers")
@assignProviderNameValue(Resource)
@assignUniqueProviderNameValue(Resource)
@doc("The provider namespace for the resource.")
extensionProvider: "Microsoft.ThisWillBeReplaced";
extensionProvider: "Microsoft.ExtensionProviderNamespace";
}

/** The provider namespace (if any) for a target resource for an extension
Expand All @@ -79,8 +79,8 @@ model TargetProviderNamespace<Resource extends {}> {
@path
@segment("providers")
@doc("The provider namespace for the resource.")
@assignProviderNameValue(Resource)
provider: "Microsoft.ThisWillBeReplaced";
@assignUniqueProviderNameValue(Resource)
provider: "Microsoft.TargetProviderNamespace";
}

/** The path parameters for an extension resource at the given target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ extern dec armUpdateProviderNamespace(target: Reflection.Operation);
*/
extern dec assignProviderNameValue(target: ModelProperty, resource: Model);

/**
* @param resource Resource model
*/
extern dec assignUniqueProviderNameValue(target: ModelProperty, resource: Model);

/**
* This decorator is used to identify Azure Resource Manager resource types and extract their
* metadata. It is *not* meant to be used directly by a spec author, it instead
Expand Down
6 changes: 6 additions & 0 deletions packages/typespec-azure-resource-manager/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ export const $lib = createTypeSpecLibrary({
default: "Resource types must have a property with '@path` and '@segment' decorators.",
},
},
"resource-without-provider-namespace": {
severity: "warning",
messages: {
default: paramMessage`The resource "${"resourceName"}" does not have a provider namespace. Please use a resource in a namespace marked with '@armProviderNamespace' or a virtual resource with a specific namespace`,
},
},
"template-type-constraint-no-met": {
severity: "error",
messages: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ArmResourcePropertiesOptionalityDecorator,
ArmUpdateProviderNamespaceDecorator,
AssignProviderNameValueDecorator,
AssignUniqueProviderNameValueDecorator,
AzureResourceBaseDecorator,
AzureResourceManagerPrivateDecorators,
ConditionalClientFlattenDecorator,
Expand Down Expand Up @@ -269,7 +270,42 @@ const $assignProviderNameValue: AssignProviderNameValueDecorator = (
) => {
const { program } = context;
const armProviderNamespace = getArmProviderNamespace(program, resourceType as Model);
if (armProviderNamespace && target.type.kind === "String") {
if (
armProviderNamespace &&
target.type.kind === "String" &&
target.type.value === "Microsoft.ThisWillBeReplaced"
) {
target.type.value = armProviderNamespace;
}
};

/**
* This decorator allows setting a unique provider name value, for scenarios in which
* multiple providers are allowed.
* @param {DecoratorContext} context DecoratorContext
* @param {Type} target Target of this decorator. Must be a string `ModelProperty`.
* @param {Type} resourceType Must be a `Model`.
*/
const $assignUniqueProviderNameValue: AssignUniqueProviderNameValueDecorator = (
context: DecoratorContext,
target: ModelProperty,
resourceType: Model,
) => {
const { program } = context;
const armProviderNamespace = getArmProviderNamespace(program, resourceType);
if (!armProviderNamespace && !isBuiltIn(getResourceBaseType(program, resourceType))) {
reportDiagnostic(program, {
code: "resource-without-provider-namespace",
format: { resourceName: resourceType.name },
target: resourceType,
});
return;
}
if (
armProviderNamespace &&
target.type.kind === "String" &&
target.type.value !== armProviderNamespace
) {
target.type = $(program).literal.createString(armProviderNamespace);
}
};
Expand Down Expand Up @@ -302,8 +338,9 @@ const $armUpdateProviderNamespace: ArmUpdateProviderNamespaceDecorator = (
});
return;
}

providerParam.type.value = armProviderNamespace;
if (providerParam.type.value === "Microsoft.ThisWillBeReplaced") {
providerParam.type.value = armProviderNamespace;
}
}
}
}
Expand Down Expand Up @@ -544,6 +581,7 @@ export const $decorators = {
azureResourceBase: $azureResourceBase,
omitIfEmpty: $omitIfEmpty,
conditionalClientFlatten: $conditionalClientFlatten,
assignUniqueProviderNameValue: $assignUniqueProviderNameValue,
assignProviderNameValue: $assignProviderNameValue,
armUpdateProviderNamespace: $armUpdateProviderNamespace,
armResourceInternal: $armResourceInternal,
Expand Down
Loading
Loading