diff --git a/.chronus/changes/typespec-azure-vscode-2025-4-27-15-18-2.md b/.chronus/changes/typespec-azure-vscode-2025-4-27-15-18-2.md deleted file mode 100644 index 3d26b01a0b..0000000000 --- a/.chronus/changes/typespec-azure-vscode-2025-4-27-15-18-2.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -changeKind: internal -packages: - - typespec-azure-vscode ---- - -Initialize the typespec-azure-vscode package diff --git a/eng/pipelines/ci.yml b/eng/pipelines/ci.yml index ce00f2fc96..af0f33b612 100644 --- a/eng/pipelines/ci.yml +++ b/eng/pipelines/ci.yml @@ -49,8 +49,8 @@ extends: matrix: "Node 20.x": nodeVersion: "20.x" - "Node 22.x": - nodeVersion: "22.x" + # "Node 22.x": # temporarily skip this platform for flaky vitest issue + # nodeVersion: "22.x" "Node 24.x": nodeVersion: "24.3.0" # Regression in node 24.4 https://github.com/microsoft/typespec/issues/7861 diff --git a/packages/samples/specs/resource-manager/legacy/legacy-operations/main.tsp b/packages/samples/specs/resource-manager/legacy/legacy-operations/main.tsp index dc318c157b..9ce7fcfa35 100644 --- a/packages/samples/specs/resource-manager/legacy/legacy-operations/main.tsp +++ b/packages/samples/specs/resource-manager/legacy/legacy-operations/main.tsp @@ -35,6 +35,7 @@ model BestPractice is Azure.ResourceManager.ProxyResource; + ...Legacy.ExtendedLocationOptionalProperty; } /** Resource-specific properties of a best practice resource */ diff --git a/packages/samples/specs/resource-manager/legacy/non-standard-properties/main.tsp b/packages/samples/specs/resource-manager/legacy/non-standard-properties/main.tsp new file mode 100644 index 0000000000..a7af114791 --- /dev/null +++ b/packages/samples/specs/resource-manager/legacy/non-standard-properties/main.tsp @@ -0,0 +1,70 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; + +using Versioning; +using Azure.ResourceManager; + +@armProviderNamespace +@service(#{ title: "ContosoProviderHubClient" }) +@versioned(Versions) +@doc("Contoso Resource Provider management API.") +namespace Microsoft.ContosoProviderHub; + +/** Contoso API versions */ +enum Versions { + /** 2021-10-01-preview version */ + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) + `2021-10-01-preview`, +} + +interface Operations extends Azure.ResourceManager.Operations {} + +#suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "This is a legacy sample" +@doc("A ContosoProviderHub resource") +model Employee is Legacy.TrackedResourceWithOptionalLocation { + ...ResourceNameParameter; + ...Legacy.EntityTagProperty; +} + +@doc("The rp-specific properties of the employee") +model EmployeeProperties { + @doc("The employee age in years") + age?: int32; + + @doc("The city of current residence") + city?: string; + + @doc("security profile for the employee") + @encode("base64url") + profile?: bytes; + + @visibility(Lifecycle.Read) + @doc("The status of the last operation.") + provisioningState?: ProvisioningState; +} + +@armResourceOperations +interface Employees extends TrackedResourceOperations {} + +@doc("The provisioning state of a resource.") +@Azure.Core.lroStatus +union ProvisioningState { + string, + ResourceProvisioningState, + + @doc("The resource is being provisioned") + Provisioning: "Provisioning", + + @doc("The resource is updating") + Updating: "Updating", + + @doc("The resource is being deleted") + Deleting: "Deleting", + + @doc("The resource create request has been accepted") + Accepted: "Accepted", +} diff --git a/packages/samples/specs/resource-manager/resource-types/private-endpoints/main.tsp b/packages/samples/specs/resource-manager/resource-types/private-endpoints/main.tsp new file mode 100644 index 0000000000..1fcbad8ad2 --- /dev/null +++ b/packages/samples/specs/resource-manager/resource-types/private-endpoints/main.tsp @@ -0,0 +1 @@ +import "./private-endpoints.tsp"; diff --git a/packages/samples/specs/resource-manager/resource-types/private-endpoints/private-endpoints.tsp b/packages/samples/specs/resource-manager/resource-types/private-endpoints/private-endpoints.tsp new file mode 100644 index 0000000000..51c6f73e65 --- /dev/null +++ b/packages/samples/specs/resource-manager/resource-types/private-endpoints/private-endpoints.tsp @@ -0,0 +1,157 @@ +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; + +using Rest; +using Versioning; +using Azure.Core; +using Azure.ResourceManager; + +/** Contoso Resource Provider management API. */ +@armProviderNamespace +@service(#{ title: "ContosoProviderHubClient" }) +@versioned(Versions) +namespace Microsoft.ContosoProviderHub; + +/** Contoso API versions */ +enum Versions { + /** 2021-10-01-preview version */ + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) + `2021-10-01-preview`, +} + +// For more information about the proxy vs tracked, +// see https://armwiki.azurewebsites.net/rp_onboarding/tracked_vs_proxy_resources.html?q=proxy%20resource +/** A ContosoProviderHub resource */ +model Employee is TrackedResource { + ...ResourceNameParameter; +} + +/** Employee properties */ +model EmployeeProperties { + /** Age of employee */ + age?: int32; + + /** City of employee */ + city?: string; + + /** Profile of employee */ + @encode("base64url") + profile?: bytes; + + /** The status of the last operation. */ + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} + +/** The provisioning state of a resource. */ +@lroStatus +union ProvisioningState { + ResourceProvisioningState, + + /** The resource is being provisioned */ + Provisioning: "Provisioning", + + /** The resource is updating */ + Updating: "Updating", + + /** The resource is being deleted */ + Deleting: "Deleting", + + /** The resource create request has been accepted */ + Accepted: "Accepted", + + string, +} + +interface Operations extends Azure.ResourceManager.Operations {} +model PrivateEndpointConnection is PrivateEndpointConnectionResource; +alias PrivateEndpointOperations = PrivateEndpoints; + +@armResourceOperations +interface Employees { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmCustomPatchSync< + Employee, + Azure.ResourceManager.Foundations.ResourceUpdateModel + >; + delete is ArmResourceDeleteSync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + /** A sample resource action that move employee to different location */ + move is ArmResourceActionSync; + + /** A sample HEAD operation to check resource existence */ + checkExistence is ArmResourceCheckExistence; + + getPrivateEndpointConnection is PrivateEndpointOperations.Read; + createOrUpdatePrivateEndpointConnection is PrivateEndpointOperations.CreateOrUpdateAsync; + updatePrivateEndpointConnection is PrivateEndpointOperations.CustomPatchAsync; + deletePrivateEndpointConnection is PrivateEndpointOperations.DeleteAsync; + listPrivateEndpointConnections is PrivateEndpointOperations.ListByParent; +} + +/** Employee move request */ +model MoveRequest { + /** The moving from location */ + from: string; + + /** The moving to location */ + to: string; +} + +/** Employee move response */ +model MoveResponse { + /** The status of the move */ + movingStatus: string; +} + +@armResourceOperations +interface Dependents { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmCustomPatchSync< + Dependent, + Azure.ResourceManager.Foundations.ResourceUpdateModel + >; + delete is ArmResourceDeleteSync; + list is ArmResourceListByParent; + getPrivateEndpointConnection is PrivateEndpointOperations.Read; + createOrUpdatePrivateEndpointConnection is Azure.ResourceManager.Legacy.PrivateEndpoints.CreateOrReplaceAsync< + Dependent, + PrivateEndpointConnection, + OptionalRequestBody = true + >; + updatePrivateEndpointConnection is Azure.ResourceManager.Legacy.PrivateEndpoints.CustomPatchAsync< + Dependent, + PrivateEndpointConnection, + PatchModel = void + >; + deletePrivateEndpointConnection is PrivateEndpointOperations.DeleteAsync; + listPrivateEndpointConnections is Azure.ResourceManager.Legacy.PrivateEndpoints.ListSinglePageByParent< + Dependent, + PrivateEndpointConnection + >; +} + +/** An employee dependent */ +@parentResource(Employee) +model Dependent is ProxyResource { + ...ResourceNameParameter; +} + +/** Dependent properties */ +model DependentProperties { + /** Age of dependent */ + age: int32; + + /** Gender of dependent */ + gender: string; + + /** The status of the last operation. */ + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} diff --git a/packages/samples/test/output/azure/resource-manager/legacy/legacy-operations/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/legacy/legacy-operations/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json index 45c9c0a760..8f0e848cf7 100644 --- a/packages/samples/test/output/azure/resource-manager/legacy/legacy-operations/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json +++ b/packages/samples/test/output/azure/resource-manager/legacy/legacy-operations/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json @@ -496,6 +496,30 @@ } }, "definitions": { + "Azure.ResourceManager.CommonTypes.ExtendedLocationType": { + "type": "string", + "description": "The supported ExtendedLocation types.", + "enum": [ + "EdgeZone", + "CustomLocation" + ], + "x-ms-enum": { + "name": "ExtendedLocationType", + "modelAsString": true, + "values": [ + { + "name": "EdgeZone", + "value": "EdgeZone", + "description": "Azure Edge Zones location type" + }, + { + "name": "CustomLocation", + "value": "CustomLocation", + "description": "Azure Custom Locations type" + } + ] + } + }, "Azure.ResourceManager.ResourceProvisioningState": { "type": "string", "description": "The provisioning state of a resource type.", @@ -535,6 +559,13 @@ "$ref": "#/definitions/BestPracticeProperties", "description": "The resource-specific properties for this resource.", "x-ms-client-flatten": true + }, + "extendedLocation": { + "$ref": "#/definitions/ExtendedLocation", + "x-ms-mutability": [ + "read", + "create" + ] } }, "allOf": [ @@ -602,6 +633,20 @@ "description": "The description of the best practice" } } + }, + "ExtendedLocation": { + "type": "object", + "description": "The complex type of the extended location.", + "properties": { + "name": { + "type": "string", + "description": "The name of the extended location." + }, + "type": { + "$ref": "#/definitions/Azure.ResourceManager.CommonTypes.ExtendedLocationType", + "description": "The type of the extended location." + } + } } }, "parameters": {} diff --git a/packages/samples/test/output/azure/resource-manager/legacy/non-standard-properties/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/legacy/non-standard-properties/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json new file mode 100644 index 0000000000..d9834a0a05 --- /dev/null +++ b/packages/samples/test/output/azure/resource-manager/legacy/non-standard-properties/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json @@ -0,0 +1,561 @@ +{ + "swagger": "2.0", + "info": { + "title": "ContosoProviderHubClient", + "version": "2021-10-01-preview", + "description": "Contoso Resource Provider management API.", + "x-typespec-generated": [ + { + "emitter": "@azure-tools/typespec-autorest" + } + ] + }, + "schemes": [ + "https" + ], + "host": "management.azure.com", + "produces": [ + "application/json" + ], + "consumes": [ + "application/json" + ], + "security": [ + { + "azure_auth": [ + "user_impersonation" + ] + } + ], + "securityDefinitions": { + "azure_auth": { + "type": "oauth2", + "description": "Azure Active Directory OAuth2 Flow.", + "flow": "implicit", + "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize", + "scopes": { + "user_impersonation": "impersonate your user account" + } + } + }, + "tags": [ + { + "name": "Operations" + }, + { + "name": "Employees" + } + ], + "paths": { + "/providers/Microsoft.ContosoProviderHub/operations": { + "get": { + "operationId": "Operations_List", + "tags": [ + "Operations" + ], + "description": "List the operations for the provider", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/OperationListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/employees": { + "get": { + "operationId": "Employees_ListBySubscription", + "tags": [ + "Employees" + ], + "description": "List Employee resources by subscription ID", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/EmployeeListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees": { + "get": { + "operationId": "Employees_ListByResourceGroup", + "tags": [ + "Employees" + ], + "description": "List Employee resources by resource group", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/EmployeeListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}": { + "get": { + "operationId": "Employees_Get", + "tags": [ + "Employees" + ], + "description": "Get a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "put": { + "operationId": "Employees_CreateOrUpdate", + "tags": [ + "Employees" + ], + "description": "Create a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "resource", + "in": "body", + "description": "Resource create parameters.", + "required": true, + "schema": { + "$ref": "#/definitions/Employee" + } + } + ], + "responses": { + "200": { + "description": "Resource 'Employee' update operation succeeded", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "201": { + "description": "Resource 'Employee' create operation succeeded", + "schema": { + "$ref": "#/definitions/Employee" + }, + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "description": "A link to the status monitor" + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "azure-async-operation" + }, + "x-ms-long-running-operation": true + }, + "patch": { + "operationId": "Employees_Update", + "tags": [ + "Employees" + ], + "description": "Update a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "properties", + "in": "body", + "description": "The resource properties to be updated.", + "required": true, + "schema": { + "$ref": "#/definitions/EmployeeUpdate" + } + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "delete": { + "operationId": "Employees_Delete", + "tags": [ + "Employees" + ], + "description": "Delete a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Resource deleted successfully." + }, + "202": { + "description": "Resource deletion accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "204": { + "description": "Resource does not exist." + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + } + } + }, + "definitions": { + "Employee": { + "type": "object", + "description": "A ContosoProviderHub resource", + "properties": { + "properties": { + "$ref": "#/definitions/EmployeeProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + }, + "etag": { + "type": "string", + "description": "\"If etag is provided in the response body, it may also be provided as a header per the normal etag convention. Entity tags are used for comparing two or more entities from the same requested resource. HTTP/1.1 uses entity tags in the etag (section 14.19), If-Match (section 14.24), If-None-Match (section 14.26), and If-Range (section 14.27) header fields.\")", + "readOnly": true + } + }, + "allOf": [ + { + "$ref": "#/definitions/TrackedResource" + } + ] + }, + "EmployeeListResult": { + "type": "object", + "description": "The response of a Employee list operation.", + "properties": { + "value": { + "type": "array", + "description": "The Employee items on this page", + "items": { + "$ref": "#/definitions/Employee" + } + }, + "nextLink": { + "type": "string", + "format": "uri", + "description": "The link to the next page of items" + } + }, + "required": [ + "value" + ] + }, + "EmployeeProperties": { + "type": "object", + "description": "The rp-specific properties of the employee", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "The employee age in years" + }, + "city": { + "type": "string", + "description": "The city of current residence" + }, + "profile": { + "type": "string", + "format": "base64url", + "description": "security profile for the employee" + }, + "provisioningState": { + "$ref": "#/definitions/ProvisioningState", + "description": "The status of the last operation.", + "readOnly": true + } + } + }, + "EmployeeUpdate": { + "type": "object", + "description": "The type used for update operations of the Employee.", + "properties": { + "tags": { + "type": "object", + "description": "Resource tags.", + "additionalProperties": { + "type": "string" + } + }, + "properties": { + "$ref": "#/definitions/EmployeeUpdateProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + } + } + }, + "EmployeeUpdateProperties": { + "type": "object", + "description": "The updatable properties of the Employee.", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "The employee age in years" + }, + "city": { + "type": "string", + "description": "The city of current residence" + }, + "profile": { + "type": "string", + "format": "base64url", + "description": "security profile for the employee" + } + } + }, + "ProvisioningState": { + "type": "string", + "description": "The provisioning state of a resource.", + "enum": [ + "Succeeded", + "Failed", + "Canceled", + "Provisioning", + "Updating", + "Deleting", + "Accepted" + ], + "x-ms-enum": { + "name": "ProvisioningState", + "modelAsString": true, + "values": [ + { + "name": "Succeeded", + "value": "Succeeded", + "description": "Resource has been created." + }, + { + "name": "Failed", + "value": "Failed", + "description": "Resource creation failed." + }, + { + "name": "Canceled", + "value": "Canceled", + "description": "Resource creation was canceled." + }, + { + "name": "Provisioning", + "value": "Provisioning", + "description": "The resource is being provisioned" + }, + { + "name": "Updating", + "value": "Updating", + "description": "The resource is updating" + }, + { + "name": "Deleting", + "value": "Deleting", + "description": "The resource is being deleted" + }, + { + "name": "Accepted", + "value": "Accepted", + "description": "The resource create request has been accepted" + } + ] + }, + "readOnly": true + }, + "TrackedResource": { + "type": "object", + "description": "A tracked resource with the 'location' property optional", + "properties": { + "tags": { + "type": "object", + "description": "Resource tags.", + "additionalProperties": { + "type": "string" + } + }, + "location": { + "type": "string", + "description": "The geo-location where the resource lives", + "x-ms-mutability": [ + "read", + "create" + ] + } + }, + "allOf": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/Resource" + } + ] + } + }, + "parameters": {} +} diff --git a/packages/samples/test/output/azure/resource-manager/resource-types/private-endpoints/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/resource-types/private-endpoints/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json new file mode 100644 index 0000000000..b9dbfe3be6 --- /dev/null +++ b/packages/samples/test/output/azure/resource-manager/resource-types/private-endpoints/@azure-tools/typespec-autorest/2021-10-01-preview/openapi.json @@ -0,0 +1,1653 @@ +{ + "swagger": "2.0", + "info": { + "title": "ContosoProviderHubClient", + "version": "2021-10-01-preview", + "description": "Contoso Resource Provider management API.", + "x-typespec-generated": [ + { + "emitter": "@azure-tools/typespec-autorest" + } + ] + }, + "schemes": [ + "https" + ], + "host": "management.azure.com", + "produces": [ + "application/json" + ], + "consumes": [ + "application/json" + ], + "security": [ + { + "azure_auth": [ + "user_impersonation" + ] + } + ], + "securityDefinitions": { + "azure_auth": { + "type": "oauth2", + "description": "Azure Active Directory OAuth2 Flow.", + "flow": "implicit", + "authorizationUrl": "https://login.microsoftonline.com/common/oauth2/authorize", + "scopes": { + "user_impersonation": "impersonate your user account" + } + } + }, + "tags": [ + { + "name": "Operations" + }, + { + "name": "Employees" + }, + { + "name": "Dependents" + } + ], + "paths": { + "/providers/Microsoft.ContosoProviderHub/operations": { + "get": { + "operationId": "Operations_List", + "tags": [ + "Operations" + ], + "description": "List the operations for the provider", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/OperationListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/employees": { + "get": { + "operationId": "Employees_ListBySubscription", + "tags": [ + "Employees" + ], + "description": "List Employee resources by subscription ID", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/EmployeeListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees": { + "get": { + "operationId": "Employees_ListByResourceGroup", + "tags": [ + "Employees" + ], + "description": "List Employee resources by resource group", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/EmployeeListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}": { + "get": { + "operationId": "Employees_Get", + "tags": [ + "Employees" + ], + "description": "Get a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "put": { + "operationId": "Employees_CreateOrUpdate", + "tags": [ + "Employees" + ], + "description": "Create a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "resource", + "in": "body", + "description": "Resource create parameters.", + "required": true, + "schema": { + "$ref": "#/definitions/Employee" + } + } + ], + "responses": { + "200": { + "description": "Resource 'Employee' update operation succeeded", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "201": { + "description": "Resource 'Employee' create operation succeeded", + "schema": { + "$ref": "#/definitions/Employee" + }, + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "description": "A link to the status monitor" + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "azure-async-operation" + }, + "x-ms-long-running-operation": true + }, + "patch": { + "operationId": "Employees_Update", + "tags": [ + "Employees" + ], + "description": "Update a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "properties", + "in": "body", + "description": "The resource properties to be updated.", + "required": true, + "schema": { + "$ref": "#/definitions/EmployeeUpdate" + } + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Employee" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "delete": { + "operationId": "Employees_Delete", + "tags": [ + "Employees" + ], + "description": "Delete a Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Resource deleted successfully." + }, + "204": { + "description": "Resource does not exist." + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "head": { + "operationId": "Employees_CheckExistence", + "tags": [ + "Employees" + ], + "description": "A sample HEAD operation to check resource existence", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "204": { + "description": "The Azure resource exists" + }, + "404": { + "description": "The Azure resource is not found" + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents": { + "get": { + "operationId": "Dependents_List", + "tags": [ + "Dependents" + ], + "description": "List Dependent resources by Employee", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/DependentListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents/{dependentName}": { + "get": { + "operationId": "Dependents_Get", + "tags": [ + "Dependents" + ], + "description": "Get a Dependent", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Dependent" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "put": { + "operationId": "Dependents_CreateOrUpdate", + "tags": [ + "Dependents" + ], + "description": "Create a Dependent", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "resource", + "in": "body", + "description": "Resource create parameters.", + "required": true, + "schema": { + "$ref": "#/definitions/Dependent" + } + } + ], + "responses": { + "200": { + "description": "Resource 'Dependent' update operation succeeded", + "schema": { + "$ref": "#/definitions/Dependent" + } + }, + "201": { + "description": "Resource 'Dependent' create operation succeeded", + "schema": { + "$ref": "#/definitions/Dependent" + }, + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "description": "A link to the status monitor" + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "azure-async-operation" + }, + "x-ms-long-running-operation": true + }, + "patch": { + "operationId": "Dependents_Update", + "tags": [ + "Dependents" + ], + "description": "Update a Dependent", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "properties", + "in": "body", + "description": "The resource properties to be updated.", + "required": true, + "schema": { + "$ref": "#/definitions/DependentUpdate" + } + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/Dependent" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "delete": { + "operationId": "Dependents_Delete", + "tags": [ + "Dependents" + ], + "description": "Delete a Dependent", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Resource deleted successfully." + }, + "204": { + "description": "Resource does not exist." + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents/{dependentName}/privateEndpointConnections": { + "get": { + "operationId": "Dependents_ListPrivateEndpointConnections", + "tags": [ + "Dependents" + ], + "description": "List Dependent PrivateEndpointConnections", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/PrivateEndpointConnectionListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents/{dependentName}/privateEndpointConnections/{privateEndpointConnectionName}": { + "get": { + "operationId": "Dependents_GetPrivateEndpointConnection", + "tags": [ + "Dependents" + ], + "description": "Get a Dependent PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "put": { + "operationId": "Dependents_CreateOrUpdatePrivateEndpointConnection", + "tags": [ + "Dependents" + ], + "description": "Create a Dependent PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + }, + { + "name": "resource", + "in": "body", + "description": "Resource create parameters.", + "required": false, + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + } + ], + "responses": { + "200": { + "description": "Resource 'PrivateEndpointConnection' update operation succeeded", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "201": { + "description": "Resource 'PrivateEndpointConnection' create operation succeeded", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + }, + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "description": "A link to the status monitor" + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "azure-async-operation" + }, + "x-ms-long-running-operation": true + }, + "patch": { + "operationId": "Dependents_UpdatePrivateEndpointConnection", + "tags": [ + "Dependents" + ], + "description": "Update a Dependent PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "202": { + "description": "Resource update request accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + }, + "delete": { + "operationId": "Dependents_DeletePrivateEndpointConnection", + "tags": [ + "Dependents" + ], + "description": "Delete a Dependent PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "dependentName", + "in": "path", + "description": "The name of the Dependent", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + } + ], + "responses": { + "202": { + "description": "Resource deletion accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "204": { + "description": "Resource does not exist." + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/move": { + "post": { + "operationId": "Employees_Move", + "tags": [ + "Employees" + ], + "description": "A sample resource action that move employee to different location", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "name": "body", + "in": "body", + "description": "The content of the action request", + "required": true, + "schema": { + "$ref": "#/definitions/MoveRequest" + } + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/MoveResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/privateEndpointConnections": { + "get": { + "operationId": "Employees_ListPrivateEndpointConnections", + "tags": [ + "Employees" + ], + "description": "List Employee PrivateEndpointConnections", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "#/definitions/PrivateEndpointConnectionListResult" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/privateEndpointConnections/{privateEndpointConnectionName}": { + "get": { + "operationId": "Employees_GetPrivateEndpointConnection", + "tags": [ + "Employees" + ], + "description": "Get a Employee PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + } + }, + "put": { + "operationId": "Employees_CreateOrUpdatePrivateEndpointConnection", + "tags": [ + "Employees" + ], + "description": "Create a Employee PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + }, + { + "name": "resource", + "in": "body", + "description": "Resource create parameters.", + "required": true, + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + } + ], + "responses": { + "200": { + "description": "Resource 'PrivateEndpointConnection' update operation succeeded", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "201": { + "description": "Resource 'PrivateEndpointConnection' create operation succeeded", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + }, + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "description": "A link to the status monitor" + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "azure-async-operation" + }, + "x-ms-long-running-operation": true + }, + "patch": { + "operationId": "Employees_UpdatePrivateEndpointConnection", + "tags": [ + "Employees" + ], + "description": "Update a Employee PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + }, + { + "name": "properties", + "in": "body", + "description": "The resource properties to be updated.", + "required": true, + "schema": { + "$ref": "#/definitions/Azure.ResourceManager.PrivateEndpointConnectionUpdate" + } + } + ], + "responses": { + "200": { + "description": "Azure operation completed successfully.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "202": { + "description": "Resource update request accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + }, + "delete": { + "operationId": "Employees_DeletePrivateEndpointConnection", + "tags": [ + "Employees" + ], + "description": "Delete a Employee PrivateEndpointConnection", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ResourceGroupNameParameter" + }, + { + "name": "employeeName", + "in": "path", + "description": "The name of the Employee", + "required": true, + "type": "string", + "pattern": "^[a-zA-Z0-9-]{3,24}$" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/parameters/PrivateEndpointConnectionName" + } + ], + "responses": { + "202": { + "description": "Resource deletion accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "204": { + "description": "Resource does not exist." + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + } + } + }, + "definitions": { + "Azure.ResourceManager.PrivateEndpointConnectionUpdate": { + "type": "object", + "description": "PATCH model for private endpoint connections", + "properties": { + "properties": { + "type": "object", + "description": "The private endpoint connection properties", + "properties": { + "privateEndpoint": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpoint", + "description": "The private endpoint resource." + }, + "privateLinkServiceConnectionState": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateLinkServiceConnectionState", + "description": "A collection of information about the state of the connection between service consumer and provider." + } + } + } + } + }, + "Dependent": { + "type": "object", + "description": "An employee dependent", + "properties": { + "properties": { + "$ref": "#/definitions/DependentProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + } + }, + "allOf": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ProxyResource" + } + ] + }, + "DependentListResult": { + "type": "object", + "description": "The response of a Dependent list operation.", + "properties": { + "value": { + "type": "array", + "description": "The Dependent items on this page", + "items": { + "$ref": "#/definitions/Dependent" + } + }, + "nextLink": { + "type": "string", + "format": "uri", + "description": "The link to the next page of items" + } + }, + "required": [ + "value" + ] + }, + "DependentProperties": { + "type": "object", + "description": "Dependent properties", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "Age of dependent" + }, + "gender": { + "type": "string", + "description": "Gender of dependent" + }, + "provisioningState": { + "$ref": "#/definitions/ProvisioningState", + "description": "The status of the last operation.", + "readOnly": true + } + }, + "required": [ + "age", + "gender" + ] + }, + "DependentUpdate": { + "type": "object", + "description": "The type used for update operations of the Dependent.", + "properties": { + "properties": { + "$ref": "#/definitions/DependentUpdateProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + } + } + }, + "DependentUpdateProperties": { + "type": "object", + "description": "The updatable properties of the Dependent.", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "Age of dependent" + }, + "gender": { + "type": "string", + "description": "Gender of dependent" + } + } + }, + "Employee": { + "type": "object", + "description": "A ContosoProviderHub resource", + "properties": { + "properties": { + "$ref": "#/definitions/EmployeeProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + } + }, + "allOf": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/TrackedResource" + } + ] + }, + "EmployeeListResult": { + "type": "object", + "description": "The response of a Employee list operation.", + "properties": { + "value": { + "type": "array", + "description": "The Employee items on this page", + "items": { + "$ref": "#/definitions/Employee" + } + }, + "nextLink": { + "type": "string", + "format": "uri", + "description": "The link to the next page of items" + } + }, + "required": [ + "value" + ] + }, + "EmployeeProperties": { + "type": "object", + "description": "Employee properties", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "Age of employee" + }, + "city": { + "type": "string", + "description": "City of employee" + }, + "profile": { + "type": "string", + "format": "base64url", + "description": "Profile of employee" + }, + "provisioningState": { + "$ref": "#/definitions/ProvisioningState", + "description": "The status of the last operation.", + "readOnly": true + } + } + }, + "EmployeeUpdate": { + "type": "object", + "description": "The type used for update operations of the Employee.", + "properties": { + "tags": { + "type": "object", + "description": "Resource tags.", + "additionalProperties": { + "type": "string" + } + }, + "properties": { + "$ref": "#/definitions/EmployeeUpdateProperties", + "description": "The resource-specific properties for this resource.", + "x-ms-client-flatten": true + } + } + }, + "EmployeeUpdateProperties": { + "type": "object", + "description": "The updatable properties of the Employee.", + "properties": { + "age": { + "type": "integer", + "format": "int32", + "description": "Age of employee" + }, + "city": { + "type": "string", + "description": "City of employee" + }, + "profile": { + "type": "string", + "format": "base64url", + "description": "Profile of employee" + } + } + }, + "MoveRequest": { + "type": "object", + "description": "Employee move request", + "properties": { + "from": { + "type": "string", + "description": "The moving from location" + }, + "to": { + "type": "string", + "description": "The moving to location" + } + }, + "required": [ + "from", + "to" + ] + }, + "MoveResponse": { + "type": "object", + "description": "Employee move response", + "properties": { + "movingStatus": { + "type": "string", + "description": "The status of the move" + } + }, + "required": [ + "movingStatus" + ] + }, + "PrivateEndpointConnectionListResult": { + "type": "object", + "description": "The response of a PrivateEndpointConnection list operation.", + "properties": { + "value": { + "type": "array", + "description": "The PrivateEndpointConnection items on this page", + "items": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/privatelinks.json#/definitions/PrivateEndpointConnection" + } + }, + "nextLink": { + "type": "string", + "format": "uri", + "description": "The link to the next page of items" + } + }, + "required": [ + "value" + ] + }, + "ProvisioningState": { + "type": "string", + "description": "The provisioning state of a resource.", + "enum": [ + "Succeeded", + "Failed", + "Canceled", + "Provisioning", + "Updating", + "Deleting", + "Accepted" + ], + "x-ms-enum": { + "name": "ProvisioningState", + "modelAsString": true, + "values": [ + { + "name": "Succeeded", + "value": "Succeeded", + "description": "Resource has been created." + }, + { + "name": "Failed", + "value": "Failed", + "description": "Resource creation failed." + }, + { + "name": "Canceled", + "value": "Canceled", + "description": "Resource creation was canceled." + }, + { + "name": "Provisioning", + "value": "Provisioning", + "description": "The resource is being provisioned" + }, + { + "name": "Updating", + "value": "Updating", + "description": "The resource is updating" + }, + { + "name": "Deleting", + "value": "Deleting", + "description": "The resource is being deleted" + }, + { + "name": "Accepted", + "value": "Accepted", + "description": "The resource create request has been accepted" + } + ] + }, + "readOnly": true + } + }, + "parameters": {} +} diff --git a/packages/typespec-autorest/CHANGELOG.md b/packages/typespec-autorest/CHANGELOG.md index df4b2fac40..fe941ad43f 100644 --- a/packages/typespec-autorest/CHANGELOG.md +++ b/packages/typespec-autorest/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log - @azure-tools/typespec-autorest +## 0.59.1 + +### Bug Fixes + +- [#3173](https://github.com/Azure/typespec-azure/pull/3173) Inline azureLocation +- [#3147](https://github.com/Azure/typespec-azure/pull/3147) Add support for x-ms-external through armExternalResource decorator +- [#3147](https://github.com/Azure/typespec-azure/pull/3147) Add support for x-ms-azure-resource extension for custom resources + + ## 0.59.0 ### Features diff --git a/packages/typespec-autorest/package.json b/packages/typespec-autorest/package.json index b6802ac4c5..6ca0292d9b 100644 --- a/packages/typespec-autorest/package.json +++ b/packages/typespec-autorest/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-autorest", - "version": "0.59.0", + "version": "0.59.1", "author": "Microsoft Corporation", "description": "TypeSpec library for emitting openapi from the TypeSpec REST protocol binding", "homepage": "https://azure.github.io/typespec-azure", diff --git a/packages/typespec-autorest/src/openapi.ts b/packages/typespec-autorest/src/openapi.ts index cced691284..b8ce62bd32 100644 --- a/packages/typespec-autorest/src/openapi.ts +++ b/packages/typespec-autorest/src/openapi.ts @@ -15,8 +15,11 @@ import { getArmCommonTypeOpenAPIRef, getArmIdentifiers, getArmKeyIdentifiers, + getCustomResourceOptions, getExternalTypeRef, + getInlineAzureType, isArmCommonType, + isArmExternalType, isArmProviderNamespace, isAzureResource, isConditionallyFlattened, @@ -68,6 +71,7 @@ import { getMinItems, getMinLength, getMinValue, + getNamespaceFullName, getPagingOperation, getPattern, getProperty, @@ -963,6 +967,16 @@ export async function getOpenAPIForService( } return undefined; } + function shouldInlineCoreScalarProperty(type: Type): boolean { + if ( + type.kind !== "ModelProperty" || + type.type.kind !== "Scalar" || + type.type.namespace === undefined + ) + return false; + const nsName = getNamespaceFullName(type.type.namespace); + return nsName === "Azure.Core" && getInlineAzureType(program, type) === true; + } function getSchemaOrRef(type: Type, schemaContext: SchemaContext, namespace?: Namespace): any { let schemaNameOverride: ((name: string, visibility: Visibility) => string) | undefined = undefined; @@ -2114,7 +2128,13 @@ export async function getOpenAPIForService( propSchema = getSchemaOrRef(prop.type, context); } } else { - propSchema = getSchemaOrRef(prop.type, context); + propSchema = shouldInlineCoreScalarProperty(prop) + ? getSchemaForInlineType( + prop.type, + getOpenAPITypeName(program, prop.type, typeNameOptions), + context, + ) + : getSchemaOrRef(prop.type, context); applyArmIdentifiersDecorator(prop.type, propSchema, prop); } @@ -2128,12 +2148,19 @@ export async function getOpenAPIForService( function attachExtensions(type: Type, emitObject: any) { // Attach any OpenAPI extensions const extensions = getExtensions(program, type); - if (isAzureResource(program, type as Model)) { + if ( + type.kind === "Model" && + (isAzureResource(program, type) || + getCustomResourceOptions(program, type)?.isAzureResource === true) + ) { emitObject["x-ms-azure-resource"] = true; } if (getAsEmbeddingVector(program, type as Model) !== undefined) { emitObject["x-ms-embedding-vector"] = true; } + if (type.kind === "Model" && isArmExternalType(program, type) === true) { + emitObject["x-ms-external"] = true; + } if (type.kind === "Scalar") { const ext = getArmResourceIdentifierConfig(program, type); if (ext) { diff --git a/packages/typespec-autorest/test/arm/resources.test.ts b/packages/typespec-autorest/test/arm/resources.test.ts index e5c134a88b..249cabe007 100644 --- a/packages/typespec-autorest/test/arm/resources.test.ts +++ b/packages/typespec-autorest/test/arm/resources.test.ts @@ -1,5 +1,5 @@ import { deepEqual, deepStrictEqual, ok, strictEqual } from "assert"; -import { it } from "vitest"; +import { expect, it } from "vitest"; import { compileOpenAPI } from "../test-host.js"; it("emits correct paths for tenant resources", async () => { @@ -338,6 +338,62 @@ it("emits x-ms-azure-resource for resource with @azureResourceBase", async () => ok(openApi.definitions?.Widget["x-ms-azure-resource"]); }); +it("emits x-ms-external for resource with @armExternalType", async () => { + const openApi = await compileOpenAPI( + ` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + namespace Microsoft.Contoso; + + #suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "legacy test" + @doc("Widget resource") + @Azure.ResourceManager.Legacy.armExternalType + model Widget { + name: string; + } +`, + { preset: "azure" }, + ); + ok(openApi.definitions?.Widget["x-ms-external"]); +}); + +it("emits x-ms-azure-resource for resource with @customAzureResource and options", async () => { + const openApi = await compileOpenAPI( + ` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + namespace Microsoft.Contoso; + + #suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "legacy test" + @doc("Widget resource") + @Azure.ResourceManager.Legacy.customAzureResource(#{isAzureResource: true}) + model Widget { + name: string; + } +`, + { preset: "azure" }, + ); + ok(openApi.definitions?.Widget["x-ms-azure-resource"]); +}); +it("does not emit x-ms-azure-resource for resource with @customAzureResource", async () => { + const openApi = await compileOpenAPI( + ` + @armProviderNamespace + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + namespace Microsoft.Contoso; + + #suppress "@azure-tools/typespec-azure-core/no-legacy-usage" "legacy test" + @doc("Widget resource") + @Azure.ResourceManager.Legacy.customAzureResource + model Widget { + name: string; + } +`, + { preset: "azure" }, + ); + expect(openApi.definitions?.Widget["x-ms-azure-resource"]).toBeUndefined(); +}); + it("excludes properties marked @invisible from the resource payload", async () => { const openApi = await compileOpenAPI( ` diff --git a/packages/typespec-autorest/test/azure-core-types.test.ts b/packages/typespec-autorest/test/azure-core-types.test.ts index afad785e31..7dc63a1c69 100644 --- a/packages/typespec-autorest/test/azure-core-types.test.ts +++ b/packages/typespec-autorest/test/azure-core-types.test.ts @@ -119,3 +119,60 @@ describe("@uniqueItems", () => { }); }); }); + +describe("azureLocation", () => { + it("defines property with azureLocation type inline", async () => { + const res = await compileOpenAPI( + ` + ${base} + model Pet { @Azure.ResourceManager.CommonTypes.Private.inlineAzureType location: Azure.Core.azureLocation }; + `, + { preset: "azure" }, + ); + + ok(res.definitions); + ok(res.definitions.Pet); + ok(res.definitions.Pet.properties); + ok(res.definitions.Pet.properties.location, "expected definition named location"); + deepStrictEqual(res.definitions.Pet.properties.location, { + type: "string", + description: "Represents an Azure geography region where supported resource providers live.", + }); + }); + it("defines property with azureLocation type inline but does not override description", async () => { + const res = await compileOpenAPI( + ` + ${base} + model Pet { /** The azure location */ @Azure.ResourceManager.CommonTypes.Private.inlineAzureType location: Azure.Core.azureLocation }; + `, + { preset: "azure" }, + ); + + ok(res.definitions); + ok(res.definitions.Pet); + ok(res.definitions.Pet.properties); + ok(res.definitions.Pet.properties.location, "expected definition named location"); + deepStrictEqual(res.definitions.Pet.properties.location, { + type: "string", + description: "The azure location", + }); + }); + it("defines property with azureLocation type as ref without decorator", async () => { + const res = await compileOpenAPI( + ` + ${base} + model Pet { /** The azure location */ location: Azure.Core.azureLocation }; + `, + { preset: "azure" }, + ); + + ok(res.definitions); + ok(res.definitions.Pet); + ok(res.definitions.Pet.properties); + ok(res.definitions.Pet.properties.location, "expected definition named location"); + deepStrictEqual(res.definitions.Pet.properties.location, { + $ref: "#/definitions/Azure.Core.azureLocation", + description: "The azure location", + }); + }); +}); diff --git a/packages/typespec-azure-resource-manager/CHANGELOG.md b/packages/typespec-azure-resource-manager/CHANGELOG.md index 6d0463ea94..7cfd6717be 100644 --- a/packages/typespec-azure-resource-manager/CHANGELOG.md +++ b/packages/typespec-azure-resource-manager/CHANGELOG.md @@ -1,5 +1,23 @@ # Change Log - @azure-tools/typespec-azure-resource-manager +## 0.59.2 + +### Bug Fixes + +- [#3147](https://github.com/Azure/typespec-azure/pull/3147) Add support for x-ms-external through armExternalResource decorator +- [#3154](https://github.com/Azure/typespec-azure/pull/3154) Add single page list and correct put template names +- [#3172](https://github.com/Azure/typespec-azure/pull/3172) Add single page list and legacy put and patch operations + + +## 0.59.1 + +### Bug Fixes + +- [#3142](https://github.com/Azure/typespec-azure/pull/3142) Relax constraints for Action request and synchronous response parameters +- [#3143](https://github.com/Azure/typespec-azure/pull/3143) Add templates for optional location and etags +- [#3141](https://github.com/Azure/typespec-azure/pull/3141) Add operations for Private Endpoints + + ## 0.59.0 ### Deprecations diff --git a/packages/typespec-azure-resource-manager/README.md b/packages/typespec-azure-resource-manager/README.md index b83afcffbb..5e1e9e0a52 100644 --- a/packages/typespec-azure-resource-manager/README.md +++ b/packages/typespec-azure-resource-manager/README.md @@ -340,9 +340,9 @@ Azure.ResourceManager common types. ##### Parameters -| Name | Type | Description | -| -------- | ---------------- | ----------- | -| provider | `valueof string` | | +| Name | Type | Description | +| -------- | ---------------- | ------------------------------------------------------------------- | +| provider | `valueof string` | Optional. The resource provider namespace for the virtual resource. | #### `@extensionResource` @@ -429,9 +429,9 @@ This decorator sets the base type of the given resource. ##### Parameters -| Name | Type | Description | -| ---------- | ---------------------------------------------------------------------------- | ----------- | -| baseTypeIt | `"Tenant" \| "Subscription" \| "ResourceGroup" \| "Location" \| "Extension"` | | +| Name | Type | Description | +| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| baseTypeIt | `"Tenant" \| "Subscription" \| "ResourceGroup" \| "Location" \| "Extension"` | The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" | #### `@resourceGroupResource` @@ -541,10 +541,28 @@ This allows sharing Azure Resource Manager resource types across specifications ### Azure.ResourceManager.Legacy +- [`@armExternalType`](#@armexternaltype) - [`@armOperationRoute`](#@armoperationroute) - [`@customAzureResource`](#@customazureresource) - [`@externalTypeRef`](#@externaltyperef) +#### `@armExternalType` + +Signifies that a Resource is represented using a library type in generated SDKs. + +```typespec +@Azure.ResourceManager.Legacy.armExternalType +``` + +##### Target + +The model to that is an external resource +`Model` + +##### Parameters + +None + #### `@armOperationRoute` Signifies that an operation is an Azure Resource Manager operation @@ -571,7 +589,7 @@ This decorator is used on resources that do not satisfy the definition of a reso but need to be identified as such. ```typespec -@Azure.ResourceManager.Legacy.customAzureResource +@Azure.ResourceManager.Legacy.customAzureResource(options?: valueof Azure.ResourceManager.Legacy.CustomResourceOptions) ``` ##### Target @@ -580,7 +598,9 @@ but need to be identified as such. ##### Parameters -None +| Name | Type | Description | +| ------- | --------------------------------------------------------- | ---------------------------------------------------- | +| options | [valueof `CustomResourceOptions`](#customresourceoptions) | Options for customizing the behavior of the resource | #### `@externalTypeRef` diff --git a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.CommonTypes.Private.ts b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.CommonTypes.Private.ts index f4c4743855..40ed618687 100644 --- a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.CommonTypes.Private.ts +++ b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.CommonTypes.Private.ts @@ -34,6 +34,11 @@ export type ArmCommonParameterDecorator = ( referenceFile?: string, ) => void; +/** + * Signifies that a property can be treated as an inline type in emitters + */ +export type InlineAzureTypeDecorator = (context: DecoratorContext, target: ModelProperty) => void; + /** * * @@ -59,5 +64,6 @@ export type ArmCommonDefinitionDecorator = ( export type AzureResourceManagerCommonTypesPrivateDecorators = { armCommonTypesVersions: ArmCommonTypesVersionsDecorator; armCommonParameter: ArmCommonParameterDecorator; + inlineAzureType: InlineAzureTypeDecorator; armCommonDefinition: ArmCommonDefinitionDecorator; }; diff --git a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Legacy.ts b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Legacy.ts index e6f45ca7ac..8b21cbd241 100644 --- a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Legacy.ts +++ b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Legacy.ts @@ -1,5 +1,9 @@ import type { DecoratorContext, Model, ModelProperty, Operation } from "@typespec/compiler"; +export interface CustomResourceOptions { + readonly isAzureResource?: boolean; +} + export interface ArmOperationOptions { readonly useStaticRoute?: boolean; readonly route?: string; @@ -8,8 +12,14 @@ export interface ArmOperationOptions { /** * This decorator is used on resources that do not satisfy the definition of a resource * but need to be identified as such. + * + * @param options Options for customizing the behavior of the resource */ -export type CustomAzureResourceDecorator = (context: DecoratorContext, target: Model) => void; +export type CustomAzureResourceDecorator = ( + context: DecoratorContext, + target: Model, + options?: CustomResourceOptions, +) => void; /** * Specify an external reference that should be used when emitting this type. @@ -35,8 +45,16 @@ export type ArmOperationRouteDecorator = ( route?: ArmOperationOptions, ) => void; +/** + * Signifies that a Resource is represented using a library type in generated SDKs. + * + * @param target The model to that is an external resource + */ +export type ArmExternalTypeDecorator = (context: DecoratorContext, target: Model) => void; + export type AzureResourceManagerLegacyDecorators = { customAzureResource: CustomAzureResourceDecorator; externalTypeRef: ExternalTypeRefDecorator; armOperationRoute: ArmOperationRouteDecorator; + armExternalType: ArmExternalTypeDecorator; }; diff --git a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Private.ts b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Private.ts index 90d7c36219..71ffcce520 100644 --- a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Private.ts +++ b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.Private.ts @@ -110,6 +110,23 @@ export type ArmResourceInternalDecorator = ( properties: Model, ) => void; +/** + * This decorator identifies Azure Resource Manager resource types that do not define + * the name identifier parameter and type + * + * @param target Azure Resource Manager resource type + * @param properties Azure Resource Manager resource properties + * @param type The resource type name, e.g. "virtualMachines" + * @param nameParameter The name of the resource name parameter, e.g. "virtualMachineName" + */ +export type ArmResourceWithParameterDecorator = ( + context: DecoratorContext, + target: Model, + properties: Model, + type: string, + nameParameter: string, +) => void; + /** * Provides default name decoration on resource name property with * camelcased and pluralized key and segment name @@ -184,6 +201,7 @@ export type AzureResourceManagerPrivateDecorators = { armUpdateProviderNamespace: ArmUpdateProviderNamespaceDecorator; assignUniqueProviderNameValue: AssignUniqueProviderNameValueDecorator; armResourceInternal: ArmResourceInternalDecorator; + armResourceWithParameter: ArmResourceWithParameterDecorator; defaultResourceKeySegmentName: DefaultResourceKeySegmentNameDecorator; enforceConstraint: EnforceConstraintDecorator; armRenameListByOperation: ArmRenameListByOperationDecorator; diff --git a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.ts b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.ts index d1cc75c8ac..706a274b1f 100644 --- a/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.ts +++ b/packages/typespec-azure-resource-manager/generated-defs/Azure.ResourceManager.ts @@ -262,6 +262,7 @@ export type ArmCommonTypesVersionDecorator = ( * Azure.ResourceManager common types. * * @param propertiesType : The type of the resource properties. + * @param provider Optional. The resource provider namespace for the virtual resource. */ export type ArmVirtualResourceDecorator = ( context: DecoratorContext, @@ -272,7 +273,7 @@ export type ArmVirtualResourceDecorator = ( /** * This decorator sets the base type of the given resource. * - * @param baseType The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" + * @param baseTypeIt The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" */ export type ResourceBaseTypeDecorator = ( context: DecoratorContext, diff --git a/packages/typespec-azure-resource-manager/lib/arm.tsp b/packages/typespec-azure-resource-manager/lib/arm.tsp index 443205d238..0be69b4011 100644 --- a/packages/typespec-azure-resource-manager/lib/arm.tsp +++ b/packages/typespec-azure-resource-manager/lib/arm.tsp @@ -6,7 +6,7 @@ import "@typespec/versioning"; import "@azure-tools/typespec-azure-core"; import "./foundations/arm.foundations.tsp"; -import "./Legacy/arm.legacy.tsp"; +import "./legacy-types/arm.legacy.tsp"; import "./common-types/common-types.tsp"; import "./extension/extension.tsp"; import "./backcompat.tsp"; @@ -17,6 +17,7 @@ import "./decorators.tsp"; import "./interfaces.tsp"; import "./responses.tsp"; import "./parameters.tsp"; +import "./private-endpoints.tsp"; using Http; using Rest; diff --git a/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp b/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp index b5aae308d2..e6886a8479 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/commontypes.private.decorators.tsp @@ -41,3 +41,8 @@ extern dec armCommonParameter( * Marks an enum as representing the valid `common-types` versions. */ extern dec armCommonTypesVersions(target: Enum); + +/** + * Signifies that a property can be treated as an inline type in emitters + */ +extern dec inlineAzureType(target: ModelProperty); diff --git a/packages/typespec-azure-resource-manager/lib/common-types/types.tsp b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp index 08c8592826..7421e34b0d 100644 --- a/packages/typespec-azure-resource-manager/lib/common-types/types.tsp +++ b/packages/typespec-azure-resource-manager/lib/common-types/types.tsp @@ -1,6 +1,5 @@ using Http; using Rest; -using OpenAPI; using Versioning; using Azure.Core; @@ -45,7 +44,8 @@ model TrackedResource extends Resource { /** The geo-location where the resource lives */ @visibility(Lifecycle.Read, Lifecycle.Create) - location: string; + @Azure.ResourceManager.CommonTypes.Private.inlineAzureType + location: Azure.Core.azureLocation; } /** @@ -344,6 +344,8 @@ union createdByType { string, } +/** @dev Resource Identity Type */ +@doc("") union ResourceIdentityType { SystemAssigned: "SystemAssigned", } @@ -367,6 +369,7 @@ model Identity { type?: ResourceIdentityType; } +/** @dev Properties of a KeyVault */ model KeyVaultProperties { /** Key vault uri to access the encryption key. */ keyIdentifier?: string; @@ -516,6 +519,7 @@ model LocationParameter { @path @minLength(1) @segment("locations") + @Azure.ResourceManager.CommonTypes.Private.inlineAzureType location: string; } diff --git a/packages/typespec-azure-resource-manager/lib/decorators.tsp b/packages/typespec-azure-resource-manager/lib/decorators.tsp index 4b953959df..3c42ce6ca9 100644 --- a/packages/typespec-azure-resource-manager/lib/decorators.tsp +++ b/packages/typespec-azure-resource-manager/lib/decorators.tsp @@ -211,13 +211,14 @@ extern dec armCommonTypesVersion( * Azure.ResourceManager common types. * * @param propertiesType: The type of the resource properties. + * @param provider Optional. The resource provider namespace for the virtual resource. */ extern dec armVirtualResource(target: Model, provider?: valueof string); /** * This decorator sets the base type of the given resource. * - * @param baseType The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" + * @param baseTypeIt The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" */ extern dec resourceBaseType( target: Model, diff --git a/packages/typespec-azure-resource-manager/lib/interfaces.tsp b/packages/typespec-azure-resource-manager/lib/interfaces.tsp index 01865a621f..8e3f0b664c 100644 --- a/packages/typespec-azure-resource-manager/lib/interfaces.tsp +++ b/packages/typespec-azure-resource-manager/lib/interfaces.tsp @@ -13,6 +13,9 @@ namespace Azure.ResourceManager; * GET "/providers/Microsoft.ContosoProviderHub/operations" */ interface Operations { + /** + * @dev List the operations for the provider. + */ @tag("Operations") @autoRoute @armUpdateProviderNamespace diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/arm.legacy.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/arm.legacy.tsp similarity index 67% rename from packages/typespec-azure-resource-manager/lib/Legacy/arm.legacy.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/arm.legacy.tsp index 7380b17c12..763201355a 100644 --- a/packages/typespec-azure-resource-manager/lib/Legacy/arm.legacy.tsp +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/arm.legacy.tsp @@ -1,8 +1,10 @@ import "./managed-identity.tsp"; -import "./decorator.tsp"; +import "./legacy.decorators.tsp"; import "./operations.tsp"; import "./interfaces.tsp"; import "./extension.tsp"; import "./extension-operations.tsp"; +import "./private-endpoints.tsp"; +import "./resource.tsp"; namespace Azure.ResourceManager.Legacy; diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/extension-operations.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/extension-operations.tsp similarity index 81% rename from packages/typespec-azure-resource-manager/lib/Legacy/extension-operations.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/extension-operations.tsp index 0bbaab91ab..4946cae484 100644 --- a/packages/typespec-azure-resource-manager/lib/Legacy/extension-operations.tsp +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/extension-operations.tsp @@ -8,6 +8,42 @@ using Azure.ResourceManager.Foundations; using Rest; using Azure.ResourceManager.Private; +/** + * DEPRECATED: Use CreateOrReplaceAsync instead. + * A long-running resource CreateOrUpdate (PUT) + * @template TargetResource the target resource, e.g. Extension.Subscription or Extension.ManagementGroup or Extension.ResourceGroup + * @template ExtensionResource the resource being created or updated + * @template Request Optional. The request body for the createOrUpdate operation + * @template LroHeaders Optional. Allows overriding the lro headers returned on resource create + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. If true, the request body is optional + */ +alias CreateOrUpdateAsync< + TargetResource extends Foundations.SimpleResource, + ExtensionResource extends Foundations.SimpleResource, + Request extends {} | void = ExtensionResource, + LroHeaders extends TypeSpec.Reflection.Model = ArmAsyncOperationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedResponse< + ExtensionResource, + LroHeaders + >, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false +> = CreateOrReplaceAsync< + TargetResource, + ExtensionResource, + Request, + LroHeaders, + Parameters, + Response, + Error, + OptionalRequestBody +>; + /** A long-running resource CreateOrUpdate (PUT) * @template TargetResource the target resource, e.g. Extension.Subscription or Extension.ManagementGroup or Extension.ResourceGroup * @template ExtensionResource the resource being created or updated @@ -25,7 +61,7 @@ using Azure.ResourceManager.Private; @enforceConstraint(ExtensionResource, Foundations.Resource) @Azure.Core.Foundations.Private.defaultFinalStateVia(#["location", "azure-async-operation"]) @put -op CreateOrUpdateAsync< +op CreateOrReplaceAsync< TargetResource extends Foundations.SimpleResource, ExtensionResource extends Foundations.SimpleResource, Request extends {} | void = ExtensionResource, diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/extension.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/extension.tsp similarity index 90% rename from packages/typespec-azure-resource-manager/lib/Legacy/extension.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/extension.tsp index b8755730eb..188ddae2f0 100644 --- a/packages/typespec-azure-resource-manager/lib/Legacy/extension.tsp +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/extension.tsp @@ -28,6 +28,7 @@ interface ExtensionOperations< * @template OptionalRequestBody Optional. Indicates whether the request body is optional * @template ErrorType Optional. The error response, if non-standard. * @template OperationOptions Optional. The route options for the operation. + * @template Request Optional. The request body for the createOrUpdate operation. */ @armOperationRoute(OperationOptions) @doc("Create a {name}", Resource) @@ -45,12 +46,13 @@ interface ExtensionOperations< >, OptionalRequestBody extends valueof boolean = false, ErrorType extends {} = ErrorResponse, - OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false } + OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false }, + Request extends {} | void = Resource >( ...TargetParameters, ...ExtensionInstanceParameters, ...Parameters, - @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Resource, + @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Request, ): Response | ErrorType; /** @@ -61,6 +63,7 @@ interface ExtensionOperations< * @template OptionalRequestBody Optional. Indicates whether the request body is optional * @template ErrorType Optional. The error response, if non-standard. * @template OperationOptions Optional. The route options for the operation. + * @template Request Optional. The request body for the createOrUpdate operation. */ #suppress "@azure-tools/typespec-azure-core/no-private-usage" @armOperationRoute(OperationOptions) @@ -73,12 +76,13 @@ interface ExtensionOperations< Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedSyncResponse, OptionalRequestBody extends valueof boolean = false, ErrorType extends {} = ErrorResponse, - OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false } + OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false }, + Request extends {} | void = Resource >( ...TargetParameters, ...ExtensionInstanceParameters, ...Parameters, - @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Resource, + @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Request, ): Response | ErrorType; /** @@ -98,7 +102,7 @@ interface ExtensionOperations< @patch(#{ implicitOptionality: false }) CustomPatchAsync< Resource extends Foundations.SimpleResource, - PatchModel extends {} = Azure.ResourceManager.Foundations.TagsUpdateModel, + PatchModel extends {} | void = Azure.ResourceManager.Foundations.TagsUpdateModel, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, Resource, @@ -136,7 +140,7 @@ interface ExtensionOperations< @patch(#{ implicitOptionality: false }) CustomPatchSync< Resource extends Foundations.SimpleResource, - PatchModel extends {} = Azure.ResourceManager.Foundations.TagsUpdateModel, + PatchModel extends {} | void = Azure.ResourceManager.Foundations.TagsUpdateModel, Parameters extends {} = {}, Response extends {} = ArmResponse, OptionalRequestBody extends valueof boolean = false, @@ -261,6 +265,27 @@ interface ExtensionOperations< OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false } >(...TargetParameters, ...ExtensionParentParameters, ...Parameters): Response | ErrorType; + /** + * List a resource, without pagination + * @template Resource The resource being listed + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The response returned by the list + * @template ErrorType Optional. The error response, if non-standard. + * @template OperationOptions Optional. The route options for the operation. + */ + @armOperationRoute(OperationOptions) + @doc("List a {name}", Resource) + @get + @listsResource(Resource) + @armResourceList(Resource) + ListSinglePage< + Resource extends Foundations.SimpleResource, + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + ErrorType extends {} = ErrorResponse, + OperationOptions extends valueof ArmOperationOptions = #{ useStaticRoute: false } + >(...TargetParameters, ...ExtensionParentParameters, ...Parameters): Response | ErrorType; + /** * A synchronous resource action. * @template Resource The resource being acted upon @@ -279,7 +304,7 @@ interface ExtensionOperations< @returnsDoc("Azure operation completed successfully.") ActionSync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, + Request, Response extends TypeSpec.Reflection.Model | void, Parameters extends {} = {}, OptionalRequestBody extends valueof boolean = false, @@ -316,7 +341,7 @@ interface ExtensionOperations< @returnsDoc("Azure operation completed successfully.") ActionAsync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, + Request, Result extends TypeSpec.Reflection.Model | void, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/interfaces.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/interfaces.tsp similarity index 100% rename from packages/typespec-azure-resource-manager/lib/Legacy/interfaces.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/interfaces.tsp diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/decorator.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/legacy.decorators.tsp similarity index 64% rename from packages/typespec-azure-resource-manager/lib/Legacy/decorator.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/legacy.decorators.tsp index 58bc68a2fe..1aefbe526f 100644 --- a/packages/typespec-azure-resource-manager/lib/Legacy/decorator.tsp +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/legacy.decorators.tsp @@ -12,11 +12,19 @@ model ArmOperationOptions { /** The status route for operations to use */ route?: string; } + +/** Options for customizing the behavior of a custom azure resource */ +model CustomResourceOptions { + /** Should the resource be marked as an Azure resource */ + isAzureResource?: boolean; +} + /** * This decorator is used on resources that do not satisfy the definition of a resource * but need to be identified as such. + * @param options Options for customizing the behavior of the resource */ -extern dec customAzureResource(target: Model); +extern dec customAzureResource(target: Model, options?: valueof CustomResourceOptions); /** * Specify an external reference that should be used when emitting this type. @@ -31,3 +39,9 @@ extern dec externalTypeRef(entity: Model | ModelProperty, jsonRef: valueof strin * @param route Optional route to associate with the operation */ extern dec armOperationRoute(target: Operation, route?: valueof ArmOperationOptions); + +/** + * Signifies that a Resource is represented using a library type in generated SDKs. + * @param target The model to that is an external resource + */ +extern dec armExternalType(target: Model); diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/managed-identity.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/managed-identity.tsp similarity index 100% rename from packages/typespec-azure-resource-manager/lib/Legacy/managed-identity.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/managed-identity.tsp diff --git a/packages/typespec-azure-resource-manager/lib/Legacy/operations.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/operations.tsp similarity index 78% rename from packages/typespec-azure-resource-manager/lib/Legacy/operations.tsp rename to packages/typespec-azure-resource-manager/lib/legacy-types/operations.tsp index b6a74b6a37..2cba9aceb2 100644 --- a/packages/typespec-azure-resource-manager/lib/Legacy/operations.tsp +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/operations.tsp @@ -45,6 +45,7 @@ interface RoutedOperations< * @template OptionalRequestBody Optional. Indicates whether the request body is optional * @template OverrideErrorType Optional. The error response, if non-standard. * @template OverrideRouteOptions Optional. The route options for the operation. + * @template Request Optional. The request body for the createOrUpdate operation. */ @doc("Create a {name}", Resource) @armOperationRoute(OverrideRouteOptions) @@ -63,12 +64,13 @@ interface RoutedOperations< >, OptionalRequestBody extends valueof boolean = false, OverrideErrorType extends {} = ErrorType, - OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute + OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute, + Request extends {} | void = Resource >( ...ParentParameters, ...ResourceTypeParameter, ...Parameters, - @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Resource, + @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Request, ): Response | OverrideErrorType; /** @@ -79,6 +81,7 @@ interface RoutedOperations< * @template OptionalRequestBody Optional. Indicates whether the request body is optional * @template OverrideErrorType Optional. The error response, if non-standard. * @template OverrideRouteOptions Optional. The route options for the operation. + * @template Request Optional. The request body for the createOrUpdate operation. */ #suppress "@azure-tools/typespec-azure-core/no-private-usage" @armOperationRoute(OverrideRouteOptions) @@ -92,12 +95,13 @@ interface RoutedOperations< Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedSyncResponse, OptionalRequestBody extends valueof boolean = false, OverrideErrorType extends {} = ErrorType, - OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute + OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute, + Request extends {} | void = Resource >( ...ParentParameters, ...ResourceTypeParameter, ...Parameters, - @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Resource, + @doc("Resource create parameters.") @armBodyRoot(OptionalRequestBody) resource: Request, ): Response | OverrideErrorType; /** @@ -118,7 +122,7 @@ interface RoutedOperations< @patch(#{ implicitOptionality: false }) CustomPatchAsync< Resource extends Foundations.SimpleResource, - PatchModel extends {} = Azure.ResourceManager.Foundations.TagsUpdateModel, + PatchModel extends {} | void = Azure.ResourceManager.Foundations.TagsUpdateModel, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, Resource, @@ -157,7 +161,7 @@ interface RoutedOperations< @patch(#{ implicitOptionality: false }) CustomPatchSync< Resource extends Foundations.SimpleResource, - PatchModel extends {} = Azure.ResourceManager.Foundations.TagsUpdateModel, + PatchModel extends {} | void = Azure.ResourceManager.Foundations.TagsUpdateModel, Parameters extends {} = {}, Response extends {} = ArmResponse, OptionalRequestBody extends valueof boolean = false, @@ -289,6 +293,29 @@ interface RoutedOperations< OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute >(...ParentParameters, ...Parameters): Response | OverrideErrorType; + /** + * List a single page of the resource + * @template Resource The resource being listed + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The response returned by the list + * @template OverrideErrorType Optional. The error response, if non-standard. + * @template OverrideRouteOptions Optional. The route options for the operation. + */ + @segmentOf(ResourceTypeParameter) + @doc("List a {name}", Resource) + @get + @listsResource(Resource) + @armOperationRoute(OverrideRouteOptions) + @armResourceList(Resource) + @Private.armUpdateProviderNamespace + ListSinglePage< + Resource extends Foundations.SimpleResource, + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + OverrideErrorType extends {} = ErrorType, + OverrideRouteOptions extends valueof ArmOperationOptions = ResourceRoute + >(...ParentParameters, ...Parameters): Response | OverrideErrorType; + /** * A synchronous resource action. * @template Resource The resource being acted upon @@ -308,8 +335,8 @@ interface RoutedOperations< @returnsDoc("Azure operation completed successfully.") ActionSync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, - Response extends TypeSpec.Reflection.Model | void, + Request, + Response, Parameters extends {} = {}, OptionalRequestBody extends valueof boolean = false, OverrideErrorType extends {} = ErrorType, @@ -346,7 +373,7 @@ interface RoutedOperations< @returnsDoc("Azure operation completed successfully.") ActionAsync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, + Request, Result extends TypeSpec.Reflection.Model | void, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, @@ -460,6 +487,42 @@ op CustomPatchSync< OptionalRequestBody >; +/** + * DEPRECATED: use CreateOrReplaceAsync instead. + * A long-running resource CreateOrUpdate (PUT) + * @template Resource the resource being created or updated + * @template Request The request body for the operation + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned on resource create + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional + */ +alias CreateOrUpdateAsync< + Resource extends Foundations.SimpleResource, + Request extends {} | void = Resource, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmAsyncOperationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedResponse< + Resource, + LroHeaders + >, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false +> = CreateOrReplaceAsync< + Resource, + Request, + BaseParameters, + LroHeaders, + Parameters, + Response, + Error, + OptionalRequestBody +>; + /** * A long-running resource CreateOrUpdate (PUT) * @template Resource the resource being created or updated @@ -477,7 +540,7 @@ op CustomPatchSync< @Private.enforceConstraint(Resource, Foundations.Resource) @Azure.Core.Foundations.Private.defaultFinalStateVia(#["location", "azure-async-operation"]) @put -op CreateOrUpdateAsync< +op CreateOrReplaceAsync< Resource extends Foundations.SimpleResource, Request extends {} | void = Resource, BaseParameters = DefaultBaseParameters, @@ -498,6 +561,35 @@ op CreateOrUpdateAsync< OptionalRequestBody >; +/** + * DEPRECATED: use CreateOrReplaceSync instead. + * Synchronous PUT operation for Azure Resource Manager resources + * @template Resource the resource being created or replaced + * @template Request The request body for the operation + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional + */ +alias CreateOrUpdateSync< + Resource extends Foundations.SimpleResource, + Request extends {} | void = Resource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedSyncResponse, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false +> = CreateOrReplaceSync< + Resource, + Request, + BaseParameters, + Parameters, + Response, + Error, + OptionalRequestBody +>; + /** * Synchronous PUT operation for Azure Resource Manager resources * @template Resource the resource being created or replaced @@ -513,7 +605,7 @@ op CreateOrUpdateAsync< @armResourceCreateOrUpdate(Resource) @Private.enforceConstraint(Resource, Foundations.Resource) @put -op CreateOrUpdateSync< +op CreateOrReplaceSync< Resource extends Foundations.SimpleResource, Request extends {} | void = Resource, BaseParameters = DefaultBaseParameters, @@ -529,12 +621,65 @@ op CreateOrUpdateSync< OptionalRequestBody >; +/** + * A resource list operation, at the subscription scope, that lists only a single page + * @template Resource the resource being patched + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the list operation + * @template Error Optional. The error response, if non-standard. + */ +@autoRoute +@doc("List {name} resources by subscription ID", Resource) +@listsResource(Resource) +@segmentOf(Resource) +@armResourceList(Resource) +@get +@Private.enforceConstraint(Resource, Foundations.Resource) +op ArmListSinglePageBySubscription< + Resource extends Foundations.SimpleResource, + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + Error extends {} = ErrorResponse +> is ArmReadOperation & Parameters, Response, Error>; + +/** + * A resource list operation, at the scope of the resource's parent that lists only a single page. + * @template Resource the resource being patched + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template ParentName Optional. The name of the parent resource + * @template ParentFriendlyName Optional. The friendly name of the parent resource + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the list operation + * @template Error Optional. The error response, if non-standard. + */ +@get +@autoRoute +@listsResource(Resource) +@segmentOf(Resource) +@Private.armRenameListByOperation(Resource, ParentName, ParentFriendlyName, false) // This must come before @armResourceList! +@armResourceList(Resource) +@Private.enforceConstraint(Resource, Foundations.Resource) +op ArmListSinglePageByParent< + Resource extends Foundations.SimpleResource, + BaseParameters = DefaultBaseParameters, + ParentName extends valueof string = "", + ParentFriendlyName extends valueof string = "", + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + Error extends {} = ErrorResponse +> is ArmReadOperation< + ResourceParentParameters & Parameters, + Response, + Error +>; + /** * @dev The base template for Azure Resource Manager PUT Operations. * @template HttpParameters The parameter object for the operation. * @template BodyParameter The body parameter * @template Response The response or union of responses for success. * @template ErrorResponse The error response. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional */ op CreateOperation< HttpParameters extends {}, diff --git a/packages/typespec-azure-resource-manager/lib/legacy-types/private-endpoints.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/private-endpoints.tsp new file mode 100644 index 0000000000..5681219166 --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/private-endpoints.tsp @@ -0,0 +1,196 @@ +import "@typespec/rest"; +import "@typespec/http"; + +namespace Azure.ResourceManager.Legacy.PrivateEndpoints; + +using Http; +using Azure.ResourceManager.Foundations; +using Rest; + +/** + * @dev List the private endpoint connections over a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource Optional. The PrivateEndpointConnection resource being listed + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template ParentName Optional. The name of the parent resource + * @template ParentFriendlyName Optional. The friendly name of the parent resource + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the list operation + * @template Error Optional. The error response, if non-standard. + */ +@doc("List {name} PrivateEndpointConnections", ParentResource) +@get +@autoRoute +@listsResource(Resource) +@segmentOf(PrivateEndpointConnectionParameter) +@armResourceList(Resource) +@Private.enforceConstraint(ParentResource, Foundations.Resource) +op ListSinglePageByParent< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + Error extends {} = ErrorResponse +> is ArmReadOperation< + ResourceInstanceParameters & Parameters, + Response, + Error +>; + +/** + * @dev Synchronous PUT operation for a Private endpoint connection to a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being created or updated + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional. + * @template Request Optional. The request body for the operation. + */ +@autoRoute +@doc("Create a {name} PrivateEndpointConnection", ParentResource) +@armResourceCreateOrUpdate(Resource) +@Private.enforceConstraint(ParentResource, Foundations.Resource) +@put +op CreateOrReplaceSync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedSyncResponse, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false, + Request extends {} | void = Resource +> is Azure.ResourceManager.Legacy.CreateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + Request, + Response, + Error, + OptionalRequestBody +>; + +/** + * @dev A long-running resource CreateOrUpdate (PUT) for a PrivateEndpointConnection to a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being created or updated + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned on resource create + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrReplace operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional. + * @template Request Optional. The request body for the operation. + */ +@autoRoute +@doc("Create a {name} PrivateEndpointConnection", ParentResource) +@armResourceCreateOrUpdate(Resource) +@Private.enforceConstraint(ParentResource, Foundations.Resource) +@Azure.Core.Foundations.Private.defaultFinalStateVia(#["location", "azure-async-operation"]) +@put +op CreateOrReplaceAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmAsyncOperationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedResponse< + Resource, + LroHeaders + >, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false, + Request extends {} | void = Resource +> is Azure.ResourceManager.Legacy.CreateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + Request, + Response, + Error, + OptionalRequestBody +>; + +/** + * A long-running resource update using a custom PATCH payload (Asynchronous) to update a PrivateEndpointConnection to a resource. + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being updated + * @template PatchModel The input model for the PATCH request + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned in the Accepted response + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the patch operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional. + */ +@autoRoute +@doc("Update a {name} PrivateEndpointConnection", ParentResource) +@armResourceUpdate(Resource) +@Private.enforceConstraint(ParentResource, Foundations.Resource) +@patch(#{ implicitOptionality: false }) +op CustomPatchAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource, + PatchModel extends {} | void = PrivateEndpointConnectionUpdate, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< + Azure.Core.StatusMonitorPollingOptions, + Resource, + string + > & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResponse | ArmAcceptedLroResponse< + "Resource update request accepted.", + LroHeaders + >, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false +> is Azure.ResourceManager.Legacy.UpdateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + PatchModel, + Response, + Error, + OptionalRequestBody +>; + +/** + * @dev A resource update using a custom PATCH payload (synchronous) to update a PrivateEndpointConnection to a resource + * @template ParentResource The parent resource of the PrivateEndpointConnection + * @template Resource Optional. The PrivateEndpointConnection resource being patched + * @template PatchModel The input model for the PATCH request + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the patch operation + * @template Error Optional. The error response, if non-standard. + * @template OptionalRequestBody Optional. Indicates whether the request body is optional. + */ +@autoRoute +@doc("Update a {name PrivateEndpointConnection}", ParentResource) +@armResourceUpdate(Resource) +@Private.enforceConstraint(ParentResource, Foundations.Resource) +@patch(#{ implicitOptionality: false }) +op CustomPatchSync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource, + PatchModel extends {} | void = PrivateEndpointConnectionUpdate, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResponse, + Error extends {} = ErrorResponse, + OptionalRequestBody extends valueof boolean = false +> is Azure.ResourceManager.Legacy.UpdateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + PatchModel, + Response, + Error, + OptionalRequestBody +>; diff --git a/packages/typespec-azure-resource-manager/lib/legacy-types/resource.tsp b/packages/typespec-azure-resource-manager/lib/legacy-types/resource.tsp new file mode 100644 index 0000000000..8f96b0197e --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/legacy-types/resource.tsp @@ -0,0 +1,92 @@ +import "@typespec/rest"; +import "@typespec/http"; + +namespace Azure.ResourceManager.Legacy; + +using Azure.ResourceManager.Private; + +/** + * This type uses an optional location property, only used by legacy APIs. + * Concrete tracked resource types can be created by aliasing this type using a specific property type. + * + * See more details on [different Azure Resource Manager resource type here.](https://azure.github.io/typespec-azure/docs/howtos/ARM/resource-type) + * @template Properties A model containing the provider-specific properties for this resource + * @template PropertiesOptional A boolean flag indicating whether the resource `Properties` field is marked as optional or required. Default true is optional and recommended. + * + * @example + * ```typespec + * model Employee is TrackedResourceWithOptionalLocation { + * ...ResourceNameParameter + * } + * ``` + */ +@doc("Concrete tracked resource types can be created by aliasing this type using a specific property type.") +@armResourceInternal(Properties) +@Http.Private.includeInapplicableMetadataInPayload(false) +model TrackedResourceWithOptionalLocation< + Properties extends {}, + PropertiesOptional extends valueof boolean = true +> extends LegacyTrackedResource { + @doc("The resource-specific properties for this resource.") + @conditionalClientFlatten + @armResourcePropertiesOptionality(PropertiesOptional) + properties?: Properties; +} + +/** + * A tracked resource with the 'location' property optional + */ +@friendlyName("TrackedResource") +model LegacyTrackedResource extends CommonTypes.Resource { + /** Resource tags. */ + tags?: Record; + + /** The geo-location where the resource lives */ + @visibility(Lifecycle.Read, Lifecycle.Create) + location?: string; +} + +/** + * Model used only to spread in the standard `etag` envelope property for a resource + * + * @example + * + * ```typespec + * model Foo is TrackedResource { + * // Only have standard Succeeded, Failed, Cancelled states + * ...ETagProperty; + * } + * ``` + */ +alias EntityTagProperty = { + /** "If etag is provided in the response body, it may also be provided as a header per the normal etag convention. Entity tags are used for comparing two or more entities from the same requested resource. HTTP/1.1 uses entity tags in the etag (section 14.19), If-Match (section 14.24), If-None-Match (section 14.26), and If-Range (section 14.27) header fields.") */ + @visibility(Lifecycle.Read) + etag?: string; +}; + +/** + * Legacy. Model representing a non-standard `extendedLocation` envelope property with all properties optional. + * Spread this model into a Resource Model, if you are converting a BrownField API with extended location that has optional properties + * + * @example + * ```typespec + * model Employee is TrackedResource { + * ...ResourceNameParameter; + * ...ExtendedLocationOptionalProperty; + * } + * ``` + */ +model ExtendedLocationOptionalProperty { + @visibility(Lifecycle.Read, Lifecycle.Create) + extendedLocation?: ExtendedLocationOptional; +} + +/** The complex type of the extended location. */ +@friendlyName("ExtendedLocation") +model ExtendedLocationOptional { + /** The name of the extended location. */ + name?: string; + + /** The type of the extended location. */ + type?: Azure.ResourceManager.Foundations.ExtendedLocationType; +} diff --git a/packages/typespec-azure-resource-manager/lib/operations.tsp b/packages/typespec-azure-resource-manager/lib/operations.tsp index 64e5eb0253..e49c9ca3cd 100644 --- a/packages/typespec-azure-resource-manager/lib/operations.tsp +++ b/packages/typespec-azure-resource-manager/lib/operations.tsp @@ -495,8 +495,8 @@ op ArmResourceDeleteSync< @post op ArmResourceActionAsyncBase< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, - Response extends TypeSpec.Reflection.Model | void, + Request, + Response extends {} | void, BaseParameters extends TypeSpec.Reflection.Model, Parameters extends {} = {}, Error extends {} = ErrorResponse, @@ -525,8 +525,8 @@ op ArmResourceActionAsyncBase< @Private.enforceConstraint(Resource, Foundations.Resource) op ArmResourceActionAsync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, - Response extends TypeSpec.Reflection.Model | void, + Request, + Response extends {} | void, BaseParameters extends TypeSpec.Reflection.Model = DefaultBaseParameters, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, @@ -564,8 +564,8 @@ op ArmResourceActionAsync< @returnsDoc("Azure operation completed successfully.") op ArmResourceActionSync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, - Response extends TypeSpec.Reflection.Model | void, + Request, + Response, BaseParameters = DefaultBaseParameters, Parameters extends {} = {}, Error extends {} = ErrorResponse, @@ -625,7 +625,7 @@ op ArmResourceActionNoContentAsync< @Private.enforceConstraint(Resource, Foundations.Resource) op ArmResourceActionNoResponseContentAsync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, + Request, BaseParameters extends TypeSpec.Reflection.Model = DefaultBaseParameters, LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< Azure.Core.StatusMonitorPollingOptions, @@ -661,7 +661,7 @@ op ArmResourceActionNoResponseContentAsync< @post op ArmResourceActionNoContentSync< Resource extends Foundations.SimpleResource, - Request extends TypeSpec.Reflection.Model | void, + Request, BaseParameters = DefaultBaseParameters, Parameters extends {} = {}, Error extends {} = ErrorResponse, diff --git a/packages/typespec-azure-resource-manager/lib/private-endpoints.tsp b/packages/typespec-azure-resource-manager/lib/private-endpoints.tsp new file mode 100644 index 0000000000..8d627f0cff --- /dev/null +++ b/packages/typespec-azure-resource-manager/lib/private-endpoints.tsp @@ -0,0 +1,379 @@ +using Http; +using Rest; +using Azure.ResourceManager.Foundations; +using Azure.ResourceManager.Private; + +namespace Azure.ResourceManager; + +/** + * A private endpoint connection resource. + * Resource providers must declare a private endpoint connection resource type in their provider namespace if + * they support private endpoint connections + * @template Description Optional. The documentary description of the private endpoint connection resource name parameter. + * + * @example + * ```ts + * namespace Microsoft.Contoso; + * model PrivateEndpointConnection is PrivateEndpointConnectionResource {} + * alias EmployeeConnectionOps is PrivateEndpoints; + * @armResourceOperations + * interface Employees { + * @doc("get a private endpoint connection for resource employee") + * getPrivateEndpointConnection is EmployeeConnectionOps.Read; + * } + * ``` + */ +@doc(Description) +@armResourceWithParameter( + CommonTypes.PrivateEndpointConnectionProperties, + "privateEndpointConnections", + "privateEndpointConnectionName" +) +@Http.Private.includeInapplicableMetadataInPayload(false) +model PrivateEndpointConnectionResource + is CommonTypes.PrivateEndpointConnection; + +/** + * Operations over private endpoint connection resources. + * @template PrivateEndpointResource The type of the private endpoint connection resource. You must declare a private endpoint connection resource type in your provider namespace. + * + * @example + * ```ts + * namespace Microsoft.Contoso; + * model PrivateEndpointConnection is PrivateEndpointConnectionResource {} + * alias EmployeeConnectionOps is PrivateEndpoints; + * @armResourceOperations + * interface Employees { + * @doc("get a private endpoint connection for resource employee") + * getPrivateEndpointConnection is EmployeeConnectionOps.Read; + * } + * ``` + */ +interface PrivateEndpoints { + /** + * @dev List the private endpoint connections over a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource Optional. The PrivateEndpointConnection resource being listed + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template ParentName Optional. The name of the parent resource + * @template ParentFriendlyName Optional. The friendly name of the parent resource + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the list operation + * @template Error Optional. The error response, if non-standard. + */ + @doc("List {name} PrivateEndpointConnections", ParentResource) + @get + @autoRoute + @list + @listsResource(Resource) + @segmentOf(PrivateEndpointConnectionParameter) + @armResourceList(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + ListByParent< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResponse>, + Error extends {} = ErrorResponse + > is ArmReadOperation< + ResourceInstanceParameters & Parameters, + Response, + Error + >; + + /** + * @dev GET the a private endpoint connection for a particular resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being read + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the read operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Get a {name} PrivateEndpointConnection", ParentResource) + @get + @armResourceRead(Resource) + Read< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResponse, + Error extends {} = ErrorResponse + > is ArmReadOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + Response, + Error + >; + + /** + * @dev A long-running resource CreateOrUpdate (PUT) for a PrivateEndpointConnection to a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being created or updated + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned on resource create + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Create a {name} PrivateEndpointConnection", ParentResource) + @armResourceCreateOrUpdate(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @Azure.Core.Foundations.Private.defaultFinalStateVia(#["location", "azure-async-operation"]) + @put + CreateOrUpdateAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmAsyncOperationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedResponse< + Resource, + LroHeaders + >, + Error extends {} = ErrorResponse + > is ArmCreateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + Resource, + Response, + Error + >; + + /** + * @dev Synchronous PUT operation for a Private endpoint connection to a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being created or updated + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrUpdate operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Create a {name} PrivateEndpointConnection", ParentResource) + @armResourceCreateOrUpdate(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @put + CreateOrReplaceSync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedSyncResponse, + Error extends {} = ErrorResponse + > is ArmCreateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + Resource, + Response, + Error + >; + + /** + * @dev A long-running resource CreateOrUpdate (PUT) for a PrivateEndpointConnection to a resource + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being created or updated + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned on resource create + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the createOrReplace operation + * @template Error Optional. The error response, if non-standard. + */ + @Private.enforceConstraint(ParentResource, Foundations.Resource) + CreateOrReplaceAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmAsyncOperationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResourceUpdatedResponse | ArmResourceCreatedResponse< + Resource, + LroHeaders + >, + Error extends {} = ErrorResponse + > is PrivateEndpoints.CreateOrUpdateAsync< + ParentResource, + Resource, + BaseParameters, + LroHeaders, + Parameters, + Response, + Error + >; + + /** + * A long-running resource update using a custom PATCH payload (Asynchronous) to update a PrivateEndpointConnection to a resource. + * @template ParentResource the parent resource of the PrivateEndpointConnection + * @template Resource the PrivateEndpointConnection resource being updated + * @template PatchModel The input model for the PATCH request + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template LroHeaders Optional. Allows overriding the lro headers returned in the Accepted response + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the patch operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Update a {name} PrivateEndpointConnection", ParentResource) + @armResourceUpdate(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @patch(#{ implicitOptionality: false }) + CustomPatchAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + PatchModel extends TypeSpec.Reflection.Model = PrivateEndpointConnectionUpdate, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader< + Azure.Core.StatusMonitorPollingOptions, + Resource, + string + > & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmResponse | ArmAcceptedLroResponse< + "Resource update request accepted.", + LroHeaders + >, + Error extends {} = ErrorResponse + > is ArmUpdateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + PatchModel, + Response, + Error + >; + + /** + * @dev A resource update using a custom PATCH payload (synchronous) to update a PrivateEndpointConnection to a resource + * @template ParentResource The parent resource of the PrivateEndpointConnection + * @template Resource Optional. The PrivateEndpointConnection resource being patched + * @template PatchModel The input model for the PATCH request + * @template BaseParameters Optional. Allows overriding the operation parameters + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response for the patch operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Update a {name PrivateEndpointConnection}", ParentResource) + @armResourceUpdate(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @patch(#{ implicitOptionality: false }) + CustomPatchSync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + PatchModel extends TypeSpec.Reflection.Model = PrivateEndpointConnectionUpdate, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmResponse, + Error extends {} = ErrorResponse + > is ArmUpdateOperation< + ResourceInstanceParameters & + KeysOf & + Parameters, + PatchModel, + Response, + Error + >; + + /** + * @dev Delete a PrivateEndpointConnection to a resource asynchronously + * @template ParentResource The parent resource of the PrivateEndpointConnection + * @template Resource Optional. The PrivateEndpointConnection resource being deleted + * @template BaseParameters Optional. Allows overriding the parameters for the operation + * @template LroHeaders Optional. Allows overriding the headers returned in the Accepted response + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response(s) for the delete operation + * @template Error Optional. The error response, if non-standard. + */ + @Private.enforceConstraint(ParentResource, Foundations.Resource) + DeleteAsync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + LroHeaders extends TypeSpec.Reflection.Model = ArmLroLocationHeader & + Azure.Core.Foundations.RetryAfterHeader, + Parameters extends {} = {}, + Response extends {} = ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse, + Error extends {} = ErrorResponse + > is PrivateEndpoints.DeleteAsyncBase< + ParentResource, + Response, + Resource, + BaseParameters, + Parameters, + Error + >; + + /** + * @dev Delete a PrivateEndpointConnection to a resource synchronously + * @template ParentResource The parent resource of the PrivateEndpointConnection + * @template Resource The PrivateEndpointConnection resource being deleted + * @template BaseParameters Optional. Allows overriding the parameters for the operation + * @template Parameters Optional. Additional parameters after the path parameters + * @template Response Optional. The success response(s) for the delete operation + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Delete a {name} PrivateEndpointConnection", ParentResource) + @armResourceDelete(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @delete + DeleteSync< + ParentResource extends Foundations.SimpleResource, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Response extends {} = ArmDeletedResponse | ArmDeletedNoContentResponse, + Error = ErrorResponse + >( + ...ResourceInstanceParameters, + ...KeysOf, + ...Parameters, + ): Response | Error; + + /** + * @dev Delete a PrivateEndpointConnection to a resource asynchronously + * @template ParentResource The parent resource of the PrivateEndpointConnection + * @template Response The response type for the operation + * @template Resource Optional. The PrivateEndpointConnection resource being deleted + * @template BaseParameters Optional. Allows overriding the parameters for the operation + * @template Parameters Optional. Additional parameters after the path parameters + * @template Error Optional. The error response, if non-standard. + */ + @autoRoute + @doc("Delete a {name} PrivateEndpointConnection", ParentResource) + @armResourceDelete(Resource) + @Private.enforceConstraint(ParentResource, Foundations.Resource) + @delete + DeleteAsyncBase< + ParentResource extends Foundations.SimpleResource, + Response, + Resource extends PrivateEndpointConnectionResource = PrivateEndpointResource, + BaseParameters = DefaultBaseParameters, + Parameters extends {} = {}, + Error extends {} = ErrorResponse + >( + ...ResourceInstanceParameters, + ...KeysOf, + ...Parameters, + ): Response | Error; +} + +/** PATCH model for private endpoint connections */ +model PrivateEndpointConnectionUpdate + is OptionalProperties>> { + /** The private endpoint connection properties */ + properties?: OptionalProperties>; +} diff --git a/packages/typespec-azure-resource-manager/lib/private.decorators.tsp b/packages/typespec-azure-resource-manager/lib/private.decorators.tsp index c15f3297ff..04b1041c27 100644 --- a/packages/typespec-azure-resource-manager/lib/private.decorators.tsp +++ b/packages/typespec-azure-resource-manager/lib/private.decorators.tsp @@ -34,6 +34,21 @@ extern dec assignUniqueProviderNameValue(target: ModelProperty, resource: Model) */ extern dec armResourceInternal(target: Model, properties: Model); +/** + * This decorator identifies Azure Resource Manager resource types that do not define + * the name identifier parameter and type + * @param target Azure Resource Manager resource type + * @param properties Azure Resource Manager resource properties + * @param type The resource type name, e.g. "virtualMachines" + * @param nameParameter The name of the resource name parameter, e.g. "virtualMachineName" + */ +extern dec armResourceWithParameter( + target: Model, + properties: Model, + type: valueof string, + nameParameter: valueof string +); + /** * Omit a property in the target model. * @internal diff --git a/packages/typespec-azure-resource-manager/package.json b/packages/typespec-azure-resource-manager/package.json index c05c000515..f0e87e2f6b 100644 --- a/packages/typespec-azure-resource-manager/package.json +++ b/packages/typespec-azure-resource-manager/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-azure-resource-manager", - "version": "0.59.0", + "version": "0.59.2", "author": "Microsoft Corporation", "description": "TypeSpec Azure Resource Manager library", "homepage": "https://azure.github.io/typespec-azure", diff --git a/packages/typespec-azure-resource-manager/src/common-types.ts b/packages/typespec-azure-resource-manager/src/common-types.ts index f73adc939b..eee03abbbb 100644 --- a/packages/typespec-azure-resource-manager/src/common-types.ts +++ b/packages/typespec-azure-resource-manager/src/common-types.ts @@ -122,7 +122,7 @@ export const $armCommonTypesVersion: ArmCommonTypesVersionDecorator = ( /** * Returns the ARM common-types version used by the service. - * @param {DecoratorContext} context DecoratorContext object + * @param {Program} program Program object * @param {type} entity Target of the decorator. Must be `Namespace` or `EnumMember` type */ export function getArmCommonTypesVersion( diff --git a/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts b/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts index afd24eade6..22a29c9fb0 100644 --- a/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts +++ b/packages/typespec-azure-resource-manager/src/commontypes.private.decorators.ts @@ -7,10 +7,12 @@ import { Program, Union, } from "@typespec/compiler"; +import { useStateMap } from "@typespec/compiler/utils"; import { ArmCommonDefinitionDecorator, ArmCommonParameterDecorator, ArmCommonTypesVersionsDecorator, + InlineAzureTypeDecorator, } from "../generated-defs/Azure.ResourceManager.CommonTypes.Private.js"; import { ArmStateKeys } from "./state.js"; @@ -148,3 +150,14 @@ export const $armCommonTypesVersions: ArmCommonTypesVersionsDecorator = ( allVersions: Array.from(enumType.members.values()).reverse(), }); }; + +export const [getInlineAzureType, setInlineAzureType] = useStateMap( + ArmStateKeys.inlineAzureType, +); + +export const $inlineAzureType: InlineAzureTypeDecorator = ( + context: DecoratorContext, + entity: ModelProperty, +) => { + setInlineAzureType(context.program, entity, true); +}; diff --git a/packages/typespec-azure-resource-manager/src/index.ts b/packages/typespec-azure-resource-manager/src/index.ts index 86865bc395..df3308e4f3 100644 --- a/packages/typespec-azure-resource-manager/src/index.ts +++ b/packages/typespec-azure-resource-manager/src/index.ts @@ -18,6 +18,7 @@ export * from "./resource.js"; export { $lib } from "./lib.js"; export { $linter } from "./linter.js"; +export { getInlineAzureType } from "./commontypes.private.decorators.js"; export { isAzureResource, isConditionallyFlattened } from "./private.decorators.js"; /** @internal */ diff --git a/packages/typespec-azure-resource-manager/src/namespace.ts b/packages/typespec-azure-resource-manager/src/namespace.ts index 8f73a4ece1..2b81f09176 100644 --- a/packages/typespec-azure-resource-manager/src/namespace.ts +++ b/packages/typespec-azure-resource-manager/src/namespace.ts @@ -26,10 +26,7 @@ import { reportDiagnostic } from "./lib.js"; import { getArmVirtualResourceDetails, getSingletonResourceKey } from "./resource.js"; import { ArmStateKeys } from "./state.js"; -function getArmCommonTypesVersion( - context: DecoratorContext, - entity: Namespace | EnumMember, -): EnumValue | undefined { +function getArmCommonTypesVersion(entity: Namespace | EnumMember): EnumValue | undefined { return entity.decorators.find((x) => x.definition?.name === "@armCommonTypesVersion")?.args[0] .jsValue as EnumValue | undefined; } @@ -169,7 +166,7 @@ export const $armProviderNamespace: ArmProviderNamespaceDecorator = ( } } - const armCommonTypesVersion = getArmCommonTypesVersion(context, entity); + const armCommonTypesVersion = getArmCommonTypesVersion(entity); // If it is versioned namespace, we will check each Version enum member. If no // @armCommonTypeVersion decorator, add the one @@ -177,7 +174,7 @@ export const $armProviderNamespace: ArmProviderNamespaceDecorator = ( if (versioned) { const versionEnum = versioned.args[0].value as Enum; versionEnum.members.forEach((v) => { - if (!getArmCommonTypesVersion(context, v)) { + if (!getArmCommonTypesVersion(v)) { context.call($armCommonTypesVersion, v, armCommonTypesVersion ?? "v3"); } }); diff --git a/packages/typespec-azure-resource-manager/src/private.decorators.ts b/packages/typespec-azure-resource-manager/src/private.decorators.ts index 061b65499e..3496297acd 100644 --- a/packages/typespec-azure-resource-manager/src/private.decorators.ts +++ b/packages/typespec-azure-resource-manager/src/private.decorators.ts @@ -34,6 +34,7 @@ import { ArmRenameListByOperationDecorator, ArmResourceInternalDecorator, ArmResourcePropertiesOptionalityDecorator, + ArmResourceWithParameterDecorator, ArmUpdateProviderNamespaceDecorator, AssignProviderNameValueDecorator, AssignUniqueProviderNameValueDecorator, @@ -51,6 +52,7 @@ import { getArmProviderNamespace, isArmLibraryNamespace } from "./namespace.js"; import { armRenameListByOperationInternal } from "./operations.js"; import { ArmResourceDetails, + ArmResourceKind, ResourceBaseType, getArmResourceKind, getArmVirtualResourceDetails, @@ -383,6 +385,15 @@ const $armResourceInternal: ArmResourceInternalDecorator = ( registerArmResource(context, resourceType); }; +const $armResourceWithParameter: ArmResourceWithParameterDecorator = ( + context: DecoratorContext, + target: Model, + properties: Model, + type: string, + nameParameter: string, +) => { + registerArmResource(context, target, type, nameParameter); +}; function getPrimaryKeyProperty(program: Program, resource: Model): ModelProperty | undefined { const nameProperty = resource.properties.get("name"); if (nameProperty !== undefined) return nameProperty; @@ -391,9 +402,19 @@ function getPrimaryKeyProperty(program: Program, resource: Model): ModelProperty return keyProps[0]; } -export function registerArmResource(context: DecoratorContext, resourceType: Model): void { +export function registerArmResource( + context: DecoratorContext, + resourceType: Model, + type?: string, + nameParameter?: string, +): void { const { program } = context; - if (resourceType.namespace && getTypeName(resourceType.namespace) === "Azure.ResourceManager") { + const namespaceName = resourceType.namespace ? getTypeName(resourceType.namespace) : undefined; + if ( + namespaceName === undefined || + namespaceName === "Azure.ResourceManager" || + namespaceName === "Azure.ResourceManager.Legacy" + ) { // The @armResource decorator will be evaluated on instantiations of // base templated resource types like TrackedResource, // so ignore in that case. @@ -419,43 +440,60 @@ export function registerArmResource(context: DecoratorContext, resourceType: Mod return; } - // Ensure the resource type has defined a name property that has a segment - const primaryKeyProperty = getPrimaryKeyProperty(program, resourceType); - if (!primaryKeyProperty) { - reportDiagnostic(program, { code: "arm-resource-missing-name-property", target: resourceType }); - return; - } + let keyName: string | undefined = undefined; + let collectionName: string | undefined = undefined; + let kind: ArmResourceKind | undefined = undefined; - // Set the name property to be read only - if (primaryKeyProperty.name === "name") { - const Lifecycle = getLifecycleVisibilityEnum(program); - clearVisibilityModifiersForClass(program, primaryKeyProperty, Lifecycle, context); - addVisibilityModifiers(program, primaryKeyProperty, [Lifecycle.members.get("Read")!], context); - sealVisibilityModifiers(program, primaryKeyProperty, Lifecycle); - } + if (type !== undefined && nameParameter !== undefined) { + keyName = nameParameter; + collectionName = type; + kind = "Proxy"; + } else { + // Ensure the resource type has defined a name property that has a segment + const primaryKeyProperty = getPrimaryKeyProperty(program, resourceType); + if (!primaryKeyProperty) { + reportDiagnostic(program, { + code: "arm-resource-missing-name-property", + target: resourceType, + }); + return; + } - const keyName = getKeyName(program, primaryKeyProperty); - if (!keyName) { - reportDiagnostic(program, { - code: "arm-resource-missing-name-key-decorator", - target: resourceType, - }); - return; - } + // Set the name property to be read only + if (primaryKeyProperty.name === "name") { + const Lifecycle = getLifecycleVisibilityEnum(program); + clearVisibilityModifiersForClass(program, primaryKeyProperty, Lifecycle, context); + addVisibilityModifiers( + program, + primaryKeyProperty, + [Lifecycle.members.get("Read")!], + context, + ); + sealVisibilityModifiers(program, primaryKeyProperty, Lifecycle); + } - const collectionName = getSegment(program, primaryKeyProperty); - if (!collectionName) { - reportDiagnostic(program, { - code: "arm-resource-missing-name-segment-decorator", - target: resourceType, - }); - return; - } + keyName = getKeyName(program, primaryKeyProperty); + if (!keyName) { + reportDiagnostic(program, { + code: "arm-resource-missing-name-key-decorator", + target: resourceType, + }); + return; + } - let kind = getArmResourceKind(resourceType); - if (isArmVirtualResource(program, resourceType)) kind = "Virtual"; - if (isCustomAzureResource(program, resourceType)) kind = "Custom"; + collectionName = getSegment(program, primaryKeyProperty); + if (!collectionName) { + reportDiagnostic(program, { + code: "arm-resource-missing-name-segment-decorator", + target: resourceType, + }); + return; + } + kind = getArmResourceKind(resourceType); + if (isArmVirtualResource(program, resourceType)) kind = "Virtual"; + if (isCustomAzureResource(program, resourceType)) kind = "Custom"; + } if (!kind) { reportDiagnostic(program, { code: "arm-resource-invalid-base-type", @@ -592,6 +630,7 @@ export const $decorators = { armRenameListByOperation: $armRenameListByOperation, armResourcePropertiesOptionality: $armResourcePropertiesOptionality, armBodyRoot: $armBodyRoot, + armResourceWithParameter: $armResourceWithParameter, } satisfies AzureResourceManagerPrivateDecorators, "Azure.ResourceManager.Extension.Private": { builtInResource: $builtInResource, diff --git a/packages/typespec-azure-resource-manager/src/resource.ts b/packages/typespec-azure-resource-manager/src/resource.ts index 3e72df28e0..3ab93e9e07 100644 --- a/packages/typespec-azure-resource-manager/src/resource.ts +++ b/packages/typespec-azure-resource-manager/src/resource.ts @@ -23,6 +23,7 @@ import { import { useStateMap } from "@typespec/compiler/utils"; import { getHttpOperation, isPathParam } from "@typespec/http"; import { $autoRoute, getParentResource, getSegment } from "@typespec/rest"; + import { ArmProviderNameValueDecorator, ArmResourceOperationsDecorator, @@ -37,7 +38,11 @@ import { SubscriptionResourceDecorator, TenantResourceDecorator, } from "../generated-defs/Azure.ResourceManager.js"; -import { CustomAzureResourceDecorator } from "../generated-defs/Azure.ResourceManager.Legacy.js"; +import { + ArmExternalTypeDecorator, + CustomAzureResourceDecorator, + CustomResourceOptions, +} from "../generated-defs/Azure.ResourceManager.Legacy.js"; import { reportDiagnostic } from "./lib.js"; import { getArmProviderNamespace, @@ -80,6 +85,19 @@ export interface ArmResourceDetailsBase { typespecType: Model; } +export const [isArmExternalType, setArmExternalType] = useStateMap( + ArmStateKeys.armExternalType, +); + +export const $armExternalType: ArmExternalTypeDecorator = ( + context: DecoratorContext, + entity: Model, +) => { + const { program } = context; + if (isTemplateDeclaration(entity)) return; + setArmExternalType(program, entity, true); +}; + /** Details for RP resources */ export interface ArmResourceDetails extends ArmResourceDetailsBase { /** The set of lifecycle operations and actions for the resource */ @@ -188,11 +206,12 @@ export const $armVirtualResource: ArmVirtualResourceDecorator = ( export const $customAzureResource: CustomAzureResourceDecorator = ( context: DecoratorContext, entity: Model, + options?: CustomResourceOptions, ) => { const { program } = context; + const optionsValue = options ?? { isAzureResource: false }; if (isTemplateDeclaration(entity)) return; - - program.stateMap(ArmStateKeys.customAzureResource).set(entity, "Custom"); + setCustomResource(program, entity, optionsValue); }; function getProperty( @@ -245,6 +264,12 @@ export function getArmVirtualResourceDetails( return undefined; } +const [getCustomResourceOptions, setCustomResource] = useStateMap( + ArmStateKeys.customAzureResource, +); + +export { getCustomResourceOptions }; + /** * Determine if the given model is a custom resource. * @param program The program to process. @@ -252,7 +277,8 @@ export function getArmVirtualResourceDetails( * @returns true if the model or any model it extends is marked as a resource, otherwise false. */ export function isCustomAzureResource(program: Program, target: Model): boolean { - if (program.stateMap(ArmStateKeys.customAzureResource).has(target)) return true; + const resourceOptions = getCustomResourceOptions(program, target); + if (resourceOptions) return true; if (target.baseModel) return isCustomAzureResource(program, target.baseModel); return false; } @@ -731,7 +757,10 @@ export function getArmResourceInfo( export function getArmResourceKind(resourceType: Model): ArmResourceKind | undefined { if (resourceType.baseModel) { const coreType = resourceType.baseModel; - if (coreType.name.startsWith("TrackedResource")) { + if ( + coreType.name.startsWith("TrackedResource") || + coreType.name.startsWith("LegacyTrackedResource") + ) { return "Tracked"; } else if (coreType.name.startsWith("ProxyResource")) { return "Proxy"; @@ -906,7 +935,7 @@ export const $identifiers: IdentifiersDecorator = ( }; /** - * This function returns identifiers using the @identifiers decorator + * This function returns identifiers using the '@identifiers' decorator * * @param program The program to process. * @param entity The array model type to check. @@ -917,7 +946,7 @@ export function getArmIdentifiers(program: Program, entity: ModelProperty): stri } /** - * This function returns identifiers using the @key decorator. + * This function returns identifiers using the '@key' decorator. * * @param program The program to process. * @param entity The array model type to check. diff --git a/packages/typespec-azure-resource-manager/src/rules/arm-resource-operation-response.ts b/packages/typespec-azure-resource-manager/src/rules/arm-resource-operation-response.ts index 5ad0bef677..e8ff0bce46 100644 --- a/packages/typespec-azure-resource-manager/src/rules/arm-resource-operation-response.ts +++ b/packages/typespec-azure-resource-manager/src/rules/arm-resource-operation-response.ts @@ -52,23 +52,27 @@ function checkArmResourceOperationReturnType( if (!isInternalTypeSpec(context.program, operation)) { const returnType = operation.returnType; if (returnType.kind === "Model") { - checkIfArmModel(context, operation, model, returnType); + throwIfNotMatchingArmModel(context, operation, model, returnType); } else if (returnType.kind === "Union") { for (const variant of returnType.variants.values()) { if (!isErrorType(variant.type) && variant.type.kind === "Model") { const modelCandidate = getEffectiveModelType(context.program, variant.type); - checkIfArmModel(context, operation, model, modelCandidate); + throwIfNotMatchingArmModel(context, operation, model, modelCandidate); if (modelCandidate.templateMapper !== undefined) { // ArmResponse for (const arg of modelCandidate.templateMapper.args) { if (isType(arg) && arg.kind === "Model") { - checkIfArmModel(context, operation, model, arg); + throwIfNotMatchingArmModel(context, operation, model, arg); if (arg.templateMapper !== undefined) { - // ArmResponse> - for (const type of arg.templateMapper.args) { - if (isType(type) && type.kind === "Model") { - checkIfArmModel(context, operation, model, type); - } + const modelArgs = arg.templateMapper.args.filter( + (a) => isType(a) && a.kind === "Model", + ); + const resourceArgs = modelArgs.filter( + (a) => getArmResource(context.program, a) !== undefined, + ); + // if there is only one ARM resource argument, it must match the expected ARM resource + if (resourceArgs.length === 1) { + throwIfNotMatchingArmModel(context, operation, model, resourceArgs[0]); } } } @@ -78,17 +82,17 @@ function checkArmResourceOperationReturnType( } } } -} -function checkIfArmModel( - context: LinterRuleContext, - operation: Operation, - model: Model, - modelCandidate: Model, -) { - if (getArmResource(context.program, modelCandidate) && modelCandidate !== model) { - context.reportDiagnostic({ - target: operation, - }); + function throwIfNotMatchingArmModel( + context: LinterRuleContext, + operation: Operation, + model: Model, + modelCandidate: Model, + ) { + if (getArmResource(context.program, modelCandidate) !== undefined && modelCandidate !== model) { + context.reportDiagnostic({ + target: operation, + }); + } } } diff --git a/packages/typespec-azure-resource-manager/src/state.ts b/packages/typespec-azure-resource-manager/src/state.ts index 9f65e0cd5f..f796eabc9a 100644 --- a/packages/typespec-azure-resource-manager/src/state.ts +++ b/packages/typespec-azure-resource-manager/src/state.ts @@ -37,4 +37,6 @@ export const ArmStateKeys = { armCommonParameters: azureResourceManagerCreateStateSymbol("armCommonParameters"), armCommonTypesVersions: azureResourceManagerCreateStateSymbol("armCommonTypesVersions"), armResourceRoute: azureResourceManagerCreateStateSymbol("armResourceRoute"), + armExternalType: azureResourceManagerCreateStateSymbol("armExternalType"), + inlineAzureType: azureResourceManagerCreateStateSymbol("inlineAzureType"), }; diff --git a/packages/typespec-azure-resource-manager/src/tsp-index.ts b/packages/typespec-azure-resource-manager/src/tsp-index.ts index 14cc4b9ee8..eae6bb932f 100644 --- a/packages/typespec-azure-resource-manager/src/tsp-index.ts +++ b/packages/typespec-azure-resource-manager/src/tsp-index.ts @@ -14,6 +14,7 @@ import { $armResourceUpdate, } from "./operations.js"; import { + $armExternalType, $armProviderNameValue, $armResourceOperations, $armVirtualResource, @@ -60,6 +61,7 @@ export const $decorators = { customAzureResource: $customAzureResource, externalTypeRef: $externalTypeRef, armOperationRoute: $armOperationRoute, + armExternalType: $armExternalType, } satisfies AzureResourceManagerLegacyDecorators, }; diff --git a/packages/typespec-azure-resource-manager/test/resource-resolution.test.ts b/packages/typespec-azure-resource-manager/test/resource-resolution.test.ts index 20c19a3763..812fd4efad 100644 --- a/packages/typespec-azure-resource-manager/test/resource-resolution.test.ts +++ b/packages/typespec-azure-resource-manager/test/resource-resolution.test.ts @@ -1049,4 +1049,327 @@ interface GenericResources { { operationGroup: "Operations", name: "list", kind: "other" }, ]); }); + + it("collects operation information for private endpoints", async () => { + const { program, diagnostics } = await compileAndDiagnose(` + +using Azure.Core; + +/** Contoso Resource Provider management API. */ +@armProviderNamespace +@service(#{ title: "ContosoProviderHubClient" }) +@versioned(Versions) +namespace Microsoft.ContosoProviderHub; + +/** Contoso API versions */ +enum Versions { + /** 2021-10-01-preview version */ + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) + v2021_20_01_preview: "2021-10-01-preview", +} + +// For more information about the proxy vs tracked, +// see https://armwiki.azurewebsites.net/rp_onboarding/tracked_vs_proxy_resources.html?q=proxy%20resource +/** A ContosoProviderHub resource */ +model Employee is TrackedResource { + ...ResourceNameParameter; +} + +/** Employee properties */ +model EmployeeProperties { + /** Age of employee */ + age?: int32; + + /** City of employee */ + city?: string; + + /** Profile of employee */ + @encode("base64url") + profile?: bytes; + + /** The status of the last operation. */ + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} + +/** The provisioning state of a resource. */ +@lroStatus +union ProvisioningState { + ResourceProvisioningState, + + /** The resource is being provisioned */ + Provisioning: "Provisioning", + + /** The resource is updating */ + Updating: "Updating", + + /** The resource is being deleted */ + Deleting: "Deleting", + + /** The resource create request has been accepted */ + Accepted: "Accepted", + + string, +} + +interface Operations extends Azure.ResourceManager.Operations {} + +model PrivateEndpointConnection is PrivateEndpointConnectionResource; +alias PrivateEndpointOperations = PrivateEndpoints; + +@armResourceOperations +interface Employees { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmCustomPatchSync< + Employee, + Azure.ResourceManager.Foundations.ResourceUpdateModel + >; + delete is ArmResourceDeleteSync; + listByResourceGroup is ArmResourceListByParent; + listBySubscription is ArmListBySubscription; + /** A sample resource action that move employee to different location */ + move is ArmResourceActionSync; + + /** A sample HEAD operation to check resource existence */ + checkExistence is ArmResourceCheckExistence; + + getPrivateEndpointConnection is PrivateEndpointOperations.Read; + createOrUpdatePrivateEndpointConnection is PrivateEndpointOperations.CreateOrUpdateAsync; + updatePrivateEndpointConnection is PrivateEndpointOperations.CustomPatchAsync; + deletePrivateEndpointConnection is PrivateEndpointOperations.DeleteAsync; + listPrivateEndpointConnections is PrivateEndpointOperations.ListByParent; +} + +/** Employee move request */ +model MoveRequest { + /** The moving from location */ + from: string; + + /** The moving to location */ + to: string; +} + +/** Employee move response */ +model MoveResponse { + /** The status of the move */ + movingStatus: string; +} + +@armResourceOperations +interface Dependents { + get is ArmResourceRead; + createOrUpdate is ArmResourceCreateOrReplaceAsync; + update is ArmCustomPatchSync< + Dependent, + Azure.ResourceManager.Foundations.ResourceUpdateModel + >; + delete is ArmResourceDeleteSync; + list is ArmResourceListByParent; + getPrivateEndpointConnection is PrivateEndpointOperations.Read; + createOrUpdatePrivateEndpointConnection is PrivateEndpointOperations.CreateOrUpdateAsync; + updatePrivateEndpointConnection is PrivateEndpointOperations.CustomPatchAsync; + deletePrivateEndpointConnection is PrivateEndpointOperations.DeleteAsync; + listPrivateEndpointConnections is PrivateEndpointOperations.ListByParent; +} + +/** An employee dependent */ +@parentResource(Employee) +model Dependent is ProxyResource { + ...ResourceNameParameter; +} + +/** Dependent properties */ +model DependentProperties { + /** Age of dependent */ + age: int32; + + /** Gender of dependent */ + gender: string; + + /** The status of the last operation. */ + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} +`); + expectDiagnosticEmpty(diagnostics); + const resources = resolveArmResources(program); + expect(resources).toBeDefined(); + expect(resources.resources).toBeDefined(); + expect(resources.resources).toHaveLength(3); + ok(resources.resources); + const employee = resources.resources[0]; + ok(employee); + expect(employee).toMatchObject({ + kind: "Tracked", + providerNamespace: "Microsoft.ContosoProviderHub", + type: expect.anything(), + operations: expect.any(Array), + }); + ok(employee.operations); + const subscriptionScope = employee.operations[0]; + ok(subscriptionScope); + checkResolvedOperations(subscriptionScope, { + operations: { + lifecycle: {}, + lists: [{ operationGroup: "Employees", name: "listBySubscription", kind: "list" }], + }, + resourceType: { + provider: "Microsoft.ContosoProviderHub", + types: ["employees"], + }, + resourceInstancePath: + "/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/employees/{name}", + }); + + const mainScope = employee.operations[1]; + ok(mainScope); + checkResolvedOperations(mainScope, { + operations: { + lifecycle: { + createOrUpdate: [ + { operationGroup: "Employees", name: "createOrUpdate", kind: "createOrUpdate" }, + ], + delete: [{ operationGroup: "Employees", name: "delete", kind: "delete" }], + read: [{ operationGroup: "Employees", name: "get", kind: "read" }], + update: [{ operationGroup: "Employees", name: "update", kind: "update" }], + }, + actions: [{ operationGroup: "Employees", name: "move", kind: "action" }], + lists: [{ operationGroup: "Employees", name: "listByResourceGroup", kind: "list" }], + }, + resourceType: { + provider: "Microsoft.ContosoProviderHub", + types: ["employees"], + }, + resourceInstancePath: + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}", + }); + + const dependent = resources.resources[2]; + ok(dependent); + expect(dependent).toMatchObject({ + kind: "Proxy", + providerNamespace: "Microsoft.ContosoProviderHub", + type: expect.anything(), + operations: expect.any(Array), + }); + ok(dependent.operations); + expect(dependent.operations).toHaveLength(1); + const instanceScope = dependent.operations[0]; + ok(instanceScope); + checkResolvedOperations(instanceScope, { + operations: { + lifecycle: { + createOrUpdate: [ + { operationGroup: "Dependents", name: "createOrUpdate", kind: "createOrUpdate" }, + ], + delete: [{ operationGroup: "Dependents", name: "delete", kind: "delete" }], + read: [{ operationGroup: "Dependents", name: "get", kind: "read" }], + update: [{ operationGroup: "Dependents", name: "update", kind: "update" }], + }, + lists: [{ operationGroup: "Dependents", name: "list", kind: "list" }], + }, + resourceType: { + provider: "Microsoft.ContosoProviderHub", + types: ["employees", "dependents"], + }, + resourceInstancePath: + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents/{dependentName}", + }); + + const privateEndpointConnection = resources.resources[1]; + ok(privateEndpointConnection); + ok(privateEndpointConnection.operations); + expect(privateEndpointConnection.operations).toHaveLength(2); + const privateForEmplInstance = privateEndpointConnection.operations[0]; + ok(privateForEmplInstance); + checkResolvedOperations(privateForEmplInstance, { + operations: { + lifecycle: { + createOrUpdate: [ + { + operationGroup: "Employees", + name: "createOrUpdatePrivateEndpointConnection", + kind: "createOrUpdate", + }, + ], + delete: [ + { + operationGroup: "Employees", + name: "deletePrivateEndpointConnection", + kind: "delete", + }, + ], + read: [ + { operationGroup: "Employees", name: "getPrivateEndpointConnection", kind: "read" }, + ], + update: [ + { + operationGroup: "Employees", + name: "updatePrivateEndpointConnection", + kind: "update", + }, + ], + }, + lists: [ + { operationGroup: "Employees", name: "listPrivateEndpointConnections", kind: "list" }, + ], + }, + resourceType: { + provider: "Microsoft.ContosoProviderHub", + types: ["employees", "privateEndpointConnections"], + }, + resourceInstancePath: + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/privateEndpointConnections/{privateEndpointConnectionName}", + }); + + const privateForDepInstance = privateEndpointConnection.operations[1]; + ok(privateForDepInstance); + + checkResolvedOperations(privateForDepInstance, { + operations: { + lifecycle: { + createOrUpdate: [ + { + operationGroup: "Dependents", + name: "createOrUpdatePrivateEndpointConnection", + kind: "createOrUpdate", + }, + ], + delete: [ + { + operationGroup: "Dependents", + name: "deletePrivateEndpointConnection", + kind: "delete", + }, + ], + read: [ + { operationGroup: "Dependents", name: "getPrivateEndpointConnection", kind: "read" }, + ], + update: [ + { + operationGroup: "Dependents", + name: "updatePrivateEndpointConnection", + kind: "update", + }, + ], + }, + lists: [ + { operationGroup: "Dependents", name: "listPrivateEndpointConnections", kind: "list" }, + ], + }, + resourceType: { + provider: "Microsoft.ContosoProviderHub", + types: ["employees", "dependents", "privateEndpointConnections"], + }, + resourceInstancePath: + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContosoProviderHub/employees/{employeeName}/dependents/{dependentName}/privateEndpointConnections/{privateEndpointConnectionName}", + }); + + checkArmOperationsHas(resources.unassociatedOperations, [ + { operationGroup: "Employees", name: "checkExistence", kind: "other" }, + { operationGroup: "Operations", name: "list", kind: "other" }, + ]); + }); }); diff --git a/packages/typespec-client-generator-core/CHANGELOG.md b/packages/typespec-client-generator-core/CHANGELOG.md index 217fc2e609..9c368d32a9 100644 --- a/packages/typespec-client-generator-core/CHANGELOG.md +++ b/packages/typespec-client-generator-core/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log - @azure-tools/typespec-client-generator-core +## 0.59.1 + +### Bug Fixes + +- [#3160](https://github.com/Azure/typespec-azure/pull/3160) Consider inheritance when mapping first segment for paging result. + + ## 0.59.0 No changes, version bump only. diff --git a/packages/typespec-client-generator-core/package.json b/packages/typespec-client-generator-core/package.json index 0b0f700f8c..e3aa7f84b9 100644 --- a/packages/typespec-client-generator-core/package.json +++ b/packages/typespec-client-generator-core/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-client-generator-core", - "version": "0.59.0", + "version": "0.59.1", "author": "Microsoft Corporation", "description": "TypeSpec Data Plane Generation library", "homepage": "https://azure.github.io/typespec-azure", diff --git a/packages/typespec-client-generator-core/src/methods.ts b/packages/typespec-client-generator-core/src/methods.ts index 32c13ddd12..c9c6913a18 100644 --- a/packages/typespec-client-generator-core/src/methods.ts +++ b/packages/typespec-client-generator-core/src/methods.ts @@ -354,13 +354,17 @@ function mapFirstSegmentForResultSegments( if (resultSegments.length > 0 && responseModel) { for (let i = 0; i < resultSegments.length; i++) { const segment = resultSegments[i]; - for (const property of responseModel.properties ?? []) { - if ( - property.__raw && - findRootSourceProperty(property.__raw) === findRootSourceProperty(segment) - ) { - return [property.__raw, ...resultSegments.slice(i + 1)]; + let current: SdkModelType | undefined = responseModel; + while (current) { + for (const property of current.properties ?? []) { + if ( + property.__raw && + findRootSourceProperty(property.__raw) === findRootSourceProperty(segment) + ) { + return [property.__raw, ...resultSegments.slice(i + 1)]; + } } + current = current.baseModel; } } } diff --git a/packages/typespec-client-generator-core/test/methods/paged-operation.test.ts b/packages/typespec-client-generator-core/test/methods/paged-operation.test.ts index f0d7edc0f3..09676ef891 100644 --- a/packages/typespec-client-generator-core/test/methods/paged-operation.test.ts +++ b/packages/typespec-client-generator-core/test/methods/paged-operation.test.ts @@ -1101,3 +1101,47 @@ it("paged result with body root", async () => { strictEqual(response.resultSegments[0], sdkPackage.models[0].properties[0]); strictEqual(method.pagingMetadata.pageItemsSegments, response.resultSegments); }); + +it("next link with body root and inheritance", async () => { + await runner.compileWithBuiltInService(` + @list + op test(): TestResponse; + + model ListMeta{ + @nextLink + nextLink: url; + } + + model ListTestResult extends ListMeta { + @pageItems + tests: Test[]; + + @header + h: string; + } + model Test { + id: string; + } + model TestResponse { + ...OkResponse; + + @bodyRoot + body: ResponseBody; + } + `); + const sdkPackage = runner.context.sdkPackage; + const method = getServiceMethodOfClient(sdkPackage); + strictEqual(method.name, "test"); + strictEqual(method.kind, "paging"); + strictEqual(method.pagingMetadata.nextLinkSegments?.length, 1); + strictEqual( + method.pagingMetadata.nextLinkSegments[0], + sdkPackage.models[0].baseModel?.properties[0], + ); + + const response = method.response; + strictEqual(response.kind, "method"); + strictEqual(response.resultSegments?.length, 1); + strictEqual(response.resultSegments[0], sdkPackage.models[0].properties[0]); + strictEqual(method.pagingMetadata.pageItemsSegments, response.resultSegments); +}); diff --git a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md index 9aed97a30b..83e5f2243a 100644 --- a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md +++ b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/data-types.md @@ -840,6 +840,55 @@ model Azure.ResourceManager.ParentKeysOf None +### `PrivateEndpointConnectionResource` {#Azure.ResourceManager.PrivateEndpointConnectionResource} + +A private endpoint connection resource. +Resource providers must declare a private endpoint connection resource type in their provider namespace if +they support private endpoint connections + +```typespec +model Azure.ResourceManager.PrivateEndpointConnectionResource +``` + +#### Template Parameters + +| Name | Description | +| ----------- | ------------------------------------------------------------------------------------------------- | +| Description | Optional. The documentary description of the private endpoint connection resource name parameter. | + +#### Examples + +```ts +namespace Microsoft.Contoso; +model PrivateEndpointConnection is PrivateEndpointConnectionResource {} +alias EmployeeConnectionOps is PrivateEndpoints; +@armResourceOperations +interface Employees { + @doc("get a private endpoint connection for resource employee") + getPrivateEndpointConnection is EmployeeConnectionOps.Read; +} +``` + +#### Properties + +| Name | Type | Description | +| ----------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | +| properties? | [`PrivateEndpointConnectionProperties`](./data-types.md#Azure.ResourceManager.CommonTypes.PrivateEndpointConnectionProperties) | The private endpoint connection properties | + +### `PrivateEndpointConnectionUpdate` {#Azure.ResourceManager.PrivateEndpointConnectionUpdate} + +PATCH model for private endpoint connections + +```typespec +model Azure.ResourceManager.PrivateEndpointConnectionUpdate +``` + +#### Properties + +| Name | Type | Description | +| ----------- | ----------------------------------------------------------------------------------------------------------- | ------------------------------------------ | +| properties? | `OptionalProperties>` | The private endpoint connection properties | + ### `ProviderNamespace` {#Azure.ResourceManager.ProviderNamespace} Model describing the provider namespace. @@ -2435,10 +2484,10 @@ model Azure.ResourceManager.CommonTypes.TrackedResource #### Properties -| Name | Type | Description | -| -------- | ---------------- | ----------------------------------------- | -| tags? | `Record` | Resource tags. | -| location | `string` | The geo-location where the resource lives | +| Name | Type | Description | +| -------- | -------------------- | ----------------------------------------- | +| tags? | `Record` | Resource tags. | +| location | `Core.azureLocation` | The geo-location where the resource lives | ### `UserAssignedIdentities` {#Azure.ResourceManager.CommonTypes.UserAssignedIdentities} @@ -3321,6 +3370,74 @@ model Azure.ResourceManager.Legacy.ArmOperationOptions | useStaticRoute? | `boolean` | Should a static route be used | | route? | `string` | The status route for operations to use | +### `CustomResourceOptions` {#Azure.ResourceManager.Legacy.CustomResourceOptions} + +Options for customizing the behavior of a custom azure resource + +```typespec +model Azure.ResourceManager.Legacy.CustomResourceOptions +``` + +#### Properties + +| Name | Type | Description | +| ---------------- | --------- | -------------------------------------------------- | +| isAzureResource? | `boolean` | Should the resource be marked as an Azure resource | + +### `ExtendedLocationOptional` {#Azure.ResourceManager.Legacy.ExtendedLocationOptional} + +The complex type of the extended location. + +```typespec +model Azure.ResourceManager.Legacy.ExtendedLocationOptional +``` + +#### Properties + +| Name | Type | Description | +| ----- | ------------------------------------------------------------------------------------------------ | ---------------------------------- | +| name? | `string` | The name of the extended location. | +| type? | [`ExtendedLocationType`](./data-types.md#Azure.ResourceManager.CommonTypes.ExtendedLocationType) | The type of the extended location. | + +### `ExtendedLocationOptionalProperty` {#Azure.ResourceManager.Legacy.ExtendedLocationOptionalProperty} + +Legacy. Model representing a non-standard `extendedLocation` envelope property with all properties optional. +Spread this model into a Resource Model, if you are converting a BrownField API with extended location that has optional properties + +```typespec +model Azure.ResourceManager.Legacy.ExtendedLocationOptionalProperty +``` + +#### Examples + +```typespec +model Employee is TrackedResource { + ...ResourceNameParameter; + ...ExtendedLocationOptionalProperty; +} +``` + +#### Properties + +| Name | Type | Description | +| ----------------- | --------------------------------------------------------------------------------------------------- | ----------- | +| extendedLocation? | [`ExtendedLocationOptional`](./data-types.md#Azure.ResourceManager.Legacy.ExtendedLocationOptional) | | + +### `LegacyTrackedResource` {#Azure.ResourceManager.Legacy.LegacyTrackedResource} + +A tracked resource with the 'location' property optional + +```typespec +model Azure.ResourceManager.Legacy.LegacyTrackedResource +``` + +#### Properties + +| Name | Type | Description | +| --------- | ---------------- | ----------------------------------------- | +| tags? | `Record` | Resource tags. | +| location? | `string` | The geo-location where the resource lives | + ### `ManagedServiceIdentityV4` {#Azure.ResourceManager.Legacy.ManagedServiceIdentityV4} Managed service identity (system assigned and/or user assigned identities) @@ -3402,6 +3519,38 @@ model Azure.ResourceManager.Legacy.ProviderParameter | -------- | -------------------------------- | ----------- | | provider | `"Microsoft.ThisWillBeReplaced"` | | +### `TrackedResourceWithOptionalLocation` {#Azure.ResourceManager.Legacy.TrackedResourceWithOptionalLocation} + +This type uses an optional location property, only used by legacy APIs. +Concrete tracked resource types can be created by aliasing this type using a specific property type. + +See more details on [different Azure Resource Manager resource type here.](https://azure.github.io/typespec-azure/docs/howtos/ARM/resource-type) + +```typespec +model Azure.ResourceManager.Legacy.TrackedResourceWithOptionalLocation +``` + +#### Template Parameters + +| Name | Description | +| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| Properties | A model containing the provider-specific properties for this resource | +| PropertiesOptional | A boolean flag indicating whether the resource `Properties` field is marked as optional or required. Default true is optional and recommended. | + +#### Examples + +```typespec +model Employee is TrackedResourceWithOptionalLocation { + ...ResourceNameParameter; +} +``` + +#### Properties + +| Name | Type | Description | +| ----------- | ------------ | ----------- | +| properties? | `Properties` | | + ### `ManagedServiceIdentityType` {#Azure.ResourceManager.Legacy.ManagedServiceIdentityType} Type of managed service identity (where both SystemAssigned and UserAssigned types are allowed). diff --git a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/decorators.md b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/decorators.md index 1518b386c5..9a14cc3b11 100644 --- a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/decorators.md +++ b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/decorators.md @@ -257,9 +257,9 @@ Azure.ResourceManager common types. #### Parameters -| Name | Type | Description | -| -------- | ---------------- | ----------- | -| provider | `valueof string` | | +| Name | Type | Description | +| -------- | ---------------- | ------------------------------------------------------------------- | +| provider | `valueof string` | Optional. The resource provider namespace for the virtual resource. | ### `@extensionResource` {#@Azure.ResourceManager.extensionResource} @@ -346,9 +346,9 @@ This decorator sets the base type of the given resource. #### Parameters -| Name | Type | Description | -| ---------- | ---------------------------------------------------------------------------- | ----------- | -| baseTypeIt | `"Tenant" \| "Subscription" \| "ResourceGroup" \| "Location" \| "Extension"` | | +| Name | Type | Description | +| ---------- | ---------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------- | +| baseTypeIt | `"Tenant" \| "Subscription" \| "ResourceGroup" \| "Location" \| "Extension"` | The built-in parent of the resource, this can be "Tenant", "Subscription", "ResourceGroup", "Location", or "Extension" | ### `@resourceGroupResource` {#@Azure.ResourceManager.resourceGroupResource} @@ -458,6 +458,23 @@ This allows sharing Azure Resource Manager resource types across specifications ## Azure.ResourceManager.Legacy +### `@armExternalType` {#@Azure.ResourceManager.Legacy.armExternalType} + +Signifies that a Resource is represented using a library type in generated SDKs. + +```typespec +@Azure.ResourceManager.Legacy.armExternalType +``` + +#### Target + +The model to that is an external resource +`Model` + +#### Parameters + +None + ### `@armOperationRoute` {#@Azure.ResourceManager.Legacy.armOperationRoute} Signifies that an operation is an Azure Resource Manager operation @@ -484,7 +501,7 @@ This decorator is used on resources that do not satisfy the definition of a reso but need to be identified as such. ```typespec -@Azure.ResourceManager.Legacy.customAzureResource +@Azure.ResourceManager.Legacy.customAzureResource(options?: valueof Azure.ResourceManager.Legacy.CustomResourceOptions) ``` #### Target @@ -493,7 +510,9 @@ but need to be identified as such. #### Parameters -None +| Name | Type | Description | +| ------- | ----------------------------------------------------------------------------------------------------- | ---------------------------------------------------- | +| options | [valueof `CustomResourceOptions`](./data-types.md#Azure.ResourceManager.Legacy.CustomResourceOptions) | Options for customizing the behavior of the resource | ### `@externalTypeRef` {#@Azure.ResourceManager.Legacy.externalTypeRef} diff --git a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/index.mdx b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/index.mdx index c396281a69..3095478bc5 100644 --- a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/index.mdx +++ b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/index.mdx @@ -63,6 +63,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager - [`ExtensionResourceInstanceOperations`](./interfaces.md#Azure.ResourceManager.ExtensionResourceInstanceOperations) - [`ExtensionResourceOperations`](./interfaces.md#Azure.ResourceManager.ExtensionResourceOperations) - [`Operations`](./interfaces.md#Azure.ResourceManager.Operations) +- [`PrivateEndpoints`](./interfaces.md#Azure.ResourceManager.PrivateEndpoints) - [`ProxyResourceOperations`](./interfaces.md#Azure.ResourceManager.ProxyResourceOperations) - [`ResourceCollectionOperations`](./interfaces.md#Azure.ResourceManager.ResourceCollectionOperations) - [`ResourceCreateAsync`](./interfaces.md#Azure.ResourceManager.ResourceCreateAsync) @@ -148,6 +149,8 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager - [`ManagedServiceIdentityProperty`](./data-types.md#Azure.ResourceManager.ManagedServiceIdentityProperty) - [`ManagedSystemAssignedIdentityProperty`](./data-types.md#Azure.ResourceManager.ManagedSystemAssignedIdentityProperty) - [`ParentKeysOf`](./data-types.md#Azure.ResourceManager.ParentKeysOf) +- [`PrivateEndpointConnectionResource`](./data-types.md#Azure.ResourceManager.PrivateEndpointConnectionResource) +- [`PrivateEndpointConnectionUpdate`](./data-types.md#Azure.ResourceManager.PrivateEndpointConnectionUpdate) - [`ProviderNamespace`](./data-types.md#Azure.ResourceManager.ProviderNamespace) - [`ProxyResource`](./data-types.md#Azure.ResourceManager.ProxyResource) - [`ResourceGroupLocationResource`](./data-types.md#Azure.ResourceManager.ResourceGroupLocationResource) @@ -311,6 +314,7 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager ### Decorators +- [`@armExternalType`](./decorators.md#@Azure.ResourceManager.Legacy.armExternalType) - [`@armOperationRoute`](./decorators.md#@Azure.ResourceManager.Legacy.armOperationRoute) - [`@customAzureResource`](./decorators.md#@Azure.ResourceManager.Legacy.customAzureResource) - [`@externalTypeRef`](./decorators.md#@Azure.ResourceManager.Legacy.externalTypeRef) @@ -324,9 +328,11 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager ### Operations +- [`ArmListSinglePageByParent`](./interfaces.md#Azure.ResourceManager.Legacy.ArmListSinglePageByParent) +- [`ArmListSinglePageBySubscription`](./interfaces.md#Azure.ResourceManager.Legacy.ArmListSinglePageBySubscription) - [`CreateOperation`](./interfaces.md#Azure.ResourceManager.Legacy.CreateOperation) -- [`CreateOrUpdateAsync`](./interfaces.md#Azure.ResourceManager.Legacy.CreateOrUpdateAsync) -- [`CreateOrUpdateSync`](./interfaces.md#Azure.ResourceManager.Legacy.CreateOrUpdateSync) +- [`CreateOrReplaceAsync`](./interfaces.md#Azure.ResourceManager.Legacy.CreateOrReplaceAsync) +- [`CreateOrReplaceSync`](./interfaces.md#Azure.ResourceManager.Legacy.CreateOrReplaceSync) - [`CustomPatchAsync`](./interfaces.md#Azure.ResourceManager.Legacy.CustomPatchAsync) - [`CustomPatchSync`](./interfaces.md#Azure.ResourceManager.Legacy.CustomPatchSync) - [`UpdateOperation`](./interfaces.md#Azure.ResourceManager.Legacy.UpdateOperation) @@ -334,16 +340,31 @@ npm install --save-peer @azure-tools/typespec-azure-resource-manager ### Models - [`ArmOperationOptions`](./data-types.md#Azure.ResourceManager.Legacy.ArmOperationOptions) +- [`CustomResourceOptions`](./data-types.md#Azure.ResourceManager.Legacy.CustomResourceOptions) +- [`ExtendedLocationOptional`](./data-types.md#Azure.ResourceManager.Legacy.ExtendedLocationOptional) +- [`ExtendedLocationOptionalProperty`](./data-types.md#Azure.ResourceManager.Legacy.ExtendedLocationOptionalProperty) +- [`LegacyTrackedResource`](./data-types.md#Azure.ResourceManager.Legacy.LegacyTrackedResource) - [`ManagedServiceIdentityV4`](./data-types.md#Azure.ResourceManager.Legacy.ManagedServiceIdentityV4) - [`ManagedServiceIdentityV4Property`](./data-types.md#Azure.ResourceManager.Legacy.ManagedServiceIdentityV4Property) - [`Provider`](./data-types.md#Azure.ResourceManager.Legacy.Provider) - [`ProviderParameter`](./data-types.md#Azure.ResourceManager.Legacy.ProviderParameter) +- [`TrackedResourceWithOptionalLocation`](./data-types.md#Azure.ResourceManager.Legacy.TrackedResourceWithOptionalLocation) ## Azure.ResourceManager.Legacy.Extension ### Operations +- [`CreateOrReplaceAsync`](./interfaces.md#Azure.ResourceManager.Legacy.Extension.CreateOrReplaceAsync) - [`CreateOrReplaceSync`](./interfaces.md#Azure.ResourceManager.Legacy.Extension.CreateOrReplaceSync) -- [`CreateOrUpdateAsync`](./interfaces.md#Azure.ResourceManager.Legacy.Extension.CreateOrUpdateAsync) - [`CustomPatchAsync`](./interfaces.md#Azure.ResourceManager.Legacy.Extension.CustomPatchAsync) - [`CustomPatchSync`](./interfaces.md#Azure.ResourceManager.Legacy.Extension.CustomPatchSync) + +## Azure.ResourceManager.Legacy.PrivateEndpoints + +### Operations + +- [`CreateOrReplaceAsync`](./interfaces.md#Azure.ResourceManager.Legacy.PrivateEndpoints.CreateOrReplaceAsync) +- [`CreateOrReplaceSync`](./interfaces.md#Azure.ResourceManager.Legacy.PrivateEndpoints.CreateOrReplaceSync) +- [`CustomPatchAsync`](./interfaces.md#Azure.ResourceManager.Legacy.PrivateEndpoints.CustomPatchAsync) +- [`CustomPatchSync`](./interfaces.md#Azure.ResourceManager.Legacy.PrivateEndpoints.CustomPatchSync) +- [`ListSinglePageByParent`](./interfaces.md#Azure.ResourceManager.Legacy.PrivateEndpoints.ListSinglePageByParent) diff --git a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md index 3a77b55bf7..7c72235416 100644 --- a/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md +++ b/website/src/content/docs/docs/libraries/azure-resource-manager/reference/interfaces.md @@ -121,12 +121,215 @@ interface Azure.ResourceManager.Operations<> #### `Operations.list` {#Azure.ResourceManager.Operations.list} -List the operations for the provider - ```typespec op Azure.ResourceManager.Operations.list(apiVersion: string, provider: "Microsoft.ThisWillBeReplaced"): Azure.ResourceManager.ArmResponse | Azure.ResourceManager.CommonTypes.ErrorResponse ``` +### `PrivateEndpoints` {#Azure.ResourceManager.PrivateEndpoints} + +Operations over private endpoint connection resources. + +```typespec +interface Azure.ResourceManager.PrivateEndpoints +``` + +#### Template Parameters + +| Name | Description | +| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| PrivateEndpointResource | The type of the private endpoint connection resource. You must declare a private endpoint connection resource type in your provider namespace. | + +#### `PrivateEndpoints.ListByParent` {#Azure.ResourceManager.PrivateEndpoints.ListByParent} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.ListByParent(provider: "Microsoft.ThisWillBeReplaced"): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ------------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | Optional. The PrivateEndpointConnection resource being listed | +| BaseParameters | Optional. Allows overriding the operation parameters | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the list operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.Read` {#Azure.ResourceManager.PrivateEndpoints.Read} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.Read(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | --------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | the PrivateEndpointConnection resource being read | +| BaseParameters | Optional. Allows overriding the operation parameters | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the read operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.CreateOrUpdateAsync` {#Azure.ResourceManager.PrivateEndpoints.CreateOrUpdateAsync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.CreateOrUpdateAsync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string, resource: Resource): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ----------------------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | the PrivateEndpointConnection resource being created or updated | +| BaseParameters | Optional. Allows overriding the operation parameters | +| LroHeaders | Optional. Allows overriding the lro headers returned on resource create | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the createOrUpdate operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.CreateOrReplaceSync` {#Azure.ResourceManager.PrivateEndpoints.CreateOrReplaceSync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.CreateOrReplaceSync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string, resource: Resource): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | --------------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | the PrivateEndpointConnection resource being created or updated | +| BaseParameters | Optional. Allows overriding the operation parameters | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the createOrUpdate operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.CreateOrReplaceAsync` {#Azure.ResourceManager.PrivateEndpoints.CreateOrReplaceAsync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.CreateOrReplaceAsync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string, resource: Resource): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ----------------------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | the PrivateEndpointConnection resource being created or updated | +| BaseParameters | Optional. Allows overriding the operation parameters | +| LroHeaders | Optional. Allows overriding the lro headers returned on resource create | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the createOrReplace operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.CustomPatchAsync` {#Azure.ResourceManager.PrivateEndpoints.CustomPatchAsync} + +A long-running resource update using a custom PATCH payload (Asynchronous) to update a PrivateEndpointConnection to a resource. + +```typespec +op Azure.ResourceManager.PrivateEndpoints.CustomPatchAsync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string, properties: PatchModel): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ----------------------------------------------------------------------------- | +| ParentResource | the parent resource of the PrivateEndpointConnection | +| Resource | the PrivateEndpointConnection resource being updated | +| PatchModel | The input model for the PATCH request | +| BaseParameters | Optional. Allows overriding the operation parameters | +| LroHeaders | Optional. Allows overriding the lro headers returned in the Accepted response | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the patch operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.CustomPatchSync` {#Azure.ResourceManager.PrivateEndpoints.CustomPatchSync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.CustomPatchSync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string, properties: PatchModel): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | -------------------------------------------------------------- | +| ParentResource | The parent resource of the PrivateEndpointConnection | +| Resource | Optional. The PrivateEndpointConnection resource being patched | +| PatchModel | The input model for the PATCH request | +| BaseParameters | Optional. Allows overriding the operation parameters | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response for the patch operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.DeleteAsync` {#Azure.ResourceManager.PrivateEndpoints.DeleteAsync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.DeleteAsync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ------------------------------------------------------------------------- | +| ParentResource | The parent resource of the PrivateEndpointConnection | +| Resource | Optional. The PrivateEndpointConnection resource being deleted | +| BaseParameters | Optional. Allows overriding the parameters for the operation | +| LroHeaders | Optional. Allows overriding the headers returned in the Accepted response | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response(s) for the delete operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.DeleteSync` {#Azure.ResourceManager.PrivateEndpoints.DeleteSync} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.DeleteSync(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | ------------------------------------------------------------ | +| ParentResource | The parent resource of the PrivateEndpointConnection | +| Resource | The PrivateEndpointConnection resource being deleted | +| BaseParameters | Optional. Allows overriding the parameters for the operation | +| Parameters | Optional. Additional parameters after the path parameters | +| Response | Optional. The success response(s) for the delete operation | +| Error | Optional. The error response, if non-standard. | + +#### `PrivateEndpoints.DeleteAsyncBase` {#Azure.ResourceManager.PrivateEndpoints.DeleteAsyncBase} + +```typespec +op Azure.ResourceManager.PrivateEndpoints.DeleteAsyncBase(provider: "Microsoft.ThisWillBeReplaced", privateEndpointConnectionName: string): Response | Error +``` + +##### Template Parameters + +| Name | Description | +| -------------- | -------------------------------------------------------------- | +| ParentResource | The parent resource of the PrivateEndpointConnection | +| Response | The response type for the operation | +| Resource | Optional. The PrivateEndpointConnection resource being deleted | +| BaseParameters | Optional. Allows overriding the parameters for the operation | +| Parameters | Optional. Additional parameters after the path parameters | +| Error | Optional. The error response, if non-standard. | + +#### Examples + +```ts +namespace Microsoft.Contoso; +model PrivateEndpointConnection is PrivateEndpointConnectionResource {} +alias EmployeeConnectionOps is PrivateEndpoints; +@armResourceOperations +interface Employees { + @doc("get a private endpoint connection for resource employee") + getPrivateEndpointConnection is EmployeeConnectionOps.Read; +} +``` + ### `ProxyResourceOperations` {#Azure.ResourceManager.ProxyResourceOperations} A composite interface for Proxy resources that include `ResourceInstanceOperations` @@ -1532,7 +1735,7 @@ interface Azure.ResourceManager.Legacy.ExtensionOperations