From 1a008e272e17aaf912af6511f5b9ba173f73d4c1 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Sun, 24 Oct 2021 09:40:23 -0500 Subject: [PATCH] fix: free-quota exception from njsonschema generator --- CHANGELOG.md | 5 + .../Api/Schemas/SonarrReleaseProfileSchema.cs | 164 ++++++++++++++++++ ...onarrReleaseProfileCompatibilityHandler.cs | 14 +- 3 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 src/TrashLib/Sonarr/Api/Schemas/SonarrReleaseProfileSchema.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 993fd762..629ac8e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix "free-quota limit" exception that occurred in new JSON schema generation logic that was added + for API backward compatibility with Sonarr. + ## [1.6.4] - 2021-10-23 ### FIXED diff --git a/src/TrashLib/Sonarr/Api/Schemas/SonarrReleaseProfileSchema.cs b/src/TrashLib/Sonarr/Api/Schemas/SonarrReleaseProfileSchema.cs new file mode 100644 index 00000000..20a471af --- /dev/null +++ b/src/TrashLib/Sonarr/Api/Schemas/SonarrReleaseProfileSchema.cs @@ -0,0 +1,164 @@ +namespace TrashLib.Sonarr.Api.Schemas +{ + public static class SonarrReleaseProfileSchema + { + public static string V1 => @"{ + 'definitions': { + 'SonarrPreferredTerm': { + 'type': [ + 'object', + 'null' + ], + 'properties': { + 'key': { + 'type': [ + 'string', + 'null' + ] + }, + 'value': { + 'type': 'integer' + } + } + } + }, + 'type': 'object', + 'properties': { + 'id': { + 'type': 'integer' + }, + 'enabled': { + 'type': 'boolean' + }, + 'name': { + 'type': [ + 'string', + 'null' + ] + }, + 'required': { + 'type': [ + 'string', + 'null' + ] + }, + 'ignored': { + 'type': [ + 'string', + 'null' + ] + }, + 'preferred': { + 'type': [ + 'array', + 'null' + ], + 'items': { + '$ref': '#/definitions/SonarrPreferredTerm' + } + }, + 'includePreferredWhenRenaming': { + 'type': 'boolean' + }, + 'indexerId': { + 'type': 'integer' + }, + 'tags': { + 'type': [ + 'array', + 'null' + ], + 'items': { + 'type': 'integer' + } + } + } +}"; + + public static string V2 => @"{ + 'definitions': { + 'SonarrPreferredTerm': { + 'type': [ + 'object', + 'null' + ], + 'properties': { + 'key': { + 'type': [ + 'string', + 'null' + ] + }, + 'value': { + 'type': 'integer' + } + } + } + }, + 'type': 'object', + 'properties': { + 'id': { + 'type': 'integer' + }, + 'enabled': { + 'type': 'boolean' + }, + 'name': { + 'type': [ + 'string', + 'null' + ] + }, + 'required': { + 'type': [ + 'array', + 'null' + ], + 'items': { + 'type': [ + 'string', + 'null' + ] + } + }, + 'ignored': { + 'type': [ + 'array', + 'null' + ], + 'items': { + 'type': [ + 'string', + 'null' + ] + } + }, + 'preferred': { + 'type': [ + 'array', + 'null' + ], + 'items': { + '$ref': '#/definitions/SonarrPreferredTerm' + } + }, + 'includePreferredWhenRenaming': { + 'type': 'boolean' + }, + 'indexerId': { + 'type': 'integer' + }, + 'tags': { + 'type': [ + 'array', + 'null' + ], + 'items': { + 'type': 'integer' + } + } + } +} +"; + } +} diff --git a/src/TrashLib/Sonarr/Api/SonarrReleaseProfileCompatibilityHandler.cs b/src/TrashLib/Sonarr/Api/SonarrReleaseProfileCompatibilityHandler.cs index bcf3af31..14e1c482 100644 --- a/src/TrashLib/Sonarr/Api/SonarrReleaseProfileCompatibilityHandler.cs +++ b/src/TrashLib/Sonarr/Api/SonarrReleaseProfileCompatibilityHandler.cs @@ -1,20 +1,17 @@ using System.Collections.Generic; using System.IO; using AutoMapper; -using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Newtonsoft.Json.Schema; -using Newtonsoft.Json.Schema.Generation; -using Newtonsoft.Json.Serialization; using Serilog; using TrashLib.Sonarr.Api.Objects; +using TrashLib.Sonarr.Api.Schemas; namespace TrashLib.Sonarr.Api { public class SonarrReleaseProfileCompatibilityHandler : ISonarrReleaseProfileCompatibilityHandler { private readonly ISonarrCompatibility _compatibility; - private readonly JSchemaGenerator _generator; private readonly IMapper _mapper; public SonarrReleaseProfileCompatibilityHandler( @@ -23,11 +20,6 @@ namespace TrashLib.Sonarr.Api { _compatibility = compatibility; _mapper = mapper; - _generator = new JSchemaGenerator - { - ContractResolver = new CamelCasePropertyNamesContractResolver(), - DefaultRequired = Required.Default - }; } public object CompatibleReleaseProfileForSending(SonarrReleaseProfile profile) @@ -42,7 +34,7 @@ namespace TrashLib.Sonarr.Api JSchema? schema; IList? errorMessages; - schema = _generator.Generate(typeof(SonarrReleaseProfile)); + schema = JSchema.Parse(SonarrReleaseProfileSchema.V2); if (profile.IsValid(schema, out errorMessages)) { return profile.ToObject() @@ -51,7 +43,7 @@ namespace TrashLib.Sonarr.Api Log.Debug("SonarrReleaseProfile is not a match for V2, proceeding to V1: {Reasons}", errorMessages); - schema = _generator.Generate(typeof(SonarrReleaseProfileV1)); + schema = JSchema.Parse(SonarrReleaseProfileSchema.V1); if (profile.IsValid(schema, out errorMessages)) { // This will throw if there's an issue during mapping.