Change ServiceStack default format to JSON, but keep HTML format for SwaggerUI Change ServiceStack default format to JSON, but keep HTML format for SwaggerUI json json

Change ServiceStack default format to JSON, but keep HTML format for SwaggerUI


The issue is removing the HTML Format essentially removes HTML ContentType from consideration, but I've changed it to preserve the Content Type if the Service returns a raw HTML string in this commit where the Swagger UI can return HTML pages even if the HTML Format is disabled.

This change is available from v5.4.1 that's now available on MyGet.

An alternative is to leave the HTML Format enabled but use a request filter to change the Content Type to JSON where it's HTML for all Requests you want to do this for, e.g:

PreRequestFilters.Add((req, res) => {    if (req.ResponseContentType.Matches(MimeTypes.Html) && !req.PathInfo.StartsWith("/swagger-ui"))        req.ResponseContentType = MimeTypes.Json;});