Open Closed

DontWrap Result by header info, or another way #7259


0
enerjisauretim created

Hi there,

We now have a couple of finished AspnetZero applications, and we started using some of their api's like login and other methods. However, the same nswag problem starts occurring: nswag generated unwrapped results.

In my opinion, you can pass such a lambda function:

Configuration.Modules.AbpAspNetCore().DefaultWrapResultAttribute.WrapOnSuccessFunc = (request) => request.Headers["x-dontwrap"] != null;

So that we can configure it per httprequest?

What we do is now create an overload for unwrapped version and use [DontWrap] Attribute, which is very weird.


5 Answer(s)
  • 0
    maliming created

    I think the content format returned by api should be fixed and should not be changed according to the content of the request header.

  • 0
    enerjisauretim created

    @maliming you are right, however, AspnetZero does inject the response type, which is wrong, either. The service should return the same structure as it promises to.

    In my opinion, instead of wrapping results, RAD tool should generate wrapped object results (such as AbpPagedResult

  • 0
    maliming created

    hi @enerjisauretim

    This returned wrapper object is automatically handled in zero's angular. https://github.com/aspnetboilerplate/abp-ng2-module/blob/master/src/abpHttpInterceptor.ts#L129

  • 0
    enerjisauretim created

    Since we are calling webapi's from our other projects via server-to-server communication, this interceptor does not work for our case.

  • 0
    maliming created

    hi

    I don't know your code, maybe you can write an interceptor similar to angular in the backend application. This is the best.

    If you want to dynamically control the return content based on the request header, you can refer to the code of the AbpResultFilter and then replace the filter (note that the order of the filters cannot be changed). Determine the request header in the filter to decide whether to wrap the returned content.

    https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/Results/AbpResultFilter.cs#L10

    services.PostConfigure<MvcOptions>(options =>
    {
    	ReplaceYourFilter(options.Filters);
    });