diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/api/Azure.Messaging.EventGrid.netstandard2.0.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/api/Azure.Messaging.EventGrid.netstandard2.0.cs index 96421f735e1cd..9bc0184e334f2 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/api/Azure.Messaging.EventGrid.netstandard2.0.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/api/Azure.Messaging.EventGrid.netstandard2.0.cs @@ -147,6 +147,7 @@ public static partial class EventGridModelFactory public static Azure.Messaging.EventGrid.SystemEvents.StorageLifecyclePolicyCompletedEventData StorageLifecyclePolicyCompletedEventData(string scheduleTime = null, Azure.Messaging.EventGrid.SystemEvents.StorageLifecyclePolicyActionSummaryDetail deleteSummary = null, Azure.Messaging.EventGrid.SystemEvents.StorageLifecyclePolicyActionSummaryDetail tierToCoolSummary = null, Azure.Messaging.EventGrid.SystemEvents.StorageLifecyclePolicyActionSummaryDetail tierToArchiveSummary = null) { throw null; } public static Azure.Messaging.EventGrid.SystemEvents.SubscriptionDeletedEventData SubscriptionDeletedEventData(string eventSubscriptionId = null) { throw null; } public static Azure.Messaging.EventGrid.SystemEvents.SubscriptionValidationEventData SubscriptionValidationEventData(string validationCode = null, string validationUrl = null) { throw null; } + [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] public static Azure.Messaging.EventGrid.SystemEvents.SubscriptionValidationResponse SubscriptionValidationResponse(string validationResponse = null) { throw null; } public static Azure.Messaging.EventGrid.SystemEvents.WebAppServicePlanUpdatedEventData WebAppServicePlanUpdatedEventData(Azure.Messaging.EventGrid.SystemEvents.AppServicePlanEventTypeDetail appServicePlanEventTypeDetail = null, Azure.Messaging.EventGrid.SystemEvents.WebAppServicePlanUpdatedEventDataSku sku = null, string name = null, string clientRequestId = null, string correlationRequestId = null, string requestId = null, string address = null, string verb = null) { throw null; } public static Azure.Messaging.EventGrid.SystemEvents.WebAppServicePlanUpdatedEventDataSku WebAppServicePlanUpdatedEventDataSku(string name = null, string tier = null, string size = null, string family = null, string capacity = null) { throw null; } @@ -1673,8 +1674,8 @@ internal SubscriptionValidationEventData() { } } public partial class SubscriptionValidationResponse { - internal SubscriptionValidationResponse() { } - public string ValidationResponse { get { throw null; } } + public SubscriptionValidationResponse() { } + public string ValidationResponse { get { throw null; } set { } } } public partial class WebAppServicePlanUpdatedEventData { diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridModelFactory.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridModelFactory.cs index c948e25c527b2..29c22c93eb135 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridModelFactory.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Customization/EventGridModelFactory.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.ComponentModel; using System.Text.Json; using Azure.Core; using Azure.Messaging.EventGrid.SystemEvents; @@ -180,6 +181,15 @@ public static ResourceActionCancelEventData ResourceActionCancelEventData(string { return new(tenantId, subscriptionId, resourceGroup, resourceProvider, resourceUri, operationName, status, JsonDocument.Parse(authorization).RootElement, JsonDocument.Parse(claims).RootElement, correlationId, JsonDocument.Parse(httpRequest).RootElement); } + + /// Initializes new instance of SubscriptionValidationResponse class. + /// The validation response sent by the subscriber to Azure Event Grid to complete the validation of an event subscription. + /// A new instance for mocking. + [EditorBrowsable(EditorBrowsableState.Never)] + public static SubscriptionValidationResponse SubscriptionValidationResponse(string validationResponse = default) + { + return new(validationResponse); + } } #pragma warning restore CA1054 // URI-like parameters should not be strings } diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/EventGridModelFactory.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/EventGridModelFactory.cs index 1cf4d75c0340c..bb4915a94facf 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/EventGridModelFactory.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/EventGridModelFactory.cs @@ -204,14 +204,6 @@ public static SubscriptionValidationEventData SubscriptionValidationEventData(st return new SubscriptionValidationEventData(validationCode, validationUrl); } - /// Initializes new instance of SubscriptionValidationResponse class. - /// The validation response sent by the subscriber to Azure Event Grid to complete the validation of an event subscription. - /// A new instance for mocking. - public static SubscriptionValidationResponse SubscriptionValidationResponse(string validationResponse = default) - { - return new SubscriptionValidationResponse(validationResponse); - } - /// Initializes new instance of SubscriptionDeletedEventData class. /// The Azure resource ID of the deleted event subscription. /// A new instance for mocking. diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/SubscriptionValidationResponse.Serialization.cs b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/SubscriptionValidationResponse.Serialization.cs index 1bee1720997f2..f6103c2c9781b 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/SubscriptionValidationResponse.Serialization.cs +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/Generated/Models/SubscriptionValidationResponse.Serialization.cs @@ -13,8 +13,19 @@ namespace Azure.Messaging.EventGrid.SystemEvents { [JsonConverter(typeof(SubscriptionValidationResponseConverter))] - public partial class SubscriptionValidationResponse + public partial class SubscriptionValidationResponse : IUtf8JsonSerializable { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (Optional.IsDefined(ValidationResponse)) + { + writer.WritePropertyName("validationResponse"); + writer.WriteStringValue(ValidationResponse); + } + writer.WriteEndObject(); + } + internal static SubscriptionValidationResponse DeserializeSubscriptionValidationResponse(JsonElement element) { Optional validationResponse = default; @@ -33,7 +44,7 @@ internal partial class SubscriptionValidationResponseConverter : JsonConverter Initializes a new instance of SubscriptionValidationResponse. - internal SubscriptionValidationResponse() + public SubscriptionValidationResponse() { } @@ -23,6 +23,6 @@ internal SubscriptionValidationResponse(string validationResponse) } /// The validation response sent by the subscriber to Azure Event Grid to complete the validation of an event subscription. - public string ValidationResponse { get; } + public string ValidationResponse { get; set; } } } diff --git a/sdk/eventgrid/Azure.Messaging.EventGrid/src/autorest.md b/sdk/eventgrid/Azure.Messaging.EventGrid/src/autorest.md index 68cc31e01460f..8240f33794863 100644 --- a/sdk/eventgrid/Azure.Messaging.EventGrid/src/autorest.md +++ b/sdk/eventgrid/Azure.Messaging.EventGrid/src/autorest.md @@ -63,12 +63,15 @@ directive: $[path]["x-namespace"] = namespace; } if (path.endsWith("EventData") || - path.endsWith("SubscriptionValidationResponse") || path.includes("EventGridEvent") || ($[path]["x-ms-client-name"] && $[path]["x-ms-client-name"].endsWith("EventData"))) { $[path]["x-csharp-usage"] = "model,output,converter"; } + if (path.endsWith("SubscriptionValidationResponse")) + { + $[path]["x-csharp-usage"] = "model,input,output,converter"; + } $[path]["x-csharp-formats"] = "json"; if (path.includes("WebAppServicePlanUpdatedEventData")) { diff --git a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/Microsoft.Azure.WebJobs.Extensions.EventGrid.sln b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/Microsoft.Azure.WebJobs.Extensions.EventGrid.sln index da305ef0daa74..044ee1337edc0 100644 --- a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/Microsoft.Azure.WebJobs.Extensions.EventGrid.sln +++ b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/Microsoft.Azure.WebJobs.Extensions.EventGrid.sln @@ -7,6 +7,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Ext EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.WebJobs.Extensions.EventGrid", "src\Microsoft.Azure.WebJobs.Extensions.EventGrid.csproj", "{9322A9CD-ADC3-4BF3-B3AA-063A66585113}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Messaging.EventGrid", "..\Azure.Messaging.EventGrid\src\Azure.Messaging.EventGrid.csproj", "{3E40026E-2DE9-4FE0-8E25-73F7B35F5D24}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ Global {9322A9CD-ADC3-4BF3-B3AA-063A66585113}.Debug|Any CPU.Build.0 = Debug|Any CPU {9322A9CD-ADC3-4BF3-B3AA-063A66585113}.Release|Any CPU.ActiveCfg = Release|Any CPU {9322A9CD-ADC3-4BF3-B3AA-063A66585113}.Release|Any CPU.Build.0 = Release|Any CPU + {3E40026E-2DE9-4FE0-8E25-73F7B35F5D24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3E40026E-2DE9-4FE0-8E25-73F7B35F5D24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3E40026E-2DE9-4FE0-8E25-73F7B35F5D24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3E40026E-2DE9-4FE0-8E25-73F7B35F5D24}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/Microsoft.Azure.WebJobs.Extensions.EventGrid.csproj b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/Microsoft.Azure.WebJobs.Extensions.EventGrid.csproj index 0623906be7d9c..9aa40b3bebb67 100644 --- a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/Microsoft.Azure.WebJobs.Extensions.EventGrid.csproj +++ b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/Microsoft.Azure.WebJobs.Extensions.EventGrid.csproj @@ -9,7 +9,13 @@ - + + + + + + + diff --git a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/HttpRequestProcessor.cs b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/HttpRequestProcessor.cs index 9f6d1629aa2f4..da41927eab6b9 100644 --- a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/HttpRequestProcessor.cs +++ b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/HttpRequestProcessor.cs @@ -8,9 +8,10 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; +using Azure.Messaging.EventGrid.SystemEvents; using Microsoft.Extensions.Logging; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using STJ = System.Text.Json; namespace Microsoft.Azure.WebJobs.Extensions.EventGrid { @@ -69,7 +70,8 @@ internal async Task ProcessAsync( SubscriptionValidationResponse validationResponse = new(){ ValidationResponse = validationCode }; var returnMessage = new HttpResponseMessage(HttpStatusCode.OK) { - Content = new StringContent(JsonConvert.SerializeObject(validationResponse)) + // use System.Text.Json to leverage the custom converter so that the casing is correct. + Content = new StringContent(STJ.JsonSerializer.Serialize(validationResponse)) }; _logger.LogInformation($"perform handshake with eventGrid for function: {functionName}"); return returnMessage; diff --git a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/SubscriptionValidationResponse.cs b/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/SubscriptionValidationResponse.cs deleted file mode 100644 index ec5cb4cba7187..0000000000000 --- a/sdk/eventgrid/Microsoft.Azure.WebJobs.Extensions.EventGrid/src/TriggerBinding/SubscriptionValidationResponse.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Newtonsoft.Json; - -namespace Microsoft.Azure.WebJobs.Extensions.EventGrid -{ - internal class SubscriptionValidationResponse - { - [JsonProperty(PropertyName = "validationResponse")] - public string ValidationResponse { get; set; } - } -}