Skip to content

Commit

Permalink
standardize casing for bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
satvu committed Nov 1, 2022
1 parent 6b1bdd5 commit e235854
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 160 deletions.
12 changes: 12 additions & 0 deletions sdk/Sdk.Generators/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,17 @@ public static string TrimStringsFromEnd(this string str, IReadOnlyList<string> s

return result;
}

public static string UppercaseFirst(this string str)
{
// Check for empty string.
if (string.IsNullOrEmpty(str))
{
return string.Empty;
}

// Return char and concat substring.
return char.ToUpper(str[0]) + str.Substring(1);
}
}
}
22 changes: 11 additions & 11 deletions sdk/Sdk.Generators/FunctionMetadataProviderGenerator.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private bool TryGetParameterInputAndTriggerBindings(MethodDeclarationSyntax meth

if (dataType is not DataType.Undefined)
{
bindingDict!.Add("dataType", FormatObject(Enum.GetName(typeof(DataType), dataType)));
bindingDict!.Add("DataType", FormatObject(Enum.GetName(typeof(DataType), dataType)));
}

// special handling for EventHubsTrigger - we need to define a property called "Cardinality"
Expand Down Expand Up @@ -433,9 +433,9 @@ private IDictionary<string, string> GetHttpReturnBinding(string returnBindingNam
{
var httpBinding = new Dictionary<string, string>();

httpBinding.Add("name", FormatObject(returnBindingName));
httpBinding.Add("type", FormatObject("http"));
httpBinding.Add("direction", FormatObject("Out"));
httpBinding.Add("Name", FormatObject(returnBindingName));
httpBinding.Add("Type", FormatObject("http"));
httpBinding.Add("Direction", FormatObject("Out"));

return httpBinding;
}
Expand All @@ -460,9 +460,9 @@ private bool TryCreateBindingDict(AttributeData bindingAttrData, string bindingN

var bindingCount = attributeProperties!.Count + 3;
bindings = new Dictionary<string, string>(capacity: bindingCount);
bindings.Add("name", FormatObject(bindingName));
bindings.Add("type", FormatObject(bindingType));
bindings.Add("direction", FormatObject(bindingDirection));
bindings.Add("Name", FormatObject(bindingName));
bindings.Add("Type", FormatObject(bindingType));
bindings.Add("Direction", FormatObject(bindingDirection));

// Add additional bindingInfo to the anonymous type because some functions have more properties than others
foreach (var prop in attributeProperties!) // attributeProperties won't be null here b/c we would've exited this method earlier if it was during TryGetAttributeProperties check
Expand All @@ -472,14 +472,14 @@ private bool TryCreateBindingDict(AttributeData bindingAttrData, string bindingN
if (prop.Value?.GetType().IsArray ?? false)
{
string arr = FormatArray((IEnumerable)prop.Value);
bindings[propertyName] = arr;
bindings[propertyName.UppercaseFirst()] = arr; // Uppercase first to use PascalCase in generated file's anonymous type
}
else
{
bool isEnum = string.Equals(prop.Key, "authLevel", StringComparison.OrdinalIgnoreCase); // prop keys come from Azure Functions defined attributes so we can check directly for authLevel

var propertyValue = FormatObject(prop.Value, isEnum);
bindings[propertyName] = propertyValue;
bindings[propertyName.UppercaseFirst()] = propertyValue;
}
}

Expand Down Expand Up @@ -511,7 +511,7 @@ private bool TryGetAttributeProperties(AttributeData attributeData, Location? at
}
else
{
attrProperties[namedArgument.Key] = namedArgument.Value.Value;
attrProperties[namedArgument.Key.UppercaseFirst()] = namedArgument.Value.Value;
}
}
}
Expand All @@ -534,7 +534,7 @@ private bool TryGetAttributeProperties(AttributeData attributeData, Location? at
}
else if (!attrProperties.Keys.Any(a => string.Equals(a, argName, StringComparison.OrdinalIgnoreCase))) // check if this property has been assigned a value already in constructor or named args
{
attrProperties[argName] = arg;
attrProperties[argName.UppercaseFirst()] = arg;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,17 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = ""input"",
type = ""EventHubTrigger"",
direction = ""In"",
eventHubName = ""test"",
Name = ""input"",
Type = ""EventHubTrigger"",
Direction = ""In"",
EventHubName = ""test"",
Connection = ""EventHubConnectionAppSetting"",
Cardinality = ""One"",");

if(!string.Equals(dataType, ""))
{
expectedOutputBuilder.Append(@"
dataType = """ + dataType + "\",");
DataType = """ + dataType + "\",");
}

expectedOutputBuilder.Append(@"
Expand Down Expand Up @@ -226,18 +226,18 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = ""input"",
type = ""EventHubTrigger"",
direction = ""In"",
eventHubName = ""test"",
Name = ""input"",
Type = ""EventHubTrigger"",
Direction = ""In"",
EventHubName = ""test"",
Connection = ""EventHubConnectionAppSetting"",
Cardinality = ""Many"","
);

if (!string.Equals(dataType, ""))
{
expectedOutputBuilder.Append(@"
dataType = """ + dataType + "\",");
DataType = """ + dataType + "\",");
}

expectedOutputBuilder.Append(@"
Expand Down Expand Up @@ -327,10 +327,10 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
};
Expand Down Expand Up @@ -471,13 +471,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'String',
DataType = 'String',
};
var Function0binding0JSON = JsonSerializer.Serialize(Function0binding0);
Function0RawBindings.Add(Function0binding0JSON);
Expand All @@ -492,13 +492,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function0);
var Function1RawBindings = new List<string>();
var Function1binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'String',
DataType = 'String',
};
var Function1binding0JSON = JsonSerializer.Serialize(Function1binding0);
Function1RawBindings.Add(Function1binding0JSON);
Expand All @@ -513,13 +513,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function1);
var Function2RawBindings = new List<string>();
var Function2binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'String',
DataType = 'String',
};
var Function2binding0JSON = JsonSerializer.Serialize(Function2binding0);
Function2RawBindings.Add(Function2binding0JSON);
Expand All @@ -534,13 +534,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function2);
var Function3RawBindings = new List<string>();
var Function3binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'String',
DataType = 'String',
};
var Function3binding0JSON = JsonSerializer.Serialize(Function3binding0);
Function3RawBindings.Add(Function3binding0JSON);
Expand Down Expand Up @@ -652,13 +652,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'Binary',
DataType = 'Binary',
};
var Function0binding0JSON = JsonSerializer.Serialize(Function0binding0);
Function0RawBindings.Add(Function0binding0JSON);
Expand All @@ -673,13 +673,13 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function0);
var Function1RawBindings = new List<string>();
var Function1binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
dataType = 'Binary',
DataType = 'Binary',
};
var Function1binding0JSON = JsonSerializer.Serialize(Function1binding0);
Function1RawBindings.Add(Function1binding0JSON);
Expand Down Expand Up @@ -778,10 +778,10 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
};
Expand All @@ -798,10 +798,10 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
metadataList.Add(Function0);
var Function1RawBindings = new List<string>();
var Function1binding0 = new {
name = 'input',
type = 'EventHubTrigger',
direction = 'In',
eventHubName = 'test',
Name = 'input',
Type = 'EventHubTrigger',
Direction = 'In',
EventHubName = 'test',
Connection = 'EventHubConnectionAppSetting',
Cardinality = 'Many',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'req',
type = 'HttpTrigger',
direction = 'In',
authLevel = (AuthorizationLevel)0,
methods = new List<string> { 'get','post' },
Name = 'req',
Type = 'HttpTrigger',
Direction = 'In',
AuthLevel = (AuthorizationLevel)0,
Methods = new List<string> { 'get','post' },
};
var Function0binding0JSON = JsonSerializer.Serialize(Function0binding0);
Function0RawBindings.Add(Function0binding0JSON);
var Function0binding1 = new {
name = '$return',
type = 'http',
direction = 'Out',
Name = '$return',
Type = 'http',
Direction = 'Out',
};
var Function0binding1JSON = JsonSerializer.Serialize(Function0binding1);
Function0RawBindings.Add(Function0binding1JSON);
Expand Down Expand Up @@ -175,11 +175,11 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'req',
type = 'HttpTrigger',
direction = 'In',
authLevel = (AuthorizationLevel)4,
methods = new List<string> { 'get','post' },
Name = 'req',
Type = 'HttpTrigger',
Direction = 'In',
AuthLevel = (AuthorizationLevel)4,
Methods = new List<string> { 'get','post' },
Route = ""/api2"",
};
var Function0binding0JSON = JsonSerializer.Serialize(Function0binding0);
Expand Down Expand Up @@ -270,18 +270,18 @@ public Task<ImmutableArray<IFunctionMetadata>> GetFunctionMetadataAsync(string d
var metadataList = new List<IFunctionMetadata>();
var Function0RawBindings = new List<string>();
var Function0binding0 = new {
name = 'req',
type = 'HttpTrigger',
direction = 'In',
methods = new List<string> { 'get' },
dataType = 'String',
Name = 'req',
Type = 'HttpTrigger',
Direction = 'In',
Methods = new List<string> { 'get' },
DataType = 'String',
};
var Function0binding0JSON = JsonSerializer.Serialize(Function0binding0);
Function0RawBindings.Add(Function0binding0JSON);
var Function0binding1 = new {
name = ""httpResponseProp"",
type = ""http"",
direction = ""Out"",
Name = ""httpResponseProp"",
Type = ""http"",
Direction = ""Out"",
};
var Function0binding1JSON = JsonSerializer.Serialize(Function0binding1);
Function0RawBindings.Add(Function0binding1JSON);
Expand Down
Loading

0 comments on commit e235854

Please sign in to comment.