Skip to content

Commit 1550e4c

Browse files
authored
Fixed an issue related to header response and added three new test cases (#1524)
* Fixed an issue related to header response and addes three new test cases * tsp - ignore comparison for the file HelpRp.cs
1 parent 7d0f5ad commit 1550e4c

File tree

1,604 files changed

+353168
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,604 files changed

+353168
-7
lines changed

packages/typespec-powershell/src/convertor/convertor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ function addResponses(psContext: SdkContext, op: HttpOperation, newOperation: Op
303303
// This is aligned with the behavior of typescript emitter and typespec-autorest emitter.
304304
newResponse.protocol.http = newResponse.protocol.http ?? new Protocol();
305305
const lroHeaders = ["location", "retry-after", "azure-asyncoperation"];
306+
const pollingResponseStatus = ["202", "201"];
306307
const addedKeys: string[] = [];
307308
for (const innerResponse of response.responses) {
308309
if (innerResponse.headers) {
309310
for (const key in innerResponse.headers) {
310-
if (addedKeys.includes(key) || (emitterOptions["remove-lro-headers"] && lroHeaders.includes(key.toLowerCase()))) {
311+
if (addedKeys.includes(key) || (emitterOptions["remove-lro-headers"] && pollingResponseStatus.includes(statusCode) && lroHeaders.includes(key.toLowerCase()))) {
311312
continue;
312313
} else {
313314
addedKeys.push(key);
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "@typespec/openapi";
4+
import "@typespec/rest";
5+
import "./models.tsp";
6+
7+
using TypeSpec.Rest;
8+
using Azure.ResourceManager;
9+
using TypeSpec.Http;
10+
using TypeSpec.OpenAPI;
11+
12+
namespace Microsoft.ElasticSan;
13+
/**
14+
* Response for ElasticSan request.
15+
*/
16+
model ElasticSan
17+
is Azure.ResourceManager.TrackedResource<ElasticSanProperties, false> {
18+
...ResourceNameParameter<
19+
Resource = ElasticSan,
20+
KeyName = "elasticSanName",
21+
SegmentName = "elasticSans",
22+
NamePattern = "^[A-Za-z0-9]+((-|_)[a-z0-9A-Z]+)*$"
23+
>;
24+
}
25+
26+
@armResourceOperations
27+
interface ElasticSans {
28+
/**
29+
* Get a ElasticSan.
30+
*/
31+
get is ArmResourceRead<ElasticSan>;
32+
33+
/**
34+
* Create ElasticSan.
35+
*/
36+
create is ArmResourceCreateOrReplaceAsync<
37+
ElasticSan,
38+
LroHeaders = ArmLroLocationHeader<FinalResult = ElasticSan> &
39+
Azure.Core.Foundations.RetryAfterHeader
40+
>;
41+
42+
/**
43+
* Update a Elastic San.
44+
*/
45+
@patch(#{ implicitOptionality: false })
46+
update is ArmCustomPatchAsync<ElasticSan, PatchModel = ElasticSanUpdate>;
47+
48+
/**
49+
* Delete a Elastic San.
50+
*/
51+
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
52+
delete is ArmResourceDeleteWithoutOkAsync<
53+
ElasticSan,
54+
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
55+
>;
56+
57+
/**
58+
* Gets a list of ElasticSan in a resource group.
59+
*/
60+
listByResourceGroup is ArmResourceListByParent<
61+
ElasticSan,
62+
Response = ArmResponse<ElasticSanList>
63+
>;
64+
65+
/**
66+
* Gets a list of ElasticSans in a subscription
67+
*/
68+
listBySubscription is ArmListBySubscription<
69+
ElasticSan,
70+
Response = ArmResponse<ElasticSanList>
71+
>;
72+
73+
/**
74+
* Gets the private link resources that need to be created for a elastic San.
75+
*/
76+
@get
77+
@action("privateLinkResources")
78+
listByElasticSan is ArmResourceActionSync<
79+
ElasticSan,
80+
void,
81+
ArmResponse<PrivateLinkResourceListResult>
82+
>;
83+
}
84+
85+
@@maxLength(ElasticSan.name, 24);
86+
@@minLength(ElasticSan.name, 3);
87+
@@doc(ElasticSan.name, "The name of the ElasticSan.");
88+
@@doc(ElasticSan.properties, "Properties of ElasticSan.");
89+
@@doc(ElasticSans.create::parameters.resource, "Elastic San object.");
90+
@@doc(ElasticSans.update::parameters.properties, "Elastic San object.");
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "@typespec/openapi";
4+
import "@typespec/rest";
5+
import "./models.tsp";
6+
import "./ElasticSan.tsp";
7+
8+
using TypeSpec.Rest;
9+
using Azure.ResourceManager;
10+
using TypeSpec.Http;
11+
using TypeSpec.OpenAPI;
12+
13+
namespace Microsoft.ElasticSan;
14+
/**
15+
* Response for PrivateEndpoint Connection object
16+
*/
17+
@parentResource(ElasticSan)
18+
model PrivateEndpointConnection
19+
is Azure.ResourceManager.ProxyResource<
20+
PrivateEndpointConnectionProperties,
21+
false
22+
> {
23+
...ResourceNameParameter<
24+
Resource = PrivateEndpointConnection,
25+
KeyName = "privateEndpointConnectionName",
26+
SegmentName = "privateEndpointConnections",
27+
NamePattern = ""
28+
>;
29+
}
30+
31+
@armResourceOperations
32+
interface PrivateEndpointConnections {
33+
/**
34+
* Gets the specified private endpoint connection associated with the Elastic San
35+
*/
36+
get is ArmResourceRead<PrivateEndpointConnection>;
37+
38+
/**
39+
* Update the state of specified private endpoint connection associated with the Elastic San
40+
*/
41+
create is ArmResourceCreateOrReplaceAsync<
42+
PrivateEndpointConnection,
43+
LroHeaders = ArmLroLocationHeader<FinalResult = PrivateEndpointConnection> &
44+
Azure.Core.Foundations.RetryAfterHeader
45+
>;
46+
47+
/**
48+
* Deletes the specified private endpoint connection associated with the Elastic San
49+
*/
50+
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
51+
delete is ArmResourceDeleteWithoutOkAsync<
52+
PrivateEndpointConnection,
53+
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
54+
>;
55+
56+
/**
57+
* List all Private Endpoint Connections associated with the Elastic San.
58+
*/
59+
list is ArmResourceListByParent<PrivateEndpointConnection>;
60+
}
61+
62+
@@doc(PrivateEndpointConnection.name,
63+
"The name of the Private Endpoint connection."
64+
);
65+
@@doc(PrivateEndpointConnection.properties,
66+
"Private Endpoint Connection Properties."
67+
);
68+
@@doc(PrivateEndpointConnections.create::parameters.resource,
69+
"Private Endpoint Connection Approval object."
70+
);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "@typespec/openapi";
4+
import "@typespec/rest";
5+
import "./models.tsp";
6+
import "./VolumeGroup.tsp";
7+
8+
using TypeSpec.Rest;
9+
using Azure.ResourceManager;
10+
using TypeSpec.Http;
11+
using TypeSpec.OpenAPI;
12+
13+
namespace Microsoft.ElasticSan;
14+
/**
15+
* Response for Volume Snapshot request.
16+
*/
17+
@parentResource(VolumeGroup)
18+
model Snapshot
19+
is Azure.ResourceManager.ProxyResource<SnapshotProperties, false> {
20+
...ResourceNameParameter<
21+
Resource = Snapshot,
22+
KeyName = "snapshotName",
23+
SegmentName = "snapshots",
24+
NamePattern = "^[a-z0-9]+(?:[._-][a-z0-9]+)*$"
25+
>;
26+
}
27+
28+
@armResourceOperations
29+
interface Snapshots {
30+
/**
31+
* Get a Volume Snapshot.
32+
*/
33+
get is ArmResourceRead<Snapshot>;
34+
35+
/**
36+
* Create a Volume Snapshot.
37+
*/
38+
create is ArmResourceCreateOrReplaceAsync<
39+
Snapshot,
40+
LroHeaders = ArmLroLocationHeader<FinalResult = Snapshot> &
41+
Azure.Core.Foundations.RetryAfterHeader
42+
>;
43+
44+
/**
45+
* Delete a Volume Snapshot.
46+
*/
47+
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
48+
delete is ArmResourceDeleteWithoutOkAsync<
49+
Snapshot,
50+
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
51+
>;
52+
53+
/**
54+
* List Snapshots in a VolumeGroup or List Snapshots by Volume (name) in a VolumeGroup using filter
55+
*/
56+
listByVolumeGroup is ArmResourceListByParent<
57+
Snapshot,
58+
Parameters = {
59+
/**
60+
* Specify $filter='volumeName eq <volume name>' to filter on volume.
61+
*/
62+
@query("$filter")
63+
$filter?: string;
64+
},
65+
Response = ArmResponse<SnapshotList>
66+
>;
67+
}
68+
69+
@@maxLength(Snapshot.name, 80);
70+
@@minLength(Snapshot.name, 1);
71+
@@doc(Snapshot.name,
72+
"The name of the volume snapshot within the given volume group."
73+
);
74+
@@doc(Snapshot.properties, "Properties of Volume Snapshot.");
75+
@@doc(Snapshots.create::parameters.resource, "Snapshot object.");
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import "@azure-tools/typespec-azure-core";
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "@azure-tools/typespec-client-generator-core";
4+
import "@typespec/openapi";
5+
import "@typespec/rest";
6+
import "./models.tsp";
7+
import "./VolumeGroup.tsp";
8+
9+
using TypeSpec.Rest;
10+
using Azure.ResourceManager;
11+
using TypeSpec.Http;
12+
using Azure.ClientGenerator.Core;
13+
14+
namespace Microsoft.ElasticSan;
15+
/**
16+
* Response for Volume request.
17+
*/
18+
@parentResource(VolumeGroup)
19+
model Volume is Azure.ResourceManager.ProxyResource<VolumeProperties, false> {
20+
...ResourceNameParameter<
21+
Resource = Volume,
22+
KeyName = "volumeName",
23+
SegmentName = "volumes",
24+
NamePattern = "^[a-z0-9]+(-[a-z0-9A-Z]+)*$"
25+
>;
26+
}
27+
28+
@armResourceOperations
29+
interface Volumes {
30+
/**
31+
* Get an Volume.
32+
*/
33+
get is ArmResourceRead<Volume>;
34+
35+
/**
36+
* Create a Volume.
37+
*/
38+
create is ArmResourceCreateOrReplaceAsync<
39+
Volume,
40+
LroHeaders = ArmLroLocationHeader<FinalResult = Volume> &
41+
Azure.Core.Foundations.RetryAfterHeader
42+
>;
43+
44+
/**
45+
* Update an Volume.
46+
*/
47+
@patch(#{ implicitOptionality: false })
48+
update is ArmCustomPatchAsync<Volume, PatchModel = VolumeUpdate>;
49+
50+
/**
51+
* Delete an Volume.
52+
*/
53+
#suppress "@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
54+
delete is ArmResourceDeleteWithoutOkAsync<
55+
Volume,
56+
Parameters = {
57+
/**
58+
* Optional, used to delete snapshots under volume. Allowed value are only true or false. Default value is false.
59+
*/
60+
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
61+
@header
62+
@clientName("deleteSnapshots", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
63+
`x-ms-delete-snapshots`?: `x-ms-delete-snapshots`;
64+
65+
/**
66+
* Optional, used to delete volume if active sessions present. Allowed value are only true or false. Default value is false.
67+
*/
68+
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
69+
@header
70+
@clientName("forceDelete", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
71+
`x-ms-force-delete`?: `x-ms-force-delete`;
72+
73+
/**
74+
* Optional. Specifies that the delete operation should be a permanent delete for the soft deleted volume. The value of deleteType can only be 'permanent'.
75+
*/
76+
@query("deleteType")
77+
deleteType?: DeleteType;
78+
},
79+
Response = ArmDeletedResponse | ArmDeleteAcceptedLroResponse | ArmDeletedNoContentResponse
80+
>;
81+
82+
/**
83+
* List Volumes in a VolumeGroup.
84+
*/
85+
listByVolumeGroup is ArmResourceListByParent<
86+
Volume,
87+
Parameters = {
88+
/**
89+
* Optional, returns only soft deleted volumes if set to true. If set to false or if not specified, returns only active volumes.
90+
*/
91+
#suppress "@azure-tools/typespec-azure-core/casing-style" "FIXME: Update justification, follow aka.ms/tsp/conversion-fix for details"
92+
@header
93+
@clientName("accessSoftDeletedResources", "csharp") // this could be temporary because we cannot reference this parameter through ::parameter syntax.
94+
`x-ms-access-soft-deleted-resources`?: `x-ms-access-soft-deleted-resources`;
95+
},
96+
Response = ArmResponse<VolumeList>
97+
>;
98+
}
99+
100+
/**
101+
* Restore Soft Deleted Volumes. The volume name is obtained by using the API to list soft deleted volumes by volume group
102+
*/
103+
@action("restore")
104+
@tag("RestoreVolumes")
105+
op restoreVolume is ArmResourceActionAsync<Volume, void, Volume>;
106+
107+
@@maxLength(Volume.name, 63);
108+
@@minLength(Volume.name, 3);
109+
@@doc(Volume.name, "The name of the Volume.");
110+
@@doc(Volume.properties, "Properties of Volume.");
111+
@@doc(Volumes.create::parameters.resource, "Volume object.");
112+
@@doc(Volumes.update::parameters.properties, "Volume object.");

0 commit comments

Comments
 (0)