diff --git a/packages/typespec-powershell/src/convertor/convertor.ts b/packages/typespec-powershell/src/convertor/convertor.ts index 87f19d0a69..379c6bdce5 100644 --- a/packages/typespec-powershell/src/convertor/convertor.ts +++ b/packages/typespec-powershell/src/convertor/convertor.ts @@ -260,18 +260,28 @@ function addResponses(psContext: SdkContext, op: HttpOperation, newOperation: Op (newResponse).schema = schema; } // Add headers + // we merge headers here, if the same header is defined in multiple responses, we only add it once. + // This is aligned with the behavior of typescript emitter and typespec-autorest emitter. newResponse.protocol.http = newResponse.protocol.http ?? new Protocol(); - if (response.responses[0].headers) { - for (const key in response.responses[0].headers) { - newResponse.protocol.http.headers = newResponse.protocol.http.headers || []; - const header = response.responses[0].headers[key]; - const headerSchema = getSchemaForType(psContext, header.type); - const headerResponse = new HttpHeader(key, headerSchema); - headerResponse.language = new Languages(); - headerResponse.language.default = new Language(); - headerResponse.language.default.description = getDoc(psContext.program, header) || ""; - headerResponse.language.default.name = pascalCase(deconstruct(key)); - newResponse.protocol.http.headers.push(headerResponse); + const addedKeys: string[] = []; + for (const innerResponse of response.responses) { + if (innerResponse.headers) { + for (const key in innerResponse.headers) { + if (addedKeys.includes(key)) { + continue; + } else { + addedKeys.push(key); + } + newResponse.protocol.http.headers = newResponse.protocol.http.headers || []; + const header = innerResponse.headers[key]; + const headerSchema = getSchemaForType(psContext, header.type); + const headerResponse = new HttpHeader(key, headerSchema); + headerResponse.language = new Languages(); + headerResponse.language.default = new Language(); + headerResponse.language.default.description = getDoc(psContext.program, header) || ""; + headerResponse.language.default.name = pascalCase(deconstruct(key)); + newResponse.protocol.http.headers.push(headerResponse); + } } } newResponse.protocol.http.statusCodes = statusCode === "*" ? ["default"] : [statusCode]; diff --git a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.PowerShell.cs b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.PowerShell.cs index 0c77be6651..a608148e07 100644 --- a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.PowerShell.cs +++ b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.PowerShell.cs @@ -115,6 +115,10 @@ internal ProviderActionsOnboardAcceptedResponseHeaders(global::System.Collection { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).Location, global::System.Convert.ToString); } + if (content.Contains("RetryAfter")) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).RetryAfter = (int?) content.GetValueForProperty("RetryAfter",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).RetryAfter, (__y)=> (int) global::System.Convert.ChangeType(__y, typeof(int))); + } AfterDeserializeDictionary(content); } @@ -136,6 +140,10 @@ internal ProviderActionsOnboardAcceptedResponseHeaders(global::System.Management { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).Location, global::System.Convert.ToString); } + if (content.Contains("RetryAfter")) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).RetryAfter = (int?) content.GetValueForProperty("RetryAfter",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).RetryAfter, (__y)=> (int) global::System.Convert.ChangeType(__y, typeof(int))); + } AfterDeserializePSObject(content); } diff --git a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.cs b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.cs index 98c332b5f6..42b14b6b3d 100644 --- a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.cs +++ b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsOnboardAcceptedResponseHeaders.cs @@ -17,6 +17,12 @@ public partial class ProviderActionsOnboardAcceptedResponseHeaders : [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Origin(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PropertyOrigin.Owned)] public string Location { get => this._location; set => this._location = value; } + /// Backing field for property. + private int? _retryAfter; + + [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Origin(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PropertyOrigin.Owned)] + public int? RetryAfter { get => this._retryAfter; set => this._retryAfter = value; } + /// void Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IHeaderSerializable.ReadHeaders(global::System.Net.Http.Headers.HttpResponseHeaders headers) { @@ -24,6 +30,10 @@ void Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IHeaderS { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).Location = System.Linq.Enumerable.FirstOrDefault(__locationHeader0) is string __headerLocationHeader0 ? __headerLocationHeader0 : (string)null; } + if (headers.TryGetValues("Retry-After", out var __retryAfterHeader1)) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsOnboardAcceptedResponseHeadersInternal)this).RetryAfter = System.Linq.Enumerable.FirstOrDefault(__retryAfterHeader1) is string __headerRetryAfterHeader1 ? int.TryParse( __headerRetryAfterHeader1, out int __headerRetryAfterHeader1Value ) ? __headerRetryAfterHeader1Value : default(int?) : default(int?); + } } /// @@ -48,11 +58,24 @@ public partial interface IProviderActionsOnboardAcceptedResponseHeaders PossibleTypes = new [] { typeof(string) })] string Location { get; set; } + [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Info( + Required = false, + ReadOnly = false, + Read = true, + Create = true, + Update = true, + Description = @"", + SerializedName = @"Retry-After", + PossibleTypes = new [] { typeof(int) })] + int? RetryAfter { get; set; } + } internal partial interface IProviderActionsOnboardAcceptedResponseHeadersInternal { string Location { get; set; } + int? RetryAfter { get; set; } + } } \ No newline at end of file diff --git a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.PowerShell.cs b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.PowerShell.cs index e79c2dcfed..e4a2241029 100644 --- a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.PowerShell.cs +++ b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.PowerShell.cs @@ -115,6 +115,10 @@ internal ProviderActionsTriggerEvaluationAcceptedResponseHeaders(global::System. { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).Location, global::System.Convert.ToString); } + if (content.Contains("RetryAfter")) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).RetryAfter = (int?) content.GetValueForProperty("RetryAfter",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).RetryAfter, (__y)=> (int) global::System.Convert.ChangeType(__y, typeof(int))); + } AfterDeserializeDictionary(content); } @@ -136,6 +140,10 @@ internal ProviderActionsTriggerEvaluationAcceptedResponseHeaders(global::System. { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).Location = (string) content.GetValueForProperty("Location",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).Location, global::System.Convert.ToString); } + if (content.Contains("RetryAfter")) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).RetryAfter = (int?) content.GetValueForProperty("RetryAfter",((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).RetryAfter, (__y)=> (int) global::System.Convert.ChangeType(__y, typeof(int))); + } AfterDeserializePSObject(content); } diff --git a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.cs b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.cs index 3c52c73cb2..b9eb9863fb 100644 --- a/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.cs +++ b/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/target/generated/api/Models/ProviderActionsTriggerEvaluationAcceptedResponseHeaders.cs @@ -17,6 +17,12 @@ public partial class ProviderActionsTriggerEvaluationAcceptedResponseHeaders : [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Origin(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PropertyOrigin.Owned)] public string Location { get => this._location; set => this._location = value; } + /// Backing field for property. + private int? _retryAfter; + + [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Origin(Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.PropertyOrigin.Owned)] + public int? RetryAfter { get => this._retryAfter; set => this._retryAfter = value; } + /// void Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IHeaderSerializable.ReadHeaders(global::System.Net.Http.Headers.HttpResponseHeaders headers) { @@ -24,6 +30,10 @@ void Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.IHeaderS { ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).Location = System.Linq.Enumerable.FirstOrDefault(__locationHeader0) is string __headerLocationHeader0 ? __headerLocationHeader0 : (string)null; } + if (headers.TryGetValues("Retry-After", out var __retryAfterHeader1)) + { + ((Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Models.IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal)this).RetryAfter = System.Linq.Enumerable.FirstOrDefault(__retryAfterHeader1) is string __headerRetryAfterHeader1 ? int.TryParse( __headerRetryAfterHeader1, out int __headerRetryAfterHeader1Value ) ? __headerRetryAfterHeader1Value : default(int?) : default(int?); + } } /// @@ -48,11 +58,24 @@ public partial interface IProviderActionsTriggerEvaluationAcceptedResponseHeader PossibleTypes = new [] { typeof(string) })] string Location { get; set; } + [Microsoft.Azure.PowerShell.Cmdlets.AppComplianceAutomation.Runtime.Info( + Required = false, + ReadOnly = false, + Read = true, + Create = true, + Update = true, + Description = @"", + SerializedName = @"Retry-After", + PossibleTypes = new [] { typeof(int) })] + int? RetryAfter { get; set; } + } internal partial interface IProviderActionsTriggerEvaluationAcceptedResponseHeadersInternal { string Location { get; set; } + int? RetryAfter { get; set; } + } } \ No newline at end of file