From 2133c6e3483104ad2b38c9eab4a6bb2653d28dad Mon Sep 17 00:00:00 2001 From: David Mouse Date: Fri, 1 Apr 2022 01:52:36 -0400 Subject: [PATCH 1/2] Parameterize request body of UpdateNamedConfiguration This gives OpenAPI clients the knowledge that they should provide a body of some kind. --- Jellyfin.Api/Controllers/ConfigurationController.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Jellyfin.Api/Controllers/ConfigurationController.cs b/Jellyfin.Api/Controllers/ConfigurationController.cs index 60529e990..464fadc06 100644 --- a/Jellyfin.Api/Controllers/ConfigurationController.cs +++ b/Jellyfin.Api/Controllers/ConfigurationController.cs @@ -86,21 +86,23 @@ namespace Jellyfin.Api.Controllers /// Updates named configuration. /// /// Configuration key. + /// Configuration. /// Named configuration updated. /// Update status. [HttpPost("Configuration/{key}")] [Authorize(Policy = Policies.RequiresElevation)] [ProducesResponseType(StatusCodes.Status204NoContent)] - public async Task UpdateNamedConfiguration([FromRoute, Required] string key) + public ActionResult UpdateNamedConfiguration([FromRoute, Required] string key, [FromBody, Required] JsonDocument configuration) { var configurationType = _configurationManager.GetConfigurationType(key); - var configuration = await JsonSerializer.DeserializeAsync(Request.Body, configurationType, _serializerOptions).ConfigureAwait(false); - if (configuration == null) + var deserializedConfiguration = configuration.Deserialize(configurationType, _serializerOptions); + + if (deserializedConfiguration == null) { throw new ArgumentException("Body doesn't contain a valid configuration"); } - _configurationManager.SaveConfiguration(key, configuration); + _configurationManager.SaveConfiguration(key, deserializedConfiguration); return NoContent(); } From e9ce82445e50e64827c968b8d2a30d1634e30c5a Mon Sep 17 00:00:00 2001 From: David Mouse Date: Fri, 1 Apr 2022 01:55:28 -0400 Subject: [PATCH 2/2] Add ConfigurationType Types to generated OpenAPI This allows clients to see and work with the associated types for each NamedConfiguration key, even if the UpdateNamedConfiguration endpoint doesn't properly advertise its types. --- .../AppBase/BaseConfigurationManager.cs | 6 ++++++ .../Filters/AdditionalModelFilter.cs | 19 ++++++++++++++++++- .../Configuration/IConfigurationManager.cs | 6 ++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs index 19fe0b108..2a4a8fb13 100644 --- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs +++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs @@ -398,6 +398,12 @@ namespace Emby.Server.Implementations.AppBase }); } + /// + public ConfigurationStore[] GetConfigurationStores() + { + return _configurationStores; + } + /// public Type GetConfigurationType(string key) { diff --git a/Jellyfin.Server/Filters/AdditionalModelFilter.cs b/Jellyfin.Server/Filters/AdditionalModelFilter.cs index 87a59e0b4..44e5b0d1e 100644 --- a/Jellyfin.Server/Filters/AdditionalModelFilter.cs +++ b/Jellyfin.Server/Filters/AdditionalModelFilter.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Plugins; +using MediaBrowser.Common.Plugins; +using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.LiveTv; using MediaBrowser.Model.ApiClient; using MediaBrowser.Model.Entities; @@ -14,6 +15,17 @@ namespace Jellyfin.Server.Filters /// public class AdditionalModelFilter : IDocumentFilter { + private readonly IServerConfigurationManager _serverConfigurationManager; + + /// + /// Initializes a new instance of the class. + /// + /// Instance of the interface. + public AdditionalModelFilter(IServerConfigurationManager serverConfigurationManager) + { + _serverConfigurationManager = serverConfigurationManager; + } + /// 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(ServerDiscoveryInfo), context.SchemaRepository); + + foreach (var configuration in _serverConfigurationManager.GetConfigurationStores()) + { + context.SchemaGenerator.GenerateSchema(configuration.ConfigurationType, context.SchemaRepository); + } } } } diff --git a/MediaBrowser.Common/Configuration/IConfigurationManager.cs b/MediaBrowser.Common/Configuration/IConfigurationManager.cs index fc63d9350..e6696a571 100644 --- a/MediaBrowser.Common/Configuration/IConfigurationManager.cs +++ b/MediaBrowser.Common/Configuration/IConfigurationManager.cs @@ -60,6 +60,12 @@ namespace MediaBrowser.Common.Configuration /// System.Object. object GetConfiguration(string key); + /// + /// Gets the array of coniguration stores. + /// + /// Array of ConfigurationStore. + ConfigurationStore[] GetConfigurationStores(); + /// /// Gets the type of the configuration. ///