-
Notifications
You must be signed in to change notification settings - Fork 5.8k
TypeSpec conversion for resources/policy #38509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pshao25
merged 52 commits into
Azure:main
from
weidongxu-microsoft:tsp-convertion_resources-policy
Jan 6, 2026
Merged
Changes from 45 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
6f73624
convert without /{policyAssignmentId} path
weidongxu-microsoft a9e2626
tspconfig
weidongxu-microsoft b05c372
prettier
weidongxu-microsoft 8fb7e4e
fix PolicyDefinition
weidongxu-microsoft d95decc
fix PolicySetDefinitionVersion
weidongxu-microsoft a57417a
fix PolicyDefinitionVersion
weidongxu-microsoft 2e03abd
fix PolicySetDefinition
weidongxu-microsoft ecafb25
fix back-compatible
weidongxu-microsoft 85eb40d
format
weidongxu-microsoft 4857ebc
fix model
weidongxu-microsoft 998a289
fix warning
weidongxu-microsoft 163413b
regen
weidongxu-microsoft a081067
add client.tsp
weidongxu-microsoft 86c76e5
remove operationId
weidongxu-microsoft 18bbded
fix listForResourceGroup
weidongxu-microsoft 204b2d3
use v6 common-types
weidongxu-microsoft 4f2b11f
use CommonTypes.ManagementGroupNameParameter
weidongxu-microsoft b98663d
revert back to common-types v5
weidongxu-microsoft 0a77e24
temp solution for /providers/microsoft.Management/managementGroups/{m…
weidongxu-microsoft eeb6530
fix PolicyAssignments_ListForManagementGroup
weidongxu-microsoft 9803a45
remove suppress
weidongxu-microsoft 75c4088
fix PolicyAssignments_List
weidongxu-microsoft 52c87fa
fix PolicyAssignments_ListForResource
weidongxu-microsoft 2d9d161
add examples
weidongxu-microsoft 662271f
fix go tspconfig
weidongxu-microsoft 5b81ce1
fix
weidongxu-microsoft f7ebb41
fix example
weidongxu-microsoft 2d4e167
use template for listForManagementGroup
weidongxu-microsoft 51eaea4
Merge branch 'main' into tsp-convertion_resources-policy
weidongxu-microsoft 7aa8790
use ListSinglePage
weidongxu-microsoft 1b81221
use PolicyAssignmentGenericOps
weidongxu-microsoft be323dc
update others
weidongxu-microsoft e7bdeda
backward compatible
weidongxu-microsoft 739e131
Merge branch 'main' into tsp-convertion_resources-policy
weidongxu-microsoft 2967570
api in client
weidongxu-microsoft 898d941
skip-url-encoding
weidongxu-microsoft e530012
fix a ref
weidongxu-microsoft 81d3906
copy existing suppress to openapi.json file
weidongxu-microsoft a61d2d7
update package name
v-jiaodi 3c83b6f
update client name
v-jiaodi 31faa2c
Merge branch 'main' into tsp-convertion_resources-policy
weidongxu-microsoft 8770a17
for tsp 1.6.0
weidongxu-microsoft 95a1dcf
fix conflicts from folder structure refactor
zedy-wj e0ba8b8
Merge branch 'main' into tsp-convertion_resources-policy
v-jiaodi 5265bc0
Update client.tsp
ChenxiJiang333 9161354
Update client.tsp
ChenxiJiang333 c9f3acc
Update tspconfig.yaml
ChenxiJiang333 3e509b1
Update client location annotation in policy client
ChenxiJiang333 c131197
add code
jliusan 7a67306
Merge branch 'main' into tsp-convertion_resources-policy
weidongxu-microsoft bc62110
use Record type directly on property
weidongxu-microsoft 64f849f
Merge branch 'main' into tsp-convertion_resources-policy
pshao25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
197 changes: 197 additions & 0 deletions
197
specification/resources/resource-manager/Microsoft.Authorization/policy/PolicyAssignment.tsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| import "@azure-tools/typespec-azure-core"; | ||
| import "@azure-tools/typespec-azure-resource-manager"; | ||
| import "@typespec/openapi"; | ||
| import "@typespec/rest"; | ||
| import "./models.tsp"; | ||
|
|
||
| using TypeSpec.Rest; | ||
| using Azure.ResourceManager; | ||
| using TypeSpec.Http; | ||
| using TypeSpec.OpenAPI; | ||
|
|
||
| namespace Microsoft.Authorization; | ||
| /** | ||
| * The policy assignment. | ||
| */ | ||
| model PolicyAssignment | ||
| is Azure.ResourceManager.ExtensionResource<PolicyAssignmentProperties> { | ||
| ...ResourceNameParameter< | ||
| Resource = PolicyAssignment, | ||
| KeyName = "policyAssignmentName", | ||
| SegmentName = "policyAssignments", | ||
| NamePattern = "^[^<>*%&:\\?.+/]*[^<>*%&:\\?.+/ ]+$" | ||
| >; | ||
|
|
||
| /** | ||
| * The location of the policy assignment. Only required when utilizing managed identity. | ||
| */ | ||
| #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property" "For backward compatibility" | ||
| location?: string; | ||
|
|
||
| /** | ||
| * The managed identity associated with the policy assignment. | ||
| */ | ||
| #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property" "For backward compatibility" | ||
| identity?: Identity; | ||
| } | ||
|
|
||
| alias PolicyAssignmentListParameters = { | ||
| /** | ||
| * The filter to apply on the operation. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, no filtering is performed. If $filter=atScope() is provided, the returned list only includes all policy assignments that apply to the scope, which is everything in the unfiltered list except those applied to sub scopes contained within the given scope. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the given scope. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. | ||
| */ | ||
| @query("$filter") | ||
| $filter?: string; | ||
|
|
||
| /** | ||
| * Comma-separated list of additional properties to be included in the response. Supported values are 'LatestDefinitionVersion, EffectiveDefinitionVersion'. | ||
| */ | ||
| @query("$expand") | ||
| $expand?: string; | ||
|
|
||
| /** | ||
| * Maximum number of records to return. When the $top filter is not provided, it will return 500 records. | ||
| */ | ||
| @maxValue(1000) | ||
| @minValue(1) | ||
| @query("$top") | ||
| $top?: int32; | ||
| }; | ||
|
|
||
| #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator" | ||
| interface PolicyAssignmentGenericOps | ||
| extends Azure.ResourceManager.Legacy.ExtensionOperations< | ||
| { | ||
| ...SubscriptionIdParameter, | ||
| ...ResourceGroupParameter, | ||
|
|
||
| /** | ||
| * The namespace of the resource provider. For example, the namespace of a virtual machine is Microsoft.Compute (from Microsoft.Compute/virtualMachines) | ||
| */ | ||
| @path | ||
| @segment("providers") | ||
| resourceProviderNamespace: string, | ||
|
|
||
| /** | ||
| * The parent resource path. Use empty string if there is none. | ||
| */ | ||
| @path(#{ allowReserved: true }) | ||
| parentResourcePath: string, | ||
|
|
||
| /** | ||
| * The resource type name. For example the type name of a web app is 'sites' (from Microsoft.Web/sites). | ||
| */ | ||
| @path(#{ allowReserved: true }) | ||
| resourceType: string, | ||
|
|
||
| /** | ||
| * The name of the resource. | ||
| */ | ||
| @path | ||
| @pattern("^.+$") | ||
| resourceName: string, | ||
|
|
||
| ...ApiVersionParameter, | ||
| }, | ||
| { | ||
| ...Extension.ExtensionProviderNamespace<PolicyAssignment>, | ||
| }, | ||
| { | ||
| ...Extension.ExtensionProviderNamespace<PolicyAssignment>, | ||
| ...KeysOf<PolicyAssignment>, | ||
| } | ||
| > {} | ||
|
|
||
| @armResourceOperations | ||
| interface PolicyAssignments { | ||
| /** | ||
| * This operation retrieves a single policy assignment, given its name and the scope it was created at. | ||
| */ | ||
| get is Extension.Read< | ||
| Extension.ScopeParameter, | ||
| PolicyAssignment, | ||
| Parameters = { | ||
| /** | ||
| * Comma-separated list of additional properties to be included in the response. Supported values are 'LatestDefinitionVersion, EffectiveDefinitionVersion'. | ||
| */ | ||
| @query("$expand") | ||
| $expand?: string; | ||
| } | ||
| >; | ||
|
|
||
| /** | ||
| * This operation creates or updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. | ||
| */ | ||
| #suppress "@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes" "For backward compatibility" | ||
| create is Extension.CreateOrReplaceSync< | ||
| Extension.ScopeParameter, | ||
| PolicyAssignment, | ||
| Response = ArmResourceCreatedSyncResponse<PolicyAssignment> | ||
| >; | ||
|
|
||
| /** | ||
| * This operation updates a policy assignment with the given scope and name. Policy assignments apply to all resources contained within their scope. For example, when you assign a policy at resource group scope, that policy applies to all resources in the group. | ||
| */ | ||
| @patch(#{ implicitOptionality: false }) | ||
| update is Extension.CustomPatchSync< | ||
| Extension.ScopeParameter, | ||
| PolicyAssignment, | ||
| PatchModel = PolicyAssignmentUpdate | ||
| >; | ||
|
|
||
| /** | ||
| * This operation deletes a policy assignment, given its name and the scope it was created in. The scope of a policy assignment is the part of its ID preceding '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'. | ||
| */ | ||
| delete is Extension.DeleteSync< | ||
| Extension.ScopeParameter, | ||
| PolicyAssignment, | ||
| Response = ArmResponse<PolicyAssignment> | ArmDeletedNoContentResponse | ||
| >; | ||
|
|
||
| /** | ||
| * This operation retrieves the list of all policy assignments associated with the given resource group in the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource group, including those that apply directly or apply from containing scopes, as well as any applied to resources contained within the resource group. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource group, which is everything in the unfiltered list except those applied to resources contained within the resource group. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource group. | ||
| */ | ||
| listForResourceGroup is Extension.ListByTarget< | ||
| Extension.ResourceGroup, | ||
| PolicyAssignment, | ||
| Parameters = PolicyAssignmentListParameters | ||
| >; | ||
|
|
||
| /** | ||
| * This operation retrieves the list of all policy assignments applicable to the management group that match the given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter=atScope() is provided, the returned list includes all policy assignments that are assigned to the management group or the management group's ancestors. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the management group. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the management group. | ||
| */ | ||
| @summary("Retrieves all policy assignments that apply to a management group.") | ||
| listForManagementGroup is Extension.ListByTarget< | ||
| Extension.ManagementGroup<"managementGroupId">, | ||
| PolicyAssignment, | ||
| Parameters = PolicyAssignmentListParameters | ||
| >; | ||
|
|
||
| /** | ||
| * This operation retrieves the list of all policy assignments associated with the given subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the subscription, including those that apply directly or from management groups that contain the given subscription, as well as any applied to objects contained within the subscription. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the subscription, which is everything in the unfiltered list except those applied to objects contained within the subscription. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the subscription. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value}. | ||
| */ | ||
| @summary("Retrieves all policy assignments that apply to a subscription.") | ||
| list is Extension.ListByTarget< | ||
| Extension.Subscription, | ||
| PolicyAssignment, | ||
| Parameters = PolicyAssignmentListParameters | ||
| >; | ||
|
|
||
| /** | ||
| * This operation retrieves the list of all policy assignments associated with the specified resource in the given resource group and subscription that match the optional given $filter. Valid values for $filter are: 'atScope()', 'atExactScope()' or 'policyDefinitionId eq '{value}''. If $filter is not provided, the unfiltered list includes all policy assignments associated with the resource, including those that apply directly or from all containing scopes, as well as any applied to resources contained within the resource. If $filter=atScope() is provided, the returned list includes all policy assignments that apply to the resource, which is everything in the unfiltered list except those applied to resources contained within the resource. If $filter=atExactScope() is provided, the returned list only includes all policy assignments that at the resource level. If $filter=policyDefinitionId eq '{value}' is provided, the returned list includes all policy assignments of the policy definition whose id is {value} that apply to the resource. Three parameters plus the resource name are used to identify a specific resource. If the resource is not part of a parent resource (the more common case), the parent resource path should not be provided (or provided as ''). For example a web app could be specified as ({resourceProviderNamespace} == 'Microsoft.Web', {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} == 'MyWebApp'). If the resource is part of a parent resource, then all parameters should be provided. For example a virtual machine DNS name could be specified as ({resourceProviderNamespace} == 'Microsoft.Compute', {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType} == 'domainNames', {resourceName} == 'MyComputerName'). A convenient alternative to providing the namespace and type name separately is to provide both in the {resourceType} parameter, format: ({resourceProviderNamespace} == '', {parentResourcePath} == '', {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp'). | ||
| */ | ||
| @summary("Retrieves all policy assignments that apply to a resource.") | ||
| @get | ||
| listForResource is PolicyAssignmentGenericOps.List< | ||
| PolicyAssignment, | ||
| PolicyAssignmentListParameters | ||
| >; | ||
| } | ||
|
|
||
| @@doc(PolicyAssignment.name, "The name of the policy assignment to get."); | ||
| @@doc(PolicyAssignment.properties, "Properties for the policy assignment."); | ||
| @@doc(PolicyAssignments.create::parameters.resource, | ||
| "Parameters for the policy assignment." | ||
| ); | ||
| @@doc(PolicyAssignments.update::parameters.properties, | ||
| "Parameters for policy assignment patch request." | ||
| ); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Go has breaking change like these, and there are no ops named as these in tsp file but exist in swagger on main branch, are these funcs removed by designed ?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are moved into client.tsp, because these ops are not the genuine "CRUD" on the resource model, but describing another equivalent route to it (e.g. route
{endpoint}/{policyAssignmentId}). Also see PR description.Chenjie seems fine to remove them from Go SDK.
If you'd like to have them, you can add "go" scope to these ops in client.tsp (currently it be
@scope("java"))Also note for #38509 (comment) on the get op