mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-26 10:44:50 +03:00
Merge remote-tracking branch 'upstream/api-migration' into api-cors
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json.Serialization;
|
||||
using Jellyfin.Api;
|
||||
using Jellyfin.Api.Auth;
|
||||
using Jellyfin.Api.Auth.FirstTimeSetupOrElevatedPolicy;
|
||||
@@ -12,6 +11,8 @@ using Jellyfin.Api.Constants;
|
||||
using Jellyfin.Api.Controllers;
|
||||
using Jellyfin.Server.Formatters;
|
||||
using Jellyfin.Server.Models;
|
||||
using MediaBrowser.Common.Json;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -89,8 +90,20 @@ namespace Jellyfin.Server.Extensions
|
||||
.AddApplicationPart(typeof(StartupController).Assembly)
|
||||
.AddJsonOptions(options =>
|
||||
{
|
||||
// Setting the naming policy to null leaves the property names as-is when serializing objects to JSON.
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = null;
|
||||
// Update all properties that are set in JsonDefaults
|
||||
var jsonOptions = JsonDefaults.PascalCase;
|
||||
|
||||
// From JsonDefaults
|
||||
options.JsonSerializerOptions.ReadCommentHandling = jsonOptions.ReadCommentHandling;
|
||||
options.JsonSerializerOptions.WriteIndented = jsonOptions.WriteIndented;
|
||||
options.JsonSerializerOptions.Converters.Clear();
|
||||
foreach (var converter in jsonOptions.Converters)
|
||||
{
|
||||
options.JsonSerializerOptions.Converters.Add(converter);
|
||||
}
|
||||
|
||||
// From JsonDefaults.PascalCase
|
||||
options.JsonSerializerOptions.PropertyNamingPolicy = jsonOptions.PropertyNamingPolicy;
|
||||
})
|
||||
.AddControllersAsServices();
|
||||
}
|
||||
@@ -104,7 +117,7 @@ namespace Jellyfin.Server.Extensions
|
||||
{
|
||||
return serviceCollection.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("api-docs", new OpenApiInfo { Title = "Jellyfin API" });
|
||||
c.SwaggerDoc("api-docs", new OpenApiInfo { Title = "Jellyfin API", Version = "v1" });
|
||||
|
||||
// Add all xml doc files to swagger generator.
|
||||
var xmlFiles = Directory.GetFiles(
|
||||
@@ -124,7 +137,30 @@ namespace Jellyfin.Server.Extensions
|
||||
// Use method name as operationId
|
||||
c.CustomOperationIds(description =>
|
||||
description.TryGetMethodInfo(out MethodInfo methodInfo) ? methodInfo.Name : null);
|
||||
|
||||
// TODO - remove when all types are supported in System.Text.Json
|
||||
c.AddSwaggerTypeMappings();
|
||||
});
|
||||
}
|
||||
|
||||
private static void AddSwaggerTypeMappings(this SwaggerGenOptions options)
|
||||
{
|
||||
/*
|
||||
* TODO remove when System.Text.Json supports non-string keys.
|
||||
* Used in Jellyfin.Api.Controller.GetChannels.
|
||||
*/
|
||||
options.MapType<Dictionary<ImageType, string>>(() =>
|
||||
new OpenApiSchema
|
||||
{
|
||||
Type = "object",
|
||||
Properties = typeof(ImageType).GetEnumNames().ToDictionary(
|
||||
name => name,
|
||||
name => new OpenApiSchema
|
||||
{
|
||||
Type = "string",
|
||||
Format = "string"
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user