Skip to content

Supports missing request body parameter #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Templates/CSharp/Model/MethodRequestBody.cs.tt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace <#=method.Namespace.GetNamespaceName()#>
public partial class <#=requestBody#>
{
<#
foreach (var param in method.Parameters)
foreach (var param in method.WithDistinctParameters())
{
var paramTypeString = param.Type.GetTypeString(method.Namespace.GetNamespaceName());

Expand Down
21 changes: 20 additions & 1 deletion src/GraphODataTemplateWriter/Extensions/OdcmModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,30 @@ public static List<OdcmMethod> WithDistinctOverloads(this OdcmMethod odcmMethod)
return methods.Distinct(methodComparer).ToList();
}

private static readonly OdcmParameterEqualityComparer paramComparer = new OdcmParameterEqualityComparer();
/// <summary>
/// Deduplicates the parameter list for an overloaded method.
/// </summary>
/// <param name="odcmMethod">Method with potential overloads and duplicate parameters across overloads.</param>
/// <returns>A deduplicated list of OdcmParameter.</returns>
public static List<OdcmParameter> WithDistinctParameters(this OdcmMethod odcmMethod)
{
var distinctMethods = odcmMethod.WithDistinctOverloads();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MIchaelMainer I love it, building on what I added a couple of weeks ago ❤


var parameters = new List<OdcmParameter>();

foreach (var method in distinctMethods)
{
parameters.AddRange(method.Parameters);
}

return parameters.Distinct(paramComparer).ToList();
}

/// Returns a List containing the supplied class' methods plus their overloads
public static IEnumerable<OdcmMethod> MethodsAndOverloads(this OdcmClass odcmClass)
{
return odcmClass.Methods.SelectMany(x => x.WithOverloads());
}
}

}