clean up output formatters

This commit is contained in:
crobibero 2020-08-20 11:17:27 -06:00
parent 634ee2d1e9
commit 2ca8d31b20
5 changed files with 14 additions and 5 deletions

View File

@ -8,7 +8,10 @@ namespace Jellyfin.Api
/// </summary> /// </summary>
[ApiController] [ApiController]
[Route("[controller]")] [Route("[controller]")]
[Produces(MediaTypeNames.Application.Json)] [Produces(
MediaTypeNames.Application.Json,
MediaTypeNames.Application.Json + "; profile=\"CamelCase\"",
MediaTypeNames.Application.Json + "; profile=\"PascalCase\"")]
public class BaseJellyfinApiController : ControllerBase public class BaseJellyfinApiController : ControllerBase
{ {
} }

View File

@ -150,6 +150,10 @@ namespace Jellyfin.Server.Extensions
.AddMvc(opts => .AddMvc(opts =>
{ {
opts.UseGeneralRoutePrefix(baseUrl); opts.UseGeneralRoutePrefix(baseUrl);
// Allow requester to change between camelCase and PascalCase
opts.RespectBrowserAcceptHeader = true;
opts.OutputFormatters.Insert(0, new CamelCaseJsonProfileFormatter()); opts.OutputFormatters.Insert(0, new CamelCaseJsonProfileFormatter());
opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter()); opts.OutputFormatters.Insert(0, new PascalCaseJsonProfileFormatter());

View File

@ -15,7 +15,7 @@ namespace Jellyfin.Server.Formatters
public CamelCaseJsonProfileFormatter() : base(JsonDefaults.GetCamelCaseOptions()) public CamelCaseJsonProfileFormatter() : base(JsonDefaults.GetCamelCaseOptions())
{ {
SupportedMediaTypes.Clear(); SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"CamelCase\"")); SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json; profile=\"CamelCase\""));
} }
} }
} }

View File

@ -1,3 +1,4 @@
using System.Net.Mime;
using MediaBrowser.Common.Json; using MediaBrowser.Common.Json;
using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
@ -16,8 +17,8 @@ namespace Jellyfin.Server.Formatters
{ {
SupportedMediaTypes.Clear(); SupportedMediaTypes.Clear();
// Add application/json for default formatter // Add application/json for default formatter
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json")); SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse(MediaTypeNames.Application.Json));
SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json;profile=\"PascalCase\"")); SupportedMediaTypes.Add(MediaTypeHeaderValue.Parse("application/json; profile=\"PascalCase\""));
} }
} }
} }

View File

@ -16,8 +16,9 @@ namespace Jellyfin.Server.Formatters
/// </summary> /// </summary>
public XmlOutputFormatter() public XmlOutputFormatter()
{ {
SupportedMediaTypes.Clear();
SupportedMediaTypes.Add(MediaTypeNames.Text.Xml); SupportedMediaTypes.Add(MediaTypeNames.Text.Xml);
SupportedMediaTypes.Add("text/xml;charset=UTF-8");
SupportedEncodings.Add(Encoding.UTF8); SupportedEncodings.Add(Encoding.UTF8);
SupportedEncodings.Add(Encoding.Unicode); SupportedEncodings.Add(Encoding.Unicode);
} }