Skip to content

Commit

Permalink
tsp - use operationId specified by the decorator @operationid
Browse files Browse the repository at this point in the history
  • Loading branch information
dolauli committed Jan 17, 2025
1 parent f77faf1 commit 4cf4e6a
Show file tree
Hide file tree
Showing 9 changed files with 1,106 additions and 1,098 deletions.
14 changes: 12 additions & 2 deletions packages/typespec-powershell/src/convertor/convertor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { stat } from "fs";
import { extractPagedMetadataNested } from "../utils/operationUtil.js";
import { parseNextLinkName } from "../utils/operationUtil.js";
import { getLroMetadata } from "@azure-tools/typespec-azure-core";
import { getOperationId } from "@typespec/openapi";

const GlobalParameter = "global-parameter";

Expand Down Expand Up @@ -163,9 +164,18 @@ function getOperationGroups(program: Program, client: SdkClient, psContext: SdkC
return operationGroups;
}

function resolveOperationId(psContext: SdkContext, op: HttpOperation, operationGroup: OperationGroup): string {
const explicitOperationId = getOperationId(psContext.program, op.operation);
if (explicitOperationId) {
return explicitOperationId;
}
return operationGroup.$key + "_" + pascalCase(op.operation.name);
}

function addOperation(psContext: SdkContext, op: HttpOperation, operationGroup: OperationGroup, model: PwshModel) {
const newOperation = new Operation(pascalCase(op.operation.name), getDoc(psContext.program, op.operation) ?? "");
newOperation.operationId = operationGroup.$key + "_" + pascalCase(op.operation.name);
const operationId = resolveOperationId(psContext, op, operationGroup);
const newOperation = new Operation( operationId.split('_')[1] ?? pascalCase(op.operation.name), getDoc(psContext.program, op.operation) ?? "");
newOperation.operationId = operationId;
// Add Api versions
newOperation.apiVersions = newOperation.apiVersions || [];
newOperation.apiVersions.push({ version: getEnrichedDefaultApiVersion(psContext.program, psContext) || "" });
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Cmdlets
/// Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.
/// </summary>
/// <remarks>
/// [OpenAPI] CheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// [OpenAPI] NestedResourceCheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// </remarks>
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReportNameAvailability_Check", SupportsShouldProcess = true)]
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReport_Check", SupportsShouldProcess = true)]
[global::System.Management.Automation.OutputType(typeof(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ICheckNameAvailabilityResponse))]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Description(@"Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.")]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Generated]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.HttpPath(Path = "/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability", ApiVersion = "2024-06-27")]
public partial class TestAzAppComplianceAutomationReportNameAvailability_Check : global::System.Management.Automation.PSCmdlet,
public partial class TestAzAppComplianceAutomationReport_Check : global::System.Management.Automation.PSCmdlet,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IContext
{
Expand Down Expand Up @@ -110,6 +110,21 @@ public partial class TestAzAppComplianceAutomationReportNameAvailability_Check :
/// <summary><see cref="Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener" /> cancellation token.</summary>
global::System.Threading.CancellationToken Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener.Token => _cancellationTokenSource.Token;

/// <summary>Backing field for <see cref="Name" /> property.</summary>
private string _name;

/// <summary>Report Name.</summary>
[global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Report Name.")]
[Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Info(
Required = true,
ReadOnly = false,
Description = @"Report Name.",
SerializedName = @"reportName",
PossibleTypes = new [] { typeof(string) })]
[global::System.Management.Automation.Alias("ReportName")]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Category(global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.ParameterCategory.Path)]
public string Name { get => this._name; set => this._name = value; }

/// <summary>
/// The instance of the <see cref="Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.HttpPipeline" /> that the remote call will use.
/// </summary>
Expand All @@ -131,20 +146,6 @@ public partial class TestAzAppComplianceAutomationReportNameAvailability_Check :
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Category(global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.ParameterCategory.Runtime)]
public global::System.Management.Automation.SwitchParameter ProxyUseDefaultCredentials { get; set; }

/// <summary>Backing field for <see cref="ReportName" /> property.</summary>
private string _reportName;

/// <summary>Report Name.</summary>
[global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "Report Name.")]
[Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Info(
Required = true,
ReadOnly = false,
Description = @"Report Name.",
SerializedName = @"reportName",
PossibleTypes = new [] { typeof(string) })]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Category(global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.ParameterCategory.Path)]
public string ReportName { get => this._reportName; set => this._reportName = value; }

/// <summary>
/// <c>overrideOnDefault</c> will be called before the regular onDefault has been processed, allowing customization of what
/// happens on that response. Implement this method in a partial class to enable this behavior
Expand Down Expand Up @@ -302,7 +303,7 @@ protected override void ProcessRecord()
try
{
// work
if (ShouldProcess($"Call remote 'ReportCheckNameAvailability' operation"))
if (ShouldProcess($"Call remote 'ReportNestedResourceCheckNameAvailability' operation"))
{
using( var asyncCommandRuntime = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.PowerShell.AsyncCommandRuntime(this, ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token) )
{
Expand Down Expand Up @@ -354,12 +355,12 @@ protected override void ProcessRecord()
try
{
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletBeforeAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
await this.Client.ReportCheckNameAvailability(ReportName, Body, onOk, onDefault, this, Pipeline);
await this.Client.ReportNestedResourceCheckNameAvailability(Name, Body, onOk, onDefault, this, Pipeline);
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletAfterAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
}
catch (Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.UndeclaredResponseException urexception)
{
WriteError(new global::System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { ReportName=ReportName})
WriteError(new global::System.Management.Automation.ErrorRecord(urexception, urexception.StatusCode.ToString(), global::System.Management.Automation.ErrorCategory.InvalidOperation, new { Name=Name})
{
ErrorDetails = new global::System.Management.Automation.ErrorDetails(urexception.Message) { RecommendedAction = urexception.Action }
});
Expand All @@ -379,9 +380,9 @@ protected override void StopProcessing()
}

/// <summary>
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReportNameAvailability_Check" /> cmdlet class.
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReport_Check" /> cmdlet class.
/// </summary>
public TestAzAppComplianceAutomationReportNameAvailability_Check()
public TestAzAppComplianceAutomationReport_Check()
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Cmdlets
/// Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.
/// </summary>
/// <remarks>
/// [OpenAPI] CheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// [OpenAPI] NestedResourceCheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// </remarks>
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReportNameAvailability_CheckExpanded", SupportsShouldProcess = true)]
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReport_CheckExpanded", SupportsShouldProcess = true)]
[global::System.Management.Automation.OutputType(typeof(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ICheckNameAvailabilityResponse))]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Description(@"Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.")]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Generated]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.HttpPath(Path = "/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability", ApiVersion = "2024-06-27")]
public partial class TestAzAppComplianceAutomationReportNameAvailability_CheckExpanded : global::System.Management.Automation.PSCmdlet,
public partial class TestAzAppComplianceAutomationReport_CheckExpanded : global::System.Management.Automation.PSCmdlet,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IContext
{
Expand Down Expand Up @@ -313,7 +313,7 @@ protected override void ProcessRecord()
try
{
// work
if (ShouldProcess($"Call remote 'ReportCheckNameAvailability' operation"))
if (ShouldProcess($"Call remote 'ReportNestedResourceCheckNameAvailability' operation"))
{
using( var asyncCommandRuntime = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.PowerShell.AsyncCommandRuntime(this, ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token) )
{
Expand Down Expand Up @@ -365,7 +365,7 @@ protected override void ProcessRecord()
try
{
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletBeforeAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
await this.Client.ReportCheckNameAvailability(ReportName, _body, onOk, onDefault, this, Pipeline);
await this.Client.ReportNestedResourceCheckNameAvailability(ReportName, _body, onOk, onDefault, this, Pipeline);
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletAfterAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
}
catch (Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.UndeclaredResponseException urexception)
Expand All @@ -390,10 +390,9 @@ protected override void StopProcessing()
}

/// <summary>
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReportNameAvailability_CheckExpanded" /> cmdlet
/// class.
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReport_CheckExpanded" /> cmdlet class.
/// </summary>
public TestAzAppComplianceAutomationReportNameAvailability_CheckExpanded()
public TestAzAppComplianceAutomationReport_CheckExpanded()
{

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Cmdlets
/// Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.
/// </summary>
/// <remarks>
/// [OpenAPI] CheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// [OpenAPI] NestedResourceCheckNameAvailability=>POST:"/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability"
/// </remarks>
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReportNameAvailability_CheckViaIdentity", SupportsShouldProcess = true)]
[global::System.Management.Automation.Cmdlet(global::System.Management.Automation.VerbsDiagnostic.Test, @"AzAppComplianceAutomationReport_CheckViaIdentity", SupportsShouldProcess = true)]
[global::System.Management.Automation.OutputType(typeof(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.ICheckNameAvailabilityResponse))]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Description(@"Checks the report's nested resource name availability, e.g: Webhooks, Evidences, Snapshots.")]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Generated]
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.HttpPath(Path = "/providers/Microsoft.AppComplianceAutomation/reports/{reportName}/checkNameAvailability", ApiVersion = "2024-06-27")]
public partial class TestAzAppComplianceAutomationReportNameAvailability_CheckViaIdentity : global::System.Management.Automation.PSCmdlet,
public partial class TestAzAppComplianceAutomationReport_CheckViaIdentity : global::System.Management.Automation.PSCmdlet,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener,
Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IContext
{
Expand Down Expand Up @@ -296,7 +296,7 @@ protected override void ProcessRecord()
try
{
// work
if (ShouldProcess($"Call remote 'ReportCheckNameAvailability' operation"))
if (ShouldProcess($"Call remote 'ReportNestedResourceCheckNameAvailability' operation"))
{
using( var asyncCommandRuntime = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.PowerShell.AsyncCommandRuntime(this, ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token) )
{
Expand Down Expand Up @@ -350,7 +350,7 @@ protected override void ProcessRecord()
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletBeforeAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
if (InputObject?.Id != null)
{
await this.Client.ReportCheckNameAvailabilityViaIdentity(InputObject.Id, Body, onOk, onDefault, this, Pipeline);
await this.Client.ReportNestedResourceCheckNameAvailabilityViaIdentity(InputObject.Id, Body, onOk, onDefault, this, Pipeline);
}
else
{
Expand All @@ -359,7 +359,7 @@ protected override void ProcessRecord()
{
ThrowTerminatingError( new global::System.Management.Automation.ErrorRecord(new global::System.Exception("InputObject has null value for InputObject.ReportName"),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, InputObject) );
}
await this.Client.ReportCheckNameAvailability(InputObject.ReportName ?? null, Body, onOk, onDefault, this, Pipeline);
await this.Client.ReportNestedResourceCheckNameAvailability(InputObject.ReportName ?? null, Body, onOk, onDefault, this, Pipeline);
}
await ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Signal(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Events.CmdletAfterAPICall); if( ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IEventListener)this).Token.IsCancellationRequested ) { return; }
}
Expand All @@ -385,10 +385,9 @@ protected override void StopProcessing()
}

/// <summary>
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReportNameAvailability_CheckViaIdentity" />
/// cmdlet class.
/// Initializes a new instance of the <see cref="TestAzAppComplianceAutomationReport_CheckViaIdentity" /> cmdlet class.
/// </summary>
public TestAzAppComplianceAutomationReportNameAvailability_CheckViaIdentity()
public TestAzAppComplianceAutomationReport_CheckViaIdentity()
{

}
Expand Down
Loading

0 comments on commit 4cf4e6a

Please sign in to comment.