Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
ModelBinder caused complex type to display property-by-property - 5.2.2 #536
Hello, I am using version Swashbuckle 5.2.2 in my WebApi project. I am getting a strange UI for endpoint where i used ModelBinder.
public class EmployeeDto
In PUT endpoint, i used ModelBinder:
public async Task UpdateEmployee(int id, [ModelBinder(typeof(EmployeeModelBinder))] EmployeeDto dto)
And after the above, Swagger UI is no more displaying EmployeeDto schema. It is displaying a drilled-down EmployeeDto with each property as a separate input:
While in POST - where there is no ModelBinder, it appears like:
I am using Visual Studio 2013.
We would like the PUT documentation to be same as POST.
What needs to be done, Please suggest.
Looks like a bug with WebApi's built-in metadata layer (ApiExplorer) which Swashbuckle is built on. For some reason it's reporting the parameter in question as having Source == "FromUri". The issue occurs here:
I'm curious, why a model binder for PUT but not POST? What does it do?
I'm having this exact problem as well :(
Okay, I found another, IMO better solution, working around the model binder issue.
This approach uses a custom JsonConverter instead of the model binder, which in my case was perfect. I was deserializing in the model binder anyway, so with this solution, I can skip an unnecessary step. Hope it can help anyone else :)
hi, sorry, i am almost two years late to post the code...but here it is...
here is the document filter:
and in swagger config:
hope this helps.
again sorry for extremly late reply, i know it might make the answer irrelevent now...
hope this helps.
Here is the solution I used
And Call this class in Swagger Config as