Allow Swagger to return Content Type XML or JSON

At the moment only application/json is available. What is required to add application/xml as option to the selectbox?


The most annoying thing is that two “Response Content Type” dropdowns appear in swagger-ui, one at the top of the operation (above the parameters) and one embedded within my Message Body parameter area (which is redundant and seems to be completely ignored).

For API calls with no Message Body parameter (i.e. a GET as opposed to PUT, POST) the UI works great and I have no complaints.

"swaggerVersion": "2.0",
"resourcePath": "/document_list",
"apis": [
"path": "/document_list",
"operations": [
"httpMethod": "GET",
"summary": "Search for documents based on a set of criteria",
"produces": [

In App_Start>SwaggerConfig.cs

// Similar to Schema filters, Swashbuckle also supports Operation and Document filters:
// Post-modify Operation descriptions once they’ve been generated by wiring up one or more
// Operation filters.

Swagger XML and JSON options

public class CustomResponseType : IOperationFilter
            public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)
                if (operation.produces.Contains("text/json"))
                if (!operation.produces.Contains("application/json"))
                if (!operation.produces.Contains("application/xml"))

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.