You could do this by wiring up your own IOperationFilter based on ApplySwaggerResponseAttributes -- that's the thing that scans for [SwaggerResponse]. Here's something I whipped up based on the Swashbuckle code https://github.com/domaindrivendev/Swashbuckle/blob/master/Swashbuckle.Core/Swagger/Annotations/ApplySwaggerResponseAttributes.cs
public class ApplyResponseTypeAttributes : IOperationFilter { public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription) { if (apiDescription.GetControllerAndActionAttributes<SwaggerResponseRemoveDefaultsAttribute>().Any()) { operation.responses.Clear(); } // SwaggerResponseAttribute trumps ResponseTypeAttribute var swaggerAttributes = apiDescription.GetControllerAndActionAttributes<SwaggerResponseAttribute>(); if (!swaggerAttributes.Any()) { var responseAttributes = apiDescription.GetControllerAndActionAttributes<ResponseTypeAttribute>().OrderBy(attr => attr.ResponseType.Name); foreach (var attr in responseAttributes) { const string StatusCode = "200"; operation.responses[StatusCode] = new Response { description = InferDescriptionFrom(StatusCode), schema = (attr.ResponseType != null) ? schemaRegistry.GetOrRegister(attr.ResponseType) : null }; } } } private string InferDescriptionFrom(string statusCode) { HttpStatusCode enumValue; if (Enum.TryParse(statusCode, true, out enumValue)) { return enumValue.ToString(); } return null; } }
In your swagger configuration in ./App_Start add the following to register this filter. It's actually pretty interesting putting a breakpoint on this so you can see how Swashbuckle works, it iterates through all your controller's actions.
c.OperationFilter<ApplyResponseTypeAttributes>();