Update: I'm starting to wonder if this is due to a bug:
https://github.com/domaindrivendev/Swashbuckle/issues/590
But the workaround suggested there does not seem to solve my problem.
I am using Swashbuckle to generate API documentation for a C# ASP.NET Web API project.
My target is to allow the following as valid URL:
/endpoint/items/123/foo?param2=bar
With a required parameter (param1) set to "foo" and an optional parameter (param2) set to "bar". I would like both parameters contained inside a single C# parameter object. (with other optional parameters like param3 and so on). Several endpoints will use identical parameters and I would like to have a single object representing the parameters.
The details of Swagger/Swashbuckle are mostly a black box to be, and I'm unable to figure this out. I'm getting duplicates in the parameter list.
Sample code to reproduce the problem:
// This endpoint is generating documentation the way I would like.
[HttpGet]
[Route("endpoint1/items/{id}/{param1}")]
public string GetDataForParameters(int id, string param1, string param2 = null, string param3 = null)
{
return string.Format("Params: {1}, {2}, {3}", id, param1, param2, param3);
}
// This endpoint has the structure I would like, but I get duplicates for param1 in the documentation.
[HttpGet]
[Route("endpoint2/items/{id}/{param1}")]
public string GetDataForParameters(int id, [FromUri(Name = "")]MyParams myParams)
{
return string.Format("Params: {1}, {2}, {3}", id, myParams.Param1, myParams.Param2, myParams.Param3);
}
public class MyParams
{
public string Param1 { get; set;}
public string Param2 { get; set;}
public string Param3 { get; set;}
}
With the second method, I receive the parameters inside a single object. But Swagger displays a duplicate entry for the "param1".
Screenshot: Swagger duplicate parameter
How can I make Swagger/Swashbuckle not display the second entry for "param1"?
The reason for having this structure is that I have multiple endpoints that return different types of data, but they use common parameters. Some of the parameters are required (and a prt of the ID) so we would like to include those in the URL, with optional parameters in the querystring. I would prefer the common parameter object should include both required and optional parameters.
Sample code created with Visual Studio 2015 update 1. Default ASP.NET Web API project. Adding the code above to the generated ValuesController.cs. Installed package Swashbuckle 5.3.1 + dependencies.