AutoWrapper 4.5.0 has been released today! This release comes with a few new options that enables you to customize how you would want the wrapper to behave, and as well as a couple of bug fixes. Here are the new options added:

  • ExcludePaths
  • SwaggerPath
  • ShowIsErrorFlagForSuccessfulResponse

Exclude Paths

The ExcludePaths option enables you to set a collection of API paths to be ignored. This feature was added by chen1tian. Thank you so much for this great contribution! Here's how it works:

Excluding Api paths/routes that do not need to be wrapped support three ExcludeMode:

  • Strict: The request path must be exactly the same as the configured path.
  • StartWith: The request path starts at the configuration path.
  • Regex: If the requested path match the configured path regular expression, it will be excluded.

The following is a quick example:

app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
    ExcludePaths = new AutoWrapperExcludePaths[] {
        // Strict Match
        new AutoWrapperExcludePaths("/Strict", ExcludeMode.Strict),
        // StartWith
        new AutoWrapperExcludePaths("/dapr", ExcludeMode.StartWith),
        // Regex
        new AutoWrapperExcludePaths("/notice/.*|/notice", ExcludeMode.Regex) 
    }
});

Support for SignalR

If you have the following SignalR endpoint:

app.UseEndpoints(endpoints =>
{
    endpoints.MapControllers();
    endpoints.MapHub<NoticeHub>("/notice");
});

then you can use the ExcludePaths and set the the "/notice" path as AutoWrapperExcludePaths for the SignalR endpoint to work. For example:

app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
    ExcludePaths = new AutoWrapperExcludePaths[] {
        new AutoWrapperExcludePaths("/notice/.*|/notice", ExcludeMode.Regex)
    }
});

Support for Dapr

In previous version, the Dapr Pubsub request cannot reach the configured Controller Action after being wrapped by AutoWrapper. The series path starting with "/dapr/" needs to be excluded to make the dapr request take effect:

app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
    ExcludePaths = new AutoWrapperExcludePaths[] {
        new AutoWrapperExcludePaths("/dapr", ExcludeMode.StartWith)          
    }
});

Swagger Path

The SwaggerPath option enables you to set the Swagger path. Default is /swagger. This option will be merged in the upcoming released of AutoWrapper version 5.x. Here's' a quick example:

app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
    SwaggerPath = "/yourswaggerpath"
});

Always Show the IsError Property

The IsError property was hidden for successful responses but it was requested back in the PR here. The ShowIsErrorFlagForSuccessfulResponse option enables you to always display the IsError property in the response.

app.UseApiResponseAndExceptionWrapper(new AutoWrapperOptions
{
    ShowIsErrorFlagForSuccessfulResponse  = true
});

That's it! I'm still working on converting the project to .NET 5. You can see the road map here: AutoWrapper Crossed 100K Downloads on NuGet!

Feel free to request an issue on github if you find bugs or request a new feature. Your valuable feedback is much appreciated to better improve this project. If you find this useful, please give it a star or be a sponsor to show your support on this project.

Cheers! 🍻