Merge pull request #7561 from DMouse10462/named-config-api-fix

Fix NamedConfiguration API Generation
This commit is contained in:
Cody Robibero 2022-04-09 08:45:13 -06:00 committed by GitHub
commit d7c548f3db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 5 deletions

View File

@ -398,6 +398,12 @@ namespace Emby.Server.Implementations.AppBase
}); });
} }
/// <inheritdoc />
public ConfigurationStore[] GetConfigurationStores()
{
return _configurationStores;
}
/// <inheritdoc /> /// <inheritdoc />
public Type GetConfigurationType(string key) public Type GetConfigurationType(string key)
{ {

View File

@ -86,21 +86,23 @@ namespace Jellyfin.Api.Controllers
/// Updates named configuration. /// Updates named configuration.
/// </summary> /// </summary>
/// <param name="key">Configuration key.</param> /// <param name="key">Configuration key.</param>
/// <param name="configuration">Configuration.</param>
/// <response code="204">Named configuration updated.</response> /// <response code="204">Named configuration updated.</response>
/// <returns>Update status.</returns> /// <returns>Update status.</returns>
[HttpPost("Configuration/{key}")] [HttpPost("Configuration/{key}")]
[Authorize(Policy = Policies.RequiresElevation)] [Authorize(Policy = Policies.RequiresElevation)]
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<ActionResult> UpdateNamedConfiguration([FromRoute, Required] string key) public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument configuration)
{ {
var configurationType = _configurationManager.GetConfigurationType(key); var configurationType = _configurationManager.GetConfigurationType(key);
var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false); var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions);
if (configuration == null)
if (deserializedConfiguration == null)
{ {
throw new ArgumentException("Body doesn't contain a valid configuration"); throw new ArgumentException("Body doesn't contain a valid configuration");
} }
_configurationManager.SaveConfiguration(key, configuration); _configurationManager.SaveConfiguration(key, deserializedConfiguration);
return NoContent(); return NoContent();
} }

View File

@ -1,4 +1,5 @@
using MediaBrowser.Common.Plugins; using MediaBrowser.Common.Plugins;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Model.ApiClient; using MediaBrowser.Model.ApiClient;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
@ -14,6 +15,17 @@ namespace Jellyfin.Server.Filters
/// </summary> /// </summary>
public class AdditionalModelFilter : IDocumentFilter public class AdditionalModelFilter : IDocumentFilter
{ {
private readonly IServerConfigurationManager _serverConfigurationManager;
/// <summary>
/// Initializes a new instance of the <see cref="AdditionalModelFilter"/> class.
/// </summary>
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
public AdditionalModelFilter(IServerConfigurationManager serverConfigurationManager)
{
_serverConfigurationManager = serverConfigurationManager;
}
/// <inheritdoc /> /// <inheritdoc />
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{ {
@ -29,6 +41,11 @@ namespace Jellyfin.Server.Filters
context.SchemaGenerator.GenerateSchema(typeof(SessionMessageType), context.SchemaRepository); context.SchemaGenerator.GenerateSchema(typeof(SessionMessageType), context.SchemaRepository);
context.SchemaGenerator.GenerateSchema(typeof(ServerDiscoveryInfo), context.SchemaRepository); context.SchemaGenerator.GenerateSchema(typeof(ServerDiscoveryInfo), context.SchemaRepository);
foreach (var configuration in _serverConfigurationManager.GetConfigurationStores())
{
context.SchemaGenerator.GenerateSchema(configuration.ConfigurationType, context.SchemaRepository);
}
} }
} }
} }

View File

@ -60,6 +60,12 @@ namespace MediaBrowser.Common.Configuration
/// <returns>System.Object.</returns> /// <returns>System.Object.</returns>
object GetConfiguration(string key); object GetConfiguration(string key);
/// <summary>
/// Gets the array of coniguration stores.
/// </summary>
/// <returns>Array of ConfigurationStore.</returns>
ConfigurationStore[] GetConfigurationStores();
/// <summary> /// <summary>
/// Gets the type of the configuration. /// Gets the type of the configuration.
/// </summary> /// </summary>