From d29d238293b58f3d1f5122726db7326be53e6dfe Mon Sep 17 00:00:00 2001 From: kshyju Date: Fri, 20 Aug 2021 09:36:26 -0700 Subject: [PATCH 01/10] camelCasing type property value working version. --- sdk/Sdk/FunctionMetadataGenerator.cs | 5 +- sdk/Sdk/StringExtensions.cs | 53 +++++++++++++++++++ .../FunctionMetadataGeneratorTests.cs | 30 +++++------ 3 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 sdk/Sdk/StringExtensions.cs diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index 536d83258..4991d9987 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -247,7 +247,7 @@ private void AddOutputBindingsFromReturnType(IList bindingMetadat private static bool IsHttpTrigger(ExpandoObject bindingMetadata) { return bindingMetadata.Any(kvp => string.Equals(kvp.Key, "Type", StringComparison.Ordinal) - && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType, StringComparison.Ordinal)); + && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType, StringComparison.OrdinalIgnoreCase)); } private bool TryAddOutputBindingsFromProperties(IList bindingMetadata, TypeDefinition typeDefinition) @@ -381,7 +381,8 @@ private static ExpandoObject BuildBindingMetadataFromAttribute(CustomAttribute a bindingDict["Name"] = parameterName!; } - bindingDict["Type"] = bindingType; + // The "Type" property value must be camelCase for the scaling component to work correctly + bindingDict["Type"] = bindingType.ToCamelCase(); bindingDict["Direction"] = GetBindingDirection(attribute); // Is string parameter type diff --git a/sdk/Sdk/StringExtensions.cs b/sdk/Sdk/StringExtensions.cs new file mode 100644 index 000000000..c721e95be --- /dev/null +++ b/sdk/Sdk/StringExtensions.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace Microsoft.Azure.Functions.Worker.Sdk +{ + internal static class StringExtensions + { + /// + /// Returns a copy of the string in camelcase. + /// + internal static string ToCamelCase(this string value) + { + if (string.IsNullOrEmpty(value) || !char.IsUpper(value[0])) + { + return value; + } + + char[] chars = value.ToCharArray(); + + for (int i = 0; i < chars.Length; i++) + { + if (i == 1) + { + if (!char.IsUpper(chars[i])) + { + break; + } + } + + bool hasNext = (i + 1 < chars.Length); + + // Stop when next char is already lowercase. + if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) + { + // If the next char is a space, lowercase current char before exiting. + if (chars[i + 1] == ' ') + { + chars[i] = char.ToLowerInvariant(chars[i]); + } + + break; + } + + chars[i] = char.ToLowerInvariant(chars[i]); + } + + return new string(chars); + } + } +} diff --git a/test/FunctionMetadataGeneratorTests/FunctionMetadataGeneratorTests.cs b/test/FunctionMetadataGeneratorTests/FunctionMetadataGeneratorTests.cs index abc9ac612..7fb4ceae8 100644 --- a/test/FunctionMetadataGeneratorTests/FunctionMetadataGeneratorTests.cs +++ b/test/FunctionMetadataGeneratorTests/FunctionMetadataGeneratorTests.cs @@ -44,7 +44,7 @@ void ValidateTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "myReq" }, - { "Type", "HttpTrigger" }, + { "Type", "httpTrigger" }, { "Direction", "In" }, { "authLevel", "Admin" }, { "methods", new[] { "get", "Post" } }, @@ -86,7 +86,7 @@ void ValidateTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "myReq" }, - { "Type", "HttpTrigger" }, + { "Type", "httpTrigger" }, { "Direction", "In" }, { "authLevel", "Admin" }, { "methods", new[] { "get", "Post" } }, @@ -119,7 +119,7 @@ void ValidateTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "myReq" }, - { "Type", "HttpTrigger" }, + { "Type", "httpTrigger" }, { "Direction", "In" }, { "authLevel", "Admin" }, { "methods", new[] { "get", "Post" } }, @@ -169,7 +169,7 @@ void ValidateQueueTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "queuePayload" }, - { "Type", "QueueTrigger" }, + { "Type", "queueTrigger" }, { "Direction", "In" }, { "Connection", "MyConnection" }, { "queueName", "queueName" }, @@ -182,7 +182,7 @@ void ValidateBlobOutput(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "$return" }, - { "Type", "Blob" }, + { "Type", "blob" }, { "Direction", "Out" }, { "blobPath", "container1/hello.txt" }, { "Connection", "MyOtherConnection" } @@ -198,7 +198,7 @@ void ValidateBlobTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "blob" }, - { "Type", "BlobTrigger" }, + { "Type", "blobTrigger" }, { "Direction", "In" }, { "blobPath", "container2/%file%" }, { "DataType", "String" } @@ -210,7 +210,7 @@ void ValidateQueueOutput(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "$return" }, - { "Type", "Queue" }, + { "Type", "queue" }, { "Direction", "Out" }, { "queueName", "queue2" }, }); @@ -236,7 +236,7 @@ void ValidateTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "timer" }, - { "Type", "TimerTrigger" }, + { "Type", "timerTrigger" }, { "Direction", "In" }, { "schedule", "0 0 0 * * *" }, { "RunOnStartup", false } @@ -273,7 +273,7 @@ void ValidateQueueTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "queuePayload" }, - { "Type", "QueueTrigger" }, + { "Type", "queueTrigger" }, { "Direction", "In" }, { "Connection", "MyConnection" }, { "queueName", "queueName" }, @@ -286,7 +286,7 @@ void ValidateBlobOutput(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "blobOutput" }, - { "Type", "Blob" }, + { "Type", "blob" }, { "Direction", "Out" }, { "blobPath", "container1/hello.txt" }, { "Connection", "MyOtherConnection" }, @@ -299,7 +299,7 @@ void ValidateQueueOutput(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "queueOutput" }, - { "Type", "Queue" }, + { "Type", "queue" }, { "Direction", "Out" }, { "queueName", "queue2" }, { "DataType", "String" } @@ -335,7 +335,7 @@ void ValidateHttpTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "req" }, - { "Type", "HttpTrigger" }, + { "Type", "httpTrigger" }, { "Direction", "In" }, { "methods", new[] { "get" } }, { "DataType", "String" } @@ -357,7 +357,7 @@ void ValidateQueueOutput(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "queueOutput" }, - { "Type", "Queue" }, + { "Type", "queue" }, { "Direction", "Out" }, { "queueName", "queue2" }, { "DataType", "String" } @@ -389,7 +389,7 @@ void ValidateHttpTrigger(ExpandoObject b) AssertExpandoObject(b, new Dictionary { { "Name", "req" }, - { "Type", "HttpTrigger" }, + { "Type", "httpTrigger" }, { "Direction", "In" }, { "methods", new[] { "get" } }, { "DataType", "String" } @@ -468,7 +468,7 @@ void ValidateTrigger(ExpandoObject b, bool many) var expected = new Dictionary() { { "Name", "input" }, - { "Type", "EventHubTrigger" }, + { "Type", "eventHubTrigger" }, { "Direction", "In" }, { "eventHubName", "test" }, { "Connection", "EventHubConnectionAppSetting" } From 3d016139033c16cce785f1cca33da0f768e1cca3 Mon Sep 17 00:00:00 2001 From: kshyju Date: Fri, 20 Aug 2021 11:37:13 -0700 Subject: [PATCH 02/10] Moved the StringExtension under a directory --- sdk/Sdk/{ => Extensions}/StringExtensions.cs | 7 ++----- sdk/Sdk/FunctionMetadataGenerator.cs | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) rename sdk/Sdk/{ => Extensions}/StringExtensions.cs (88%) diff --git a/sdk/Sdk/StringExtensions.cs b/sdk/Sdk/Extensions/StringExtensions.cs similarity index 88% rename from sdk/Sdk/StringExtensions.cs rename to sdk/Sdk/Extensions/StringExtensions.cs index c721e95be..4b1cd974d 100644 --- a/sdk/Sdk/StringExtensions.cs +++ b/sdk/Sdk/Extensions/StringExtensions.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. namespace Microsoft.Azure.Functions.Worker.Sdk @@ -9,7 +6,7 @@ namespace Microsoft.Azure.Functions.Worker.Sdk internal static class StringExtensions { /// - /// Returns a copy of the string in camelcase. + /// Returns a copy of the string in camelCase. /// internal static string ToCamelCase(this string value) { diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index 4991d9987..a4387e6f2 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -381,7 +381,7 @@ private static ExpandoObject BuildBindingMetadataFromAttribute(CustomAttribute a bindingDict["Name"] = parameterName!; } - // The "Type" property value must be camelCase for the scaling component to work correctly + // The "Type" property value must be camelCase for the scaling infrastructure to work correctly bindingDict["Type"] = bindingType.ToCamelCase(); bindingDict["Direction"] = GetBindingDirection(attribute); From ce4c8d9c53a8d48e47581e4ca79da98cdc35e4b9 Mon Sep 17 00:00:00 2001 From: kshyju Date: Fri, 20 Aug 2021 12:16:06 -0700 Subject: [PATCH 03/10] Fixed a failing test in the correct fashion. --- sdk/Sdk/FunctionMetadataGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index a4387e6f2..948f78b2a 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -247,7 +247,7 @@ private void AddOutputBindingsFromReturnType(IList bindingMetadat private static bool IsHttpTrigger(ExpandoObject bindingMetadata) { return bindingMetadata.Any(kvp => string.Equals(kvp.Key, "Type", StringComparison.Ordinal) - && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType, StringComparison.OrdinalIgnoreCase)); + && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType.ToCamelCase(), StringComparison.Ordinal)); } private bool TryAddOutputBindingsFromProperties(IList bindingMetadata, TypeDefinition typeDefinition) From 31f0e1edfd177cc0eff00bc7bc1795b7c7a94000 Mon Sep 17 00:00:00 2001 From: kshyju Date: Fri, 20 Aug 2021 16:24:44 -0700 Subject: [PATCH 04/10] Moved 2 existing extension method classes under Extensions directory. Also added tests for ToCamelCase extension method. --- .../CustomAttributeExtensions.cs | 1 - sdk/Sdk/Extensions/StringExtensions.cs | 4 +++- .../TypeReferenceExtensions.cs | 0 .../StringExtensionsTests.cs | 24 +++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) rename sdk/Sdk/{ => Extensions}/CustomAttributeExtensions.cs (99%) rename sdk/Sdk/{ => Extensions}/TypeReferenceExtensions.cs (100%) create mode 100644 test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs diff --git a/sdk/Sdk/CustomAttributeExtensions.cs b/sdk/Sdk/Extensions/CustomAttributeExtensions.cs similarity index 99% rename from sdk/Sdk/CustomAttributeExtensions.cs rename to sdk/Sdk/Extensions/CustomAttributeExtensions.cs index 6cd240eb9..817cfed9d 100644 --- a/sdk/Sdk/CustomAttributeExtensions.cs +++ b/sdk/Sdk/Extensions/CustomAttributeExtensions.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; using Mono.Cecil; namespace Microsoft.Azure.Functions.Worker.Sdk diff --git a/sdk/Sdk/Extensions/StringExtensions.cs b/sdk/Sdk/Extensions/StringExtensions.cs index 4b1cd974d..b3f7555e8 100644 --- a/sdk/Sdk/Extensions/StringExtensions.cs +++ b/sdk/Sdk/Extensions/StringExtensions.cs @@ -8,8 +8,10 @@ internal static class StringExtensions /// /// Returns a copy of the string in camelCase. /// - internal static string ToCamelCase(this string value) + public static string ToCamelCase(this string value) { + // Using the same logic as in JsonCamelCaseNamingPolicy(System.Text.Json) + if (string.IsNullOrEmpty(value) || !char.IsUpper(value[0])) { return value; diff --git a/sdk/Sdk/TypeReferenceExtensions.cs b/sdk/Sdk/Extensions/TypeReferenceExtensions.cs similarity index 100% rename from sdk/Sdk/TypeReferenceExtensions.cs rename to sdk/Sdk/Extensions/TypeReferenceExtensions.cs diff --git a/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs new file mode 100644 index 000000000..69dc54ffd --- /dev/null +++ b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using Microsoft.Azure.Functions.Worker.Sdk; +using Xunit; + +namespace Microsoft.Azure.Functions.SdkTests +{ + public class StringExtensionsTests + { + [Theory] + [InlineData("QueueTrigger", "queueTrigger")] + [InlineData("HTTPTrigger", "httpTrigger")] + [InlineData("Blob", "blob")] + [InlineData("", "")] + [InlineData(null, null)] + public void ToCamelCaseWorks(string input, string expectedOutput) + { + var actual = input.ToCamelCase(); + + Assert.Equal(expectedOutput, actual); + } + } +} From 50515b3a0c487fcf2f041489d011254a705503b8 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Sun, 22 Aug 2021 23:24:12 -0700 Subject: [PATCH 05/10] Fixed functions.metadata file present in E2E tests, which is being used for the expected value for the test assertions. --- test/SdkE2ETests/Contents/functions.metadata | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/SdkE2ETests/Contents/functions.metadata b/test/SdkE2ETests/Contents/functions.metadata index 18b5a73db..4df05982d 100644 --- a/test/SdkE2ETests/Contents/functions.metadata +++ b/test/SdkE2ETests/Contents/functions.metadata @@ -10,7 +10,7 @@ "bindings": [ { "name": "req", - "type": "HttpTrigger", + "type": "httpTrigger", "direction": "In", "authLevel": "Anonymous", "methods": [ @@ -20,7 +20,7 @@ }, { "name": "myBlob", - "type": "Blob", + "type": "blob", "direction": "In", "dataType": "String", "blobPath": "test-samples/sample1.txt", @@ -28,7 +28,7 @@ }, { "name": "Book", - "type": "Queue", + "type": "queue", "direction": "Out", "queueName": "functionstesting2", "connection": "AzureWebJobsStorage" @@ -51,14 +51,14 @@ "bindings": [ { "name": "myQueueItem", - "type": "QueueTrigger", + "type": "queueTrigger", "direction": "In", "queueName": "functionstesting2", "connection": "AzureWebJobsStorage" }, { "name": "myBlob", - "type": "Blob", + "type": "blob", "direction": "In", "dataType": "String", "blobPath": "test-samples/sample1.txt", @@ -77,7 +77,7 @@ "bindings": [ { "name": "req", - "type": "HttpTrigger", + "type": "httpTrigger", "direction": "In", "authLevel": "Anonymous", "methods": [ @@ -87,7 +87,7 @@ }, { "name": "Name", - "type": "Queue", + "type": "queue", "direction": "Out", "dataType": "String", "queueName": "functionstesting2", @@ -111,7 +111,7 @@ "bindings": [ { "name": "req", - "type": "HttpTrigger", + "type": "httpTrigger", "direction": "In", "authLevel": "Anonymous", "methods": [ @@ -137,7 +137,7 @@ "bindings": [ { "name": "req", - "type": "HttpTrigger", + "type": "httpTrigger", "direction": "In", "authLevel": "Anonymous", "methods": [ From 34236bba3755573d124d580fc5d25acee6bb0211 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Mon, 23 Aug 2021 09:21:52 -0700 Subject: [PATCH 06/10] Added one more test input entry(allo lowercase) for the ToCamelCaseWorks extension tests. --- test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs index 69dc54ffd..805369f03 100644 --- a/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs +++ b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs @@ -12,6 +12,7 @@ public class StringExtensionsTests [InlineData("QueueTrigger", "queueTrigger")] [InlineData("HTTPTrigger", "httpTrigger")] [InlineData("Blob", "blob")] + [InlineData("http", "http")] [InlineData("", "")] [InlineData(null, null)] public void ToCamelCaseWorks(string input, string expectedOutput) From 8693f5bad70700b3ef626d2b3412782cbbf7e8ac Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Tue, 24 Aug 2021 15:28:10 -0700 Subject: [PATCH 07/10] Switched to existing "ToLowerFirstCharacter" extension to be consistent with previous inproc. --- sdk/Sdk/Extensions/StringExtensions.cs | 44 ++++--------------- sdk/Sdk/FunctionMetadataGenerator.cs | 6 +-- .../StringExtensionsTests.cs | 7 ++- 3 files changed, 15 insertions(+), 42 deletions(-) diff --git a/sdk/Sdk/Extensions/StringExtensions.cs b/sdk/Sdk/Extensions/StringExtensions.cs index b3f7555e8..d91bbb429 100644 --- a/sdk/Sdk/Extensions/StringExtensions.cs +++ b/sdk/Sdk/Extensions/StringExtensions.cs @@ -1,52 +1,26 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using System.Linq; +using System; + namespace Microsoft.Azure.Functions.Worker.Sdk { internal static class StringExtensions { /// - /// Returns a copy of the string in camelCase. + /// Returns a copy of the string where the first character is in lower case. /// - public static string ToCamelCase(this string value) + public static string ToLowerFirstCharacter(this string str) { - // Using the same logic as in JsonCamelCaseNamingPolicy(System.Text.Json) - - if (string.IsNullOrEmpty(value) || !char.IsUpper(value[0])) + if (!string.IsNullOrEmpty(str)) { - return value; + return Char.ToLowerInvariant(str.First()) + str.Substring(1); } - - char[] chars = value.ToCharArray(); - - for (int i = 0; i < chars.Length; i++) + else { - if (i == 1) - { - if (!char.IsUpper(chars[i])) - { - break; - } - } - - bool hasNext = (i + 1 < chars.Length); - - // Stop when next char is already lowercase. - if (i > 0 && hasNext && !char.IsUpper(chars[i + 1])) - { - // If the next char is a space, lowercase current char before exiting. - if (chars[i + 1] == ' ') - { - chars[i] = char.ToLowerInvariant(chars[i]); - } - - break; - } - - chars[i] = char.ToLowerInvariant(chars[i]); + return str; } - - return new string(chars); } } } diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index 948f78b2a..7dd8dafbc 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -247,7 +247,7 @@ private void AddOutputBindingsFromReturnType(IList bindingMetadat private static bool IsHttpTrigger(ExpandoObject bindingMetadata) { return bindingMetadata.Any(kvp => string.Equals(kvp.Key, "Type", StringComparison.Ordinal) - && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType.ToCamelCase(), StringComparison.Ordinal)); + && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType.ToLowerFirstCharacter(), StringComparison.Ordinal)); } private bool TryAddOutputBindingsFromProperties(IList bindingMetadata, TypeDefinition typeDefinition) @@ -381,8 +381,8 @@ private static ExpandoObject BuildBindingMetadataFromAttribute(CustomAttribute a bindingDict["Name"] = parameterName!; } - // The "Type" property value must be camelCase for the scaling infrastructure to work correctly - bindingDict["Type"] = bindingType.ToCamelCase(); + // The first character of "Type" property value must be lower case for the scaling infrastructure to work correctly + bindingDict["Type"] = bindingType.ToLowerFirstCharacter(); bindingDict["Direction"] = GetBindingDirection(attribute); // Is string parameter type diff --git a/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs index 805369f03..36c50ca71 100644 --- a/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs +++ b/test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs @@ -9,15 +9,14 @@ namespace Microsoft.Azure.Functions.SdkTests public class StringExtensionsTests { [Theory] - [InlineData("QueueTrigger", "queueTrigger")] - [InlineData("HTTPTrigger", "httpTrigger")] + [InlineData("HttpTrigger", "httpTrigger")] [InlineData("Blob", "blob")] [InlineData("http", "http")] [InlineData("", "")] [InlineData(null, null)] - public void ToCamelCaseWorks(string input, string expectedOutput) + public void ToLowerFirstCharacterWorks(string input, string expectedOutput) { - var actual = input.ToCamelCase(); + var actual = input.ToLowerFirstCharacter(); Assert.Equal(expectedOutput, actual); } From 015e1d3defe88182f4b232982a9922c4e9dd6963 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Fri, 27 Aug 2021 15:08:27 -0700 Subject: [PATCH 08/10] Moved the ToLowerFirstCharacter call inside GetBindingType --- sdk/Sdk/FunctionMetadataGenerator.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index 7dd8dafbc..972ae90b1 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -381,8 +381,7 @@ private static ExpandoObject BuildBindingMetadataFromAttribute(CustomAttribute a bindingDict["Name"] = parameterName!; } - // The first character of "Type" property value must be lower case for the scaling infrastructure to work correctly - bindingDict["Type"] = bindingType.ToLowerFirstCharacter(); + bindingDict["Type"] = bindingType; bindingDict["Direction"] = GetBindingDirection(attribute); // Is string parameter type @@ -608,10 +607,15 @@ private static string GetBindingType(CustomAttribute attribute) var attributeType = attribute.AttributeType.Name; // TODO: Should "webjob type" be a property of the "worker types" and come from there? - return attributeType - .Replace("TriggerAttribute", "Trigger") - .Replace("InputAttribute", string.Empty) - .Replace("OutputAttribute", string.Empty); + var bindingType = attributeType + .Replace("TriggerAttribute", "Trigger") + .Replace("InputAttribute", string.Empty) + .Replace("OutputAttribute", string.Empty); + + // The first character of "Type" property value must be lower case for the scaling infrastructure to work correctly + bindingType = bindingType.ToLowerFirstCharacter(); + + return bindingType; } private static void AddHttpOutputBinding(IList bindingMetadata, string name) From 85e60a0075471eda75766ad1aaf4a383e649d114 Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Fri, 27 Aug 2021 15:18:53 -0700 Subject: [PATCH 09/10] Updated the constant value instead of explicit lowercasing --- sdk/Sdk/Constants.cs | 2 +- sdk/Sdk/FunctionMetadataGenerator.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/Sdk/Constants.cs b/sdk/Sdk/Constants.cs index 1f3b6dd15..fb3c6140c 100644 --- a/sdk/Sdk/Constants.cs +++ b/sdk/Sdk/Constants.cs @@ -31,7 +31,7 @@ internal static class Constants internal const string ReadOnlyMemoryOfBytes = "System.ReadOnlyMemory`1"; internal const string ReturnBindingName = "$return"; - internal const string HttpTriggerBindingType = "HttpTrigger"; + internal const string HttpTriggerBindingType = "httpTrigger"; internal const string IsBatchedKey = "IsBatched"; } } diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index 972ae90b1..ee829be6a 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -247,7 +247,7 @@ private void AddOutputBindingsFromReturnType(IList bindingMetadat private static bool IsHttpTrigger(ExpandoObject bindingMetadata) { return bindingMetadata.Any(kvp => string.Equals(kvp.Key, "Type", StringComparison.Ordinal) - && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType.ToLowerFirstCharacter(), StringComparison.Ordinal)); + && string.Equals(kvp.Value?.ToString(), Constants.HttpTriggerBindingType, StringComparison.Ordinal)); } private bool TryAddOutputBindingsFromProperties(IList bindingMetadata, TypeDefinition typeDefinition) From ff6681201337c24e71eebcec9ba0d5ad99d3478a Mon Sep 17 00:00:00 2001 From: Shyju Krishnankutty Date: Mon, 30 Aug 2021 19:23:13 -0700 Subject: [PATCH 10/10] Removed the unnecessary semi column added by merge --- sdk/Sdk/FunctionMetadataGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/Sdk/FunctionMetadataGenerator.cs b/sdk/Sdk/FunctionMetadataGenerator.cs index a56788979..a442ad439 100644 --- a/sdk/Sdk/FunctionMetadataGenerator.cs +++ b/sdk/Sdk/FunctionMetadataGenerator.cs @@ -610,7 +610,7 @@ private static string GetBindingType(CustomAttribute attribute) var bindingType = attributeType .Replace("TriggerAttribute", "Trigger") .Replace("InputAttribute", string.Empty) - .Replace("OutputAttribute", string.Empty); + .Replace("OutputAttribute", string.Empty) .Replace("Attribute", string.Empty); // The first character of "Type" property value must be lower case for the scaling infrastructure to work correctly