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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion packages/typespec-powershell/src/convertor/convertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,12 @@ function addResponses(psContext: SdkContext, op: HttpOperation, newOperation: Op
// This is aligned with the behavior of typescript emitter and typespec-autorest emitter.
newResponse.protocol.http = newResponse.protocol.http ?? new Protocol();
const lroHeaders = ["location", "retry-after", "azure-asyncoperation"];
const pollingResponseStatus = ["202", "201"];
const addedKeys: string[] = [];
for (const innerResponse of response.responses) {
if (innerResponse.headers) {
for (const key in innerResponse.headers) {
if (addedKeys.includes(key) || (emitterOptions["remove-lro-headers"] && lroHeaders.includes(key.toLowerCase()))) {
if (addedKeys.includes(key) || (emitterOptions["remove-lro-headers"] && pollingResponseStatus.includes(statusCode) && lroHeaders.includes(key.toLowerCase()))) {
continue;
} else {
addedKeys.push(key);
Expand Down
90 changes: 90 additions & 0 deletions tests-upgrade/tests-emitter/ElasticSan.brown/ElasticSan.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/openapi";
import "@typespec/rest";
import "./models.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace Microsoft.ElasticSan;
/**
* Response for ElasticSan request.
*/
model ElasticSan
is Azure.ResourceManager.TrackedResource<ElasticSanProperties, false> {
...ResourceNameParameter<
Resource = ElasticSan,
KeyName = "elasticSanName",
SegmentName = "elasticSans",
NamePattern = "^[A-Za-z0-9]+((-|_)[a-z0-9A-Z]+)*$"
>;
}

@armResourceOperations
interface ElasticSans {
/**
* Get a ElasticSan.
*/
get is ArmResourceRead<ElasticSan>;

/**
* Create ElasticSan.
*/
create is ArmResourceCreateOrReplaceAsync<
ElasticSan,
LroHeaders = ArmLroLocationHeader<FinalResult = ElasticSan> &
Azure.Core.Foundations.RetryAfterHeader
>;

/**
* Update a Elastic San.
*/
@patch(#{ implicitOptionality: false })
update is ArmCustomPatchAsync<ElasticSan, PatchModel = ElasticSanUpdate>;

/**
* Delete a Elastic San.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
delete is ArmResourceDeleteWithoutOkAsync<
ElasticSan,
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
>;

/**
* Gets a list of ElasticSan in a resource group.
*/
listByResourceGroup is ArmResourceListByParent<
ElasticSan,
Response = ArmResponse<ElasticSanList>
>;

/**
* Gets a list of ElasticSans in a subscription
*/
listBySubscription is ArmListBySubscription<
ElasticSan,
Response = ArmResponse<ElasticSanList>
>;

/**
* Gets the private link resources that need to be created for a elastic San.
*/
@get
@action("privateLinkResources")
listByElasticSan is ArmResourceActionSync<
ElasticSan,
void,
ArmResponse<PrivateLinkResourceListResult>
>;
}

@@maxLength(ElasticSan.name, 24);
@@minLength(ElasticSan.name, 3);
@@doc(ElasticSan.name, "The name of the ElasticSan.");
@@doc(ElasticSan.properties, "Properties of ElasticSan.");
@@doc(ElasticSans.create::parameters.resource, "Elastic San object.");
@@doc(ElasticSans.update::parameters.properties, "Elastic San object.");
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/openapi";
import "@typespec/rest";
import "./models.tsp";
import "./ElasticSan.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace Microsoft.ElasticSan;
/**
* Response for PrivateEndpoint Connection object
*/
@parentResource(ElasticSan)
model PrivateEndpointConnection
is Azure.ResourceManager.ProxyResource<
PrivateEndpointConnectionProperties,
false
> {
...ResourceNameParameter<
Resource = PrivateEndpointConnection,
KeyName = "privateEndpointConnectionName",
SegmentName = "privateEndpointConnections",
NamePattern = ""
>;
}

@armResourceOperations
interface PrivateEndpointConnections {
/**
* Gets the specified private endpoint connection associated with the Elastic San
*/
get is ArmResourceRead<PrivateEndpointConnection>;

/**
* Update the state of specified private endpoint connection associated with the Elastic San
*/
create is ArmResourceCreateOrReplaceAsync<
PrivateEndpointConnection,
LroHeaders = ArmLroLocationHeader<FinalResult = PrivateEndpointConnection> &
Azure.Core.Foundations.RetryAfterHeader
>;

/**
* Deletes the specified private endpoint connection associated with the Elastic San
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
delete is ArmResourceDeleteWithoutOkAsync<
PrivateEndpointConnection,
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
>;

/**
* List all Private Endpoint Connections associated with the Elastic San.
*/
list is ArmResourceListByParent<PrivateEndpointConnection>;
}

@@doc(PrivateEndpointConnection.name,
"The name of the Private Endpoint connection."
);
@@doc(PrivateEndpointConnection.properties,
"Private Endpoint Connection Properties."
);
@@doc(PrivateEndpointConnections.create::parameters.resource,
"Private Endpoint Connection Approval object."
);
75 changes: 75 additions & 0 deletions tests-upgrade/tests-emitter/ElasticSan.brown/Snapshot.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@typespec/openapi";
import "@typespec/rest";
import "./models.tsp";
import "./VolumeGroup.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using TypeSpec.Http;
using TypeSpec.OpenAPI;

namespace Microsoft.ElasticSan;
/**
* Response for Volume Snapshot request.
*/
@parentResource(VolumeGroup)
model Snapshot
is Azure.ResourceManager.ProxyResource<SnapshotProperties, false> {
...ResourceNameParameter<
Resource = Snapshot,
KeyName = "snapshotName",
SegmentName = "snapshots",
NamePattern = "^[a-z0-9]+(?:[._-][a-z0-9]+)*$"
>;
}

@armResourceOperations
interface Snapshots {
/**
* Get a Volume Snapshot.
*/
get is ArmResourceRead<Snapshot>;

/**
* Create a Volume Snapshot.
*/
create is ArmResourceCreateOrReplaceAsync<
Snapshot,
LroHeaders = ArmLroLocationHeader<FinalResult = Snapshot> &
Azure.Core.Foundations.RetryAfterHeader
>;

/**
* Delete a Volume Snapshot.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
delete is ArmResourceDeleteWithoutOkAsync<
Snapshot,
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
>;

/**
* List Snapshots in a VolumeGroup or List Snapshots by Volume (name) in a VolumeGroup using filter
*/
listByVolumeGroup is ArmResourceListByParent<
Snapshot,
Parameters = {
/**
* Specify $filter='volumeName eq <volume name>' to filter on volume.
*/
@query("$filter")
$filter?: string;
},
Response = ArmResponse<SnapshotList>
>;
}

@@maxLength(Snapshot.name, 80);
@@minLength(Snapshot.name, 1);
@@doc(Snapshot.name,
"The name of the volume snapshot within the given volume group."
);
@@doc(Snapshot.properties, "Properties of Volume Snapshot.");
@@doc(Snapshots.create::parameters.resource, "Snapshot object.");
112 changes: 112 additions & 0 deletions tests-upgrade/tests-emitter/ElasticSan.brown/Volume.tsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import "@azure-tools/typespec-azure-core";
import "@azure-tools/typespec-azure-resource-manager";
import "@azure-tools/typespec-client-generator-core";
import "@typespec/openapi";
import "@typespec/rest";
import "./models.tsp";
import "./VolumeGroup.tsp";

using TypeSpec.Rest;
using Azure.ResourceManager;
using TypeSpec.Http;
using Azure.ClientGenerator.Core;

namespace Microsoft.ElasticSan;
/**
* Response for Volume request.
*/
@parentResource(VolumeGroup)
model Volume is Azure.ResourceManager.ProxyResource<VolumeProperties, false> {
...ResourceNameParameter<
Resource = Volume,
KeyName = "volumeName",
SegmentName = "volumes",
NamePattern = "^[a-z0-9]+(-[a-z0-9A-Z]+)*$"
>;
}

@armResourceOperations
interface Volumes {
/**
* Get an Volume.
*/
get is ArmResourceRead<Volume>;

/**
* Create a Volume.
*/
create is ArmResourceCreateOrReplaceAsync<
Volume,
LroHeaders = ArmLroLocationHeader<FinalResult = Volume> &
Azure.Core.Foundations.RetryAfterHeader
>;

/**
* Update an Volume.
*/
@patch(#{ implicitOptionality: false })
update is ArmCustomPatchAsync<Volume, PatchModel = VolumeUpdate>;

/**
* Delete an Volume.
*/
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
delete is ArmResourceDeleteWithoutOkAsync<
Volume,
Parameters = {
/**
* Optional, used to delete snapshots under volume. Allowed value are only true or false. Default value is false.
*/
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
@header
@clientName("deleteSnapshots", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
`x-ms-delete-snapshots`?: `x-ms-delete-snapshots`;

/**
* Optional, used to delete volume if active sessions present. Allowed value are only true or false. Default value is false.
*/
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
@header
@clientName("forceDelete", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
`x-ms-force-delete`?: `x-ms-force-delete`;

/**
* Optional. Specifies that the delete operation should be a permanent delete for the soft deleted volume. The value of deleteType can only be 'permanent'.
*/
@query("deleteType")
deleteType?: DeleteType;
},
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
>;

/**
* List Volumes in a VolumeGroup.
*/
listByVolumeGroup is ArmResourceListByParent<
Volume,
Parameters = {
/**
* Optional, returns only soft deleted volumes if set to true. If set to false or if not specified, returns only active volumes.
*/
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
@header
@clientName("accessSoftDeletedResources", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
`x-ms-access-soft-deleted-resources`?: `x-ms-access-soft-deleted-resources`;
},
Response = ArmResponse<VolumeList>
>;
}

/**
* Restore Soft Deleted Volumes. The volume name is obtained by using the API to list soft deleted volumes by volume group
*/
@action("restore")
@tag("RestoreVolumes")
op restoreVolume is ArmResourceActionAsync<Volume, void, Volume>;

@@maxLength(Volume.name, 63);
@@minLength(Volume.name, 3);
@@doc(Volume.name, "The name of the Volume.");
@@doc(Volume.properties, "Properties of Volume.");
@@doc(Volumes.create::parameters.resource, "Volume object.");
@@doc(Volumes.update::parameters.properties, "Volume object.");
Loading
Loading