fix: free-quota exception from njsonschema generator

pull/47/head
Robert Dailey 3 years ago
parent 8dd1f9c676
commit 1a008e272e

@ -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

@ -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'
}
}
}
}
";
}
}

@ -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<string>? errorMessages;
schema = _generator.Generate(typeof(SonarrReleaseProfile));
schema = JSchema.Parse(SonarrReleaseProfileSchema.V2);
if (profile.IsValid(schema, out errorMessages))
{
return profile.ToObject<SonarrReleaseProfile>()
@ -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.

Loading…
Cancel
Save