diff --git a/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs new file mode 100644 index 000000000..0b2751597 --- /dev/null +++ b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileController.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using NzbDrone.Core.Languages; +using Sonarr.Http; +using Sonarr.Http.REST; +using Sonarr.Http.REST.Attributes; + +namespace Sonarr.Api.V3.Profiles.Languages +{ + [V3ApiController] + [Obsolete("Deprecated")] + public class LanguageProfileController : RestController + { + [RestPostById] + [Produces("application/json")] + [Consumes("application/json")] + public ActionResult Create(LanguageProfileResource resource) + { + return Accepted(resource); + } + + [RestDeleteById] + public void DeleteProfile(int id) + { + } + + [RestPutById] + [Produces("application/json")] + [Consumes("application/json")] + public ActionResult Update(LanguageProfileResource resource) + { + return Accepted(resource); + } + + [RestGetById] + [Produces("application/json")] + protected override LanguageProfileResource GetResourceById(int id) + { + return new LanguageProfileResource + { + Id = 1, + Name = "Deprecated", + UpgradeAllowed = true, + Cutoff = Language.English, + Languages = new List + { + new LanguageProfileItemResource + { + Language = Language.English, + Allowed = true + } + } + }; + } + + [HttpGet] + [Produces("application/json")] + public ActionResult> GetAll() + { + return new List + { + new LanguageProfileResource + { + Id = 1, + Name = "Deprecated", + UpgradeAllowed = true, + Cutoff = Language.English, + Languages = new List + { + new LanguageProfileItemResource + { + Language = Language.English, + Allowed = true + } + } + } + }; + } + } +} diff --git a/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileResource.cs b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileResource.cs new file mode 100644 index 000000000..35c745672 --- /dev/null +++ b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileResource.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using System.Linq; +using Sonarr.Http.REST; + +namespace Sonarr.Api.V3.Profiles.Languages +{ + public class LanguageProfileResource : RestResource + { + public string Name { get; set; } + public bool UpgradeAllowed { get; set; } + public NzbDrone.Core.Languages.Language Cutoff { get; set; } + public List Languages { get; set; } + } + + public class LanguageProfileItemResource : RestResource + { + public NzbDrone.Core.Languages.Language Language { get; set; } + public bool Allowed { get; set; } + } +} diff --git a/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileSchemaController.cs b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileSchemaController.cs new file mode 100644 index 000000000..fd3e549cc --- /dev/null +++ b/src/Sonarr.Api.V3/Profiles/Languages/LanguageProfileSchemaController.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Mvc; +using NzbDrone.Core.Languages; +using Sonarr.Http; +using Sonarr.Http.REST; + +namespace Sonarr.Api.V3.Profiles.Languages +{ + [V3ApiController("languageprofile/schema")] + [Obsolete("Deprecated")] + public class LanguageProfileSchemaController : RestController + { + [HttpGet] + [Produces("application/json")] + public LanguageProfileResource GetSchema() + { + return new LanguageProfileResource + { + Id = 1, + Name = "Deprecated", + UpgradeAllowed = true, + Cutoff = Language.English, + Languages = new List + { + new LanguageProfileItemResource + { + Language = Language.English, + Allowed = true + } + } + }; + } + + protected override LanguageProfileResource GetResourceById(int id) + { + throw new global::System.NotImplementedException(); + } + } +} diff --git a/src/Sonarr.Api.V3/Series/SeriesResource.cs b/src/Sonarr.Api.V3/Series/SeriesResource.cs index 42bb71c29..1bdf58ae3 100644 --- a/src/Sonarr.Api.V3/Series/SeriesResource.cs +++ b/src/Sonarr.Api.V3/Series/SeriesResource.cs @@ -66,6 +66,9 @@ namespace Sonarr.Api.V3.Series public SeriesStatisticsResource Statistics { get; set; } public bool? EpisodesChanged { get; set; } + + [Obsolete("Deprecated")] + public int LanguageProfileId => 1; } public static class SeriesResourceMapper diff --git a/src/Sonarr.Api.V3/openapi.json b/src/Sonarr.Api.V3/openapi.json index f71bf87dc..900204fd2 100644 --- a/src/Sonarr.Api.V3/openapi.json +++ b/src/Sonarr.Api.V3/openapi.json @@ -27,6 +27,18 @@ } ], "paths": { + "/api": { + "get": { + "tags": [ + "ApiInfo" + ], + "responses": { + "200": { + "description": "Success" + } + } + } + }, "/login": { "post": { "tags": [ @@ -1596,7 +1608,24 @@ }, "responses": { "200": { - "description": "Success" + "description": "Success", + "content": { + "text/plain": { + "schema": { + "$ref": "#/components/schemas/EpisodeResource" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/EpisodeResource" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/EpisodeResource" + } + } + } } } }, @@ -3088,6 +3117,195 @@ } } }, + "/api/v3/languageprofile": { + "post": { + "tags": [ + "LanguageProfile" + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + }, + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + }, + "deprecated": true + }, + "get": { + "tags": [ + "LanguageProfile" + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + } + }, + "deprecated": true + } + }, + "/api/v3/languageprofile/{id}": { + "delete": { + "tags": [ + "LanguageProfile" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "Success" + } + }, + "deprecated": true + }, + "put": { + "tags": [ + "LanguageProfile" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + }, + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + }, + "deprecated": true + }, + "get": { + "tags": [ + "LanguageProfile" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + } + } + }, + "/api/v3/languageprofile/schema": { + "get": { + "tags": [ + "LanguageProfileSchema" + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + }, + "deprecated": true + } + }, + "/api/v3/languageprofile/schema/{id}": { + "get": { + "tags": [ + "LanguageProfileSchema" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer", + "format": "int32" + } + } + ], + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/LanguageProfileResource" + } + } + } + } + } + } + }, "/api/v3/localization": { "get": { "tags": [ @@ -8064,6 +8282,49 @@ }, "additionalProperties": false }, + "LanguageProfileItemResource": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int32" + }, + "language": { + "$ref": "#/components/schemas/Language" + }, + "allowed": { + "type": "boolean" + } + }, + "additionalProperties": false + }, + "LanguageProfileResource": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int32" + }, + "name": { + "type": "string", + "nullable": true + }, + "upgradeAllowed": { + "type": "boolean" + }, + "cutoff": { + "$ref": "#/components/schemas/Language" + }, + "languages": { + "type": "array", + "items": { + "$ref": "#/components/schemas/LanguageProfileItemResource" + }, + "nullable": true + } + }, + "additionalProperties": false + }, "LanguageResource": { "type": "object", "properties": { @@ -10004,6 +10265,9 @@ }, "nullable": true }, + "originalLanguage": { + "$ref": "#/components/schemas/Language" + }, "remotePoster": { "type": "string", "nullable": true @@ -10116,6 +10380,12 @@ "episodesChanged": { "type": "boolean", "nullable": true + }, + "languageProfileId": { + "type": "integer", + "format": "int32", + "readOnly": true, + "deprecated": true } }, "additionalProperties": false diff --git a/src/Sonarr.Http/REST/RestController.cs b/src/Sonarr.Http/REST/RestController.cs index 03f615ffb..13c51cd4b 100644 --- a/src/Sonarr.Http/REST/RestController.cs +++ b/src/Sonarr.Http/REST/RestController.cs @@ -6,6 +6,8 @@ using FluentValidation.Results; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Filters; +using NLog; +using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Datastore; using Sonarr.Http.REST.Attributes; using Sonarr.Http.Validation; @@ -16,6 +18,9 @@ namespace Sonarr.Http.REST where TResource : RestResource, new() { private static readonly List VALIDATE_ID_ATTRIBUTES = new List { typeof(RestPutByIdAttribute), typeof(RestDeleteByIdAttribute) }; + private static readonly Type DEPRECATED_ATTRIBUTE = typeof(ObsoleteAttribute); + + private readonly Logger _logger; protected ResourceValidator PostValidator { get; private set; } protected ResourceValidator PutValidator { get; private set; } @@ -31,6 +36,8 @@ namespace Sonarr.Http.REST protected RestController() { + _logger = NzbDroneLogger.GetLogger(this); + PostValidator = new ResourceValidator(); PutValidator = new ResourceValidator(); SharedValidator = new ResourceValidator(); @@ -89,6 +96,13 @@ namespace Sonarr.Http.REST } } + var controllerAttributes = descriptor.ControllerTypeInfo.CustomAttributes; + if (controllerAttributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE) || attributes.Any(x => x.AttributeType == DEPRECATED_ATTRIBUTE)) + { + _logger.Warn("API call made to deprecated endpoint from {0}", Request.Headers.UserAgent.ToString()); + Response.Headers.Add("Deprecation", "true"); + } + base.OnActionExecuting(context); }