-
Notifications
You must be signed in to change notification settings - Fork 77
Using ARM ResourceInstanceParameters with proper return type handling #3458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
v-jiaodi
wants to merge
1
commit into
Azure:main
Choose a base branch
from
v-jiaodi:crate-ut-for-hardwaresecuritymodules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
145 changes: 145 additions & 0 deletions
145
...c-ts/test/modularUnit/scenarios/apiOperations/cloudHsmClusterBackupStatusArm.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
# CloudHSM Cluster Backup Status Get Operation with ARM ResourceInstanceParameters | ||
|
||
Should generate correct operation for getting backup status using ARM ResourceInstanceParameters with proper return type handling. | ||
|
||
## TypeSpec | ||
|
||
This is the TypeSpec definition for CloudHSM cluster backup status operation using ARM patterns. | ||
|
||
```tsp | ||
import "@typespec/http"; | ||
import "@typespec/rest"; | ||
import "@typespec/versioning"; | ||
import "@azure-tools/typespec-azure-core"; | ||
import "@azure-tools/typespec-azure-resource-manager"; | ||
|
||
using TypeSpec.Http; | ||
using TypeSpec.Rest; | ||
using TypeSpec.Versioning; | ||
using Azure.Core; | ||
using Azure.ResourceManager; | ||
|
||
@armProviderNamespace | ||
@service(#{ title: "HardwareSecurityModules" }) | ||
@versioned(Versions) | ||
@armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) | ||
namespace Microsoft.HardwareSecurityModules; | ||
|
||
enum Versions { | ||
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) | ||
@useDependency(Azure.Core.Versions.v1_0_Preview_1) | ||
v2021_10_01_preview: "2021-10-01-preview", | ||
} | ||
|
||
model BackupResult { | ||
properties?: BackupResultProperties; | ||
} | ||
|
||
model BackupResultProperties { | ||
azureStorageBlobContainerUri?: string; | ||
backupId?: string; | ||
status?: string; | ||
statusDetails?: string; | ||
startTime?: utcDateTime; | ||
endTime?: utcDateTime; | ||
} | ||
|
||
op get( | ||
@path subscriptionId: string, | ||
@path resourceGroupName: string, | ||
@path cloudHsmClusterName: string, | ||
@path jobId: string, | ||
): (BackupResult & | ||
Azure.Core.RequestIdResponseHeader) | ArmAcceptedResponse<ExtraHeaders = { | ||
@header("Location") | ||
@doc("The Location header contains the URL where the status of the long running operation can be checked.") | ||
location?: string; | ||
} & Azure.Core.RequestIdResponseHeader> | ErrorResponse;; | ||
``` | ||
|
||
The config would be like: | ||
|
||
```yaml | ||
withRawContent: true | ||
``` | ||
|
||
## Operations | ||
|
||
Should generate operations correctly with proper ARM pattern handling: | ||
|
||
```ts operations | ||
import { HardwareSecurityModulesContext as Client } from "./index.js"; | ||
import { | ||
BackupResult, | ||
backupResultDeserializer, | ||
errorResponseDeserializer, | ||
} from "../models/models.js"; | ||
import { expandUrlTemplate } from "../static-helpers/urlTemplate.js"; | ||
import { GetOptionalParams } from "./options.js"; | ||
import { | ||
StreamableMethod, | ||
PathUncheckedResponse, | ||
createRestError, | ||
operationOptionsToRequestParameters, | ||
} from "@azure-rest/core-client"; | ||
|
||
export function _getSend( | ||
context: Client, | ||
resourceGroupName: string, | ||
cloudHsmClusterName: string, | ||
jobId: string, | ||
options: GetOptionalParams = { requestOptions: {} }, | ||
): StreamableMethod { | ||
const path = expandUrlTemplate( | ||
"/{subscriptionId}/{resourceGroupName}/{cloudHsmClusterName}/{jobId}", | ||
{ | ||
subscriptionId: context.subscriptionId, | ||
resourceGroupName: resourceGroupName, | ||
cloudHsmClusterName: cloudHsmClusterName, | ||
jobId: jobId, | ||
}, | ||
{ | ||
allowReserved: options?.requestOptions?.skipUrlEncoding, | ||
}, | ||
); | ||
return context | ||
.path(path) | ||
.get({ | ||
...operationOptionsToRequestParameters(options), | ||
headers: { | ||
accept: "application/json", | ||
...options.requestOptions?.headers, | ||
}, | ||
}); | ||
} | ||
|
||
export async function _getDeserialize( | ||
result: PathUncheckedResponse, | ||
): Promise<BackupResult> { | ||
const expectedStatuses = ["200", "202"]; | ||
if (!expectedStatuses.includes(result.status)) { | ||
const error = createRestError(result); | ||
error.details = errorResponseDeserializer(result.body); | ||
throw error; | ||
} | ||
|
||
return backupResultDeserializer(result.body); | ||
} | ||
|
||
export async function get( | ||
context: Client, | ||
resourceGroupName: string, | ||
cloudHsmClusterName: string, | ||
jobId: string, | ||
options: GetOptionalParams = { requestOptions: {} }, | ||
): Promise<BackupResult | null> { | ||
const result = await _getSend( | ||
context, | ||
resourceGroupName, | ||
cloudHsmClusterName, | ||
jobId, | ||
options, | ||
); | ||
return _getDeserialize(result); | ||
} | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pending issue: Azure/typespec-azure#3302