Skip to content

Commit 43d095c

Browse files
authored
tsp - Add clientname support for body parameter (#1518)
1 parent e39ad19 commit 43d095c

File tree

33 files changed

+237
-264
lines changed

33 files changed

+237
-264
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ function createBodyParameter(psContext: SdkContext, parameter: HttpOperationBody
365365
const paramSchema = parameter.property?.sourceProperty
366366
? getSchemaForType(psContext, parameter.property?.sourceProperty?.type)
367367
: getSchemaForType(psContext, parameter.type)
368-
const newParameter = new Parameter(parameter.property?.name || "", parameter.property ? getDoc(psContext.program, parameter.property) || "" : "", paramSchema);
368+
const paramName = parameter.property ? (getClientNameOverride(psContext, parameter.property) || parameter.property.name || "") : "";
369+
const newParameter = new Parameter(paramName, parameter.property ? getDoc(psContext.program, parameter.property) || "" : "", paramSchema);
369370
newParameter.protocol.http = newParameter.protocol.http ?? new Protocol();
370371
newParameter.protocol.http.in = "body";
371372
// ToDo, we need to support x-ms-client is specified.

packages/typespec-powershell/src/utils/modelUtils.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import {
4747
getLifecycleVisibilityEnum,
4848
getVisibilityForClass,
4949
} from "@typespec/compiler";
50-
import { SdkContext, isReadOnly, getWireName } from "@azure-tools/typespec-client-generator-core";
50+
import { SdkContext, isReadOnly, getWireName, getClientNameOverride } from "@azure-tools/typespec-client-generator-core";
5151

5252
import { reportDiagnostic } from "../lib.js";
5353
import { AnySchema, SealedChoiceSchema, ChoiceSchema, ChoiceValue, SchemaType, ArraySchema, Schema, DictionarySchema, ObjectSchema, Discriminator as M4Discriminator, Property, StringSchema, NumberSchema, ConstantSchema, ConstantValue, BooleanSchema } from "@autorest/codemodel";
@@ -521,6 +521,9 @@ function getSchemaForUnion(
521521
//Yabo: how to deal with x-nullable?
522522
const nullable = union.variants.size !== nonNullOptions.length;
523523
schema = getSchemaForType(dpgContext, nonNullOptions[0], options);
524+
if (nonNullOptions[0].kind === "Model" && isRecordModelType(dpgContext.program, nonNullOptions[0]) && nonNullOptions[0].name === "Record") {
525+
return { ...schema };
526+
}
524527
} else {
525528
const values = [];
526529
const [asEnum, _] = getUnionAsEnum(union);
@@ -740,8 +743,9 @@ function getSchemaForModel(
740743
}
741744

742745
const program = dpgContext.program;
743-
const overridedModelName =
746+
const overridedModelName = getClientNameOverride(dpgContext, model) ??
744747
getFriendlyName(program, model) ?? getWireName(dpgContext, model);
748+
745749
const fullNamespaceName =
746750
overridedModelName ??
747751
getModelNamespaceName(dpgContext, model.namespace!)

tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/.gitignore

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/cmdlets/NewAzAppComplianceAutomationEvidence_CreateExpanded.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
4242
private object _firstResponse = null;
4343

4444
/// <summary>A class represent an AppComplianceAutomation evidence resource.</summary>
45-
private Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IEvidenceResource _resourceBody = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.EvidenceResource();
45+
private Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IEvidenceResource _propertiesBody = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.EvidenceResource();
4646

4747
/// <summary>
4848
/// A flag to tell whether it is the first returned object in a call. Zero means no response yet. One means 1 returned object.
@@ -70,7 +70,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
7070
Description = @"Control id.",
7171
SerializedName = @"controlId",
7272
PossibleTypes = new [] { typeof(string) })]
73-
public string ControlId { get => _resourceBody.ControlId ?? null; set => _resourceBody.ControlId = value; }
73+
public string ControlId { get => _propertiesBody.ControlId ?? null; set => _propertiesBody.ControlId = value; }
7474

7575
/// <summary>
7676
/// The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet
@@ -92,7 +92,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
9292
SerializedName = @"evidenceType",
9393
PossibleTypes = new [] { typeof(string) })]
9494
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PSArgumentCompleterAttribute("File", "AutoCollectedEvidence", "Data")]
95-
public string EvidenceType { get => _resourceBody.EvidenceType ?? null; set => _resourceBody.EvidenceType = value; }
95+
public string EvidenceType { get => _propertiesBody.EvidenceType ?? null; set => _propertiesBody.EvidenceType = value; }
9696

9797
/// <summary>Accessor for extensibleParameters.</summary>
9898
public global::System.Collections.Generic.IDictionary<global::System.String,global::System.Object> ExtensibleParameters { get => _extensibleParameters ; }
@@ -106,7 +106,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
106106
Description = @"Extra data considered as evidence.",
107107
SerializedName = @"extraData",
108108
PossibleTypes = new [] { typeof(string) })]
109-
public string ExtraData { get => _resourceBody.ExtraData ?? null; set => _resourceBody.ExtraData = value; }
109+
public string ExtraData { get => _propertiesBody.ExtraData ?? null; set => _propertiesBody.ExtraData = value; }
110110

111111
/// <summary>The path of the file in storage.</summary>
112112
[global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "The path of the file in storage.")]
@@ -117,7 +117,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
117117
Description = @"The path of the file in storage.",
118118
SerializedName = @"filePath",
119119
PossibleTypes = new [] { typeof(string) })]
120-
public string FilePath { get => _resourceBody.FilePath ?? null; set => _resourceBody.FilePath = value; }
120+
public string FilePath { get => _propertiesBody.FilePath ?? null; set => _propertiesBody.FilePath = value; }
121121

122122
/// <summary>SendAsync Pipeline Steps to be appended to the front of the pipeline</summary>
123123
[global::System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "SendAsync Pipeline Steps to be appended to the front of the pipeline")]
@@ -229,7 +229,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateExpanded : globa
229229
Description = @"Responsibility id.",
230230
SerializedName = @"responsibilityId",
231231
PossibleTypes = new [] { typeof(string) })]
232-
public string ResponsibilityId { get => _resourceBody.ResponsibilityId ?? null; set => _resourceBody.ResponsibilityId = value; }
232+
public string ResponsibilityId { get => _propertiesBody.ResponsibilityId ?? null; set => _propertiesBody.ResponsibilityId = value; }
233233

234234
/// <summary>
235235
/// <c>overrideOnCreated</c> will be called before the regular onCreated has been processed, allowing customization of what
@@ -460,7 +460,7 @@ protected override void ProcessRecord()
460460
try
461461
{
462462
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; }
463-
await this.Client.EvidenceCreateOrUpdate(ReportName, Name, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _resourceBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
463+
await this.Client.EvidenceCreateOrUpdate(ReportName, Name, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _propertiesBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
464464
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; }
465465
}
466466
catch (Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.UndeclaredResponseException urexception)

tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/cmdlets/NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpanded.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
4242
private object _firstResponse = null;
4343

4444
/// <summary>A class represent an AppComplianceAutomation evidence resource.</summary>
45-
private Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IEvidenceResource _resourceBody = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.EvidenceResource();
45+
private Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IEvidenceResource _propertiesBody = new Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.EvidenceResource();
4646

4747
/// <summary>
4848
/// A flag to tell whether it is the first returned object in a call. Zero means no response yet. One means 1 returned object.
@@ -70,7 +70,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
7070
Description = @"Control id.",
7171
SerializedName = @"controlId",
7272
PossibleTypes = new [] { typeof(string) })]
73-
public string ControlId { get => _resourceBody.ControlId ?? null; set => _resourceBody.ControlId = value; }
73+
public string ControlId { get => _propertiesBody.ControlId ?? null; set => _propertiesBody.ControlId = value; }
7474

7575
/// <summary>
7676
/// The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet
@@ -92,7 +92,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
9292
SerializedName = @"evidenceType",
9393
PossibleTypes = new [] { typeof(string) })]
9494
[global::Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PSArgumentCompleterAttribute("File", "AutoCollectedEvidence", "Data")]
95-
public string EvidenceType { get => _resourceBody.EvidenceType ?? null; set => _resourceBody.EvidenceType = value; }
95+
public string EvidenceType { get => _propertiesBody.EvidenceType ?? null; set => _propertiesBody.EvidenceType = value; }
9696

9797
/// <summary>Accessor for extensibleParameters.</summary>
9898
public global::System.Collections.Generic.IDictionary<global::System.String,global::System.Object> ExtensibleParameters { get => _extensibleParameters ; }
@@ -106,7 +106,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
106106
Description = @"Extra data considered as evidence.",
107107
SerializedName = @"extraData",
108108
PossibleTypes = new [] { typeof(string) })]
109-
public string ExtraData { get => _resourceBody.ExtraData ?? null; set => _resourceBody.ExtraData = value; }
109+
public string ExtraData { get => _propertiesBody.ExtraData ?? null; set => _propertiesBody.ExtraData = value; }
110110

111111
/// <summary>The path of the file in storage.</summary>
112112
[global::System.Management.Automation.Parameter(Mandatory = true, HelpMessage = "The path of the file in storage.")]
@@ -117,7 +117,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
117117
Description = @"The path of the file in storage.",
118118
SerializedName = @"filePath",
119119
PossibleTypes = new [] { typeof(string) })]
120-
public string FilePath { get => _resourceBody.FilePath ?? null; set => _resourceBody.FilePath = value; }
120+
public string FilePath { get => _propertiesBody.FilePath ?? null; set => _propertiesBody.FilePath = value; }
121121

122122
/// <summary>SendAsync Pipeline Steps to be appended to the front of the pipeline</summary>
123123
[global::System.Management.Automation.Parameter(Mandatory = false, DontShow = true, HelpMessage = "SendAsync Pipeline Steps to be appended to the front of the pipeline")]
@@ -208,7 +208,7 @@ public partial class NewAzAppComplianceAutomationEvidence_CreateViaIdentityExpan
208208
Description = @"Responsibility id.",
209209
SerializedName = @"responsibilityId",
210210
PossibleTypes = new [] { typeof(string) })]
211-
public string ResponsibilityId { get => _resourceBody.ResponsibilityId ?? null; set => _resourceBody.ResponsibilityId = value; }
211+
public string ResponsibilityId { get => _propertiesBody.ResponsibilityId ?? null; set => _propertiesBody.ResponsibilityId = value; }
212212

213213
/// <summary>
214214
/// <c>overrideOnCreated</c> will be called before the regular onCreated has been processed, allowing customization of what
@@ -442,7 +442,7 @@ protected override void ProcessRecord()
442442
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; }
443443
if (InputObject?.Id != null)
444444
{
445-
await this.Client.EvidenceCreateOrUpdateViaIdentity(InputObject.Id, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _resourceBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
445+
await this.Client.EvidenceCreateOrUpdateViaIdentity(InputObject.Id, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _propertiesBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
446446
}
447447
else
448448
{
@@ -455,7 +455,7 @@ protected override void ProcessRecord()
455455
{
456456
ThrowTerminatingError( new global::System.Management.Automation.ErrorRecord(new global::System.Exception("InputObject has null value for InputObject.EvidenceName"),string.Empty, global::System.Management.Automation.ErrorCategory.InvalidArgument, InputObject) );
457457
}
458-
await this.Client.EvidenceCreateOrUpdate(InputObject.ReportName ?? null, InputObject.EvidenceName ?? null, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _resourceBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
458+
await this.Client.EvidenceCreateOrUpdate(InputObject.ReportName ?? null, InputObject.EvidenceName ?? null, this.InvocationInformation.BoundParameters.ContainsKey("OfferGuid") ? OfferGuid : null, this.InvocationInformation.BoundParameters.ContainsKey("ReportCreatorTenantId") ? ReportCreatorTenantId : null, _propertiesBody, onOk, onCreated, onDefault, this, Pipeline, Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.SerializationMode.IncludeCreate);
459459
}
460460
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; }
461461
}

0 commit comments

Comments
 (0)