Update: I'm starting to wonder if this is due to an error:
https://github.com/domaindrivendev/Swashbuckle/issues/590
But the suggested workaround does not seem to solve my problem.
I am using Swashbuckle to create API documentation for a C # ASP.NET Web API project.
My goal is to allow the following as a valid URL:
/endpoint/items/123/foo?param2=bar
With the required parameter (param1) set to "foo" and the optional parameter (param2) set to "bar". I would like both parameters to be contained within the same C # parameter object. (with other optional parameters like param3 etc.). Several endpoints will use the same parameters, and I would like to have one object representing the parameters.
Details Swagger / Swashbuckle is basically a black box, and I can't figure it out. I get 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;} }
The second method, I get the parameters inside the same object. But Swagger displays a double entry for "param1".
Screenshot: Duplicate Swagger option
How can I make Swagger / Swashbuckle not display the second entry for "param1"?
The reason for having this structure is because I have several endpoints that return different data types, but they use common parameters. Some parameters are required (and prt identifier), so we would like to include them in the URL, with optional parameters in the query string. I would prefer the generic parameter object to include both required and optional parameters.
Sample Code Created Using Visual Studio 2015 Update 1. ASP.NET default web API project. Adding the code above to the generated ValuesController.cs. Installed Swashbuckle 5.3.1 package + dependencies.