Skip to content

Commit 9b352e0

Browse files
this commit introduces comments explaining the conversion from snake_case to pascal case in accordance with OAuth 2.0.
the to snake case method has been rewritten as a lambda expression for greater conciseness.
1 parent 0ee4510 commit 9b352e0

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

Source/Vinder.Federation.WebApi/Binders/SnakeCaseFormModelBinder.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
namespace Vinder.Federation.WebApi.Binders;
22

3+
// oauth 2.0 requires form parameters to be sent in snake_case.
4+
// this binder converts snake_case form fields into pascal case model properties.
5+
6+
// https://www.rfc-editor.org/rfc/rfc6749#section-4.4.2
7+
38
public sealed class SnakeCaseFormModelBinder : IModelBinder
49
{
5-
#pragma warning disable S2325
610
public async Task BindModelAsync(ModelBindingContext bindingContext)
711
{
812
if (!bindingContext.HttpContext.Request.HasFormContentType)
@@ -36,8 +40,7 @@ public async Task BindModelAsync(ModelBindingContext bindingContext)
3640
bindingContext.Result = ModelBindingResult.Success(model);
3741
}
3842

39-
private static string ToSnakeCase(string input)
40-
{
41-
return Regex.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2").ToLowerInvariant();
42-
}
43-
}
43+
private static string ToSnakeCase(string input) => Regex
44+
.Replace(input, @"([a-z0-9])([A-Z])", "$1_$2")
45+
.ToLowerInvariant();
46+
}

0 commit comments

Comments
 (0)