Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP NET Boilerplate > Generating C# swagger client using swagger codegen tool (nswag) not working

I tried generating c# code for and API I created with ASP Net Boilerplate, but the response is not deserializing correctly.

Upon investigation, it seems the json response is wrapped using a class called "AjaxResponse"; however, the swagger.json doesn't include this type in the method response.

Does anyone know how to build a C# Swagger Client that accounts for the wrapped result?

like image 212
Matt Avatar asked Jan 03 '23 14:01

Matt


1 Answers

Aspnet Boilerplate wraps real result within AjaxResponse. The class AjaxResponse is a generic type class. Swaggergen Tool fails to produce the right proxy classes because wrapping the result occurs in runtime. So the signature of the api, grabbed by Swagger is the raw result (not wrapped).

So the only solution is disabling automatic wrapper for solution-wide. Add the 2 lines to the PreInitialize() method in your Web.Core project. And your problem will be solved.

Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnError = false;

Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccess = false;
like image 113
Alper Ebicoglu Avatar answered Jan 24 '23 05:01

Alper Ebicoglu