RicoSuter/NSwag

Default optional parameters configuration is generating duplicate methods for the CSharp Client

Open

#2,516 opened on Nov 12, 2019

View on GitHub
 (4 comments) (6 reactions) (0 assignees)C# (1,189 forks)batch import
help wantedproject: NSwag.CodeGeneration.CSharp (Clients)type: bug

Repository metrics

Stars
 (6,291 stars)
PR merge metrics
 (No merged PRs in 30d)

Description

I started to use the "Generate Optional Parameter" option

But the C Sharp client is generating duplicate methods since it is generating a method with a nulleable parameter and cancellation token nulleable and also another method with cancelation token nulleable

c# sample endpoint

[HttpGet("all")]
public async Task<ActionResult<BucketInfo[]>> GetBuckets(string prefix)

sample config.zip c# sample code generated

[System.CodeDom.Compiler.GeneratedCode("NSwag", "13.1.3.0 (NJsonSchema v10.0.27.0 (Newtonsoft.Json v11.0.0.0))")]
public partial interface IBucketClient
{
    /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
    /// <summary>Return the complete list of drives</summary>
    /// <returns>Returns the list of drives</returns>
    /// <exception cref="GDriveSDKException">A server side error occurred.</exception>
    System.Threading.Tasks.Task<GDriveSDKResponse<System.Collections.Generic.ICollection<BucketInfo>>> AllGetAsync(string prefix = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

    /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
    /// <summary>Get the list of owned and shared TeamDrives for the user</summary>
    /// <returns>Return the list of drives</returns>
    /// <exception cref="GDriveSDKException">A server side error occurred.</exception>
    System.Threading.Tasks.Task<GDriveSDKResponse<System.Collections.Generic.ICollection<TeamDrive>>> AllGetAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));

}

I set the "Operation Generation Mode" with the MultipleClientsFromFirstTagAndPathSegments Attached you can find a sample configuration that we are using

Would it be possible to eliminate the method that only receives the cancellationtoken parameter?

Contributor guide