Api 2.2 changes
This commit is contained in:
1 parent
7bc93bc12a
commit
638a468732
27 files changed
+15632
-1528
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -48,7 +48,7 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
||||
}
|
||||
|
||||
public Task<Film> GetSingleFilm(int filmId, CancellationToken? cancellationToken = null)
|
||||
=> Invoke((ct) => _apiClient.FilmsAsync(filmId, new[] { Anonymous.BUDGET, Anonymous.REVIEW, Anonymous.RATING, Anonymous.POSTERS }, ct), cancellationToken);
|
||||
=> Invoke((ct) => _apiClient.FilmsAsync(filmId, ct), cancellationToken);
|
||||
|
||||
public Task<ICollection<StaffResponse>> GetStaff(int filmId, CancellationToken? cancellationToken = null)
|
||||
=> Invoke((ct) => _apiClient.StaffAllAsync(filmId, ct), cancellationToken);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||
<PackageReference Include="NSwag.MSBuild" Version="13.11.1">
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class BadDoubleConverter : JsonConverter
|
||||
{
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => false;
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
=> objectType == typeof(double);
|
||||
|
||||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
if (double.TryParse(Convert.ToString(reader.Value), out var result))
|
||||
return result;
|
||||
|
||||
return 0.0d;
|
||||
}
|
||||
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class BadFilmSearchResponse_filmsTypeConverter : StringEnumConverter
|
||||
{
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
=> objectType == typeof(FilmSearchResponse_filmsType);
|
||||
|
||||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
try
|
||||
{
|
||||
return base.ReadJson(reader, objectType, existingValue, serializer);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return FilmSearchResponse_filmsType.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -3,7 +3,7 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class IntegerOverflowConverter : JsonConverter
|
||||
public class BadIntegerConverter : JsonConverter
|
||||
{
|
||||
public override bool CanRead => true;
|
||||
public override bool CanWrite => false;
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class BadProductionStatusConverter : StringEnumConverter
|
||||
{
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
=> objectType == typeof(FilmProductionStatus);
|
||||
|
||||
public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
|
||||
{
|
||||
try
|
||||
{
|
||||
return base.ReadJson(reader, objectType, existingValue, serializer);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return FilmProductionStatus.UNKNOWN;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ using Newtonsoft.Json.Converters;
|
||||
|
||||
namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class ProfessionKeyConverter : StringEnumConverter
|
||||
public class BadProfessionKeyConverter : StringEnumConverter
|
||||
{
|
||||
public override bool CanConvert(System.Type objectType)
|
||||
=> objectType == typeof(PersonResponse_filmsProfessionKey);
|
||||
+12
-30
@@ -8,15 +8,12 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
||||
{
|
||||
public class DeclarationPatcherContractResolver : DefaultContractResolver
|
||||
{
|
||||
private readonly JsonConverter _integerConverter = new IntegerOverflowConverter();
|
||||
|
||||
private readonly ICollection<(System.Type, string)> _allowNull = new[] {
|
||||
(typeof(CommonFilmData), "ratingAgeLimits"),
|
||||
(typeof(Budget), null),
|
||||
};
|
||||
|
||||
private readonly ICollection<(System.Type, string, JsonConverter)> _patchConverters = new[] {
|
||||
(typeof(object), (string)null, (JsonConverter)new ProfessionKeyConverter()),
|
||||
private readonly ICollection<JsonConverter> _badConverters = new JsonConverter[] {
|
||||
new BadIntegerConverter(),
|
||||
new BadDoubleConverter(),
|
||||
new BadProfessionKeyConverter(),
|
||||
new BadProductionStatusConverter(),
|
||||
new BadFilmSearchResponse_filmsTypeConverter(),
|
||||
};
|
||||
|
||||
protected override IList<JsonProperty> CreateProperties(System.Type type, MemberSerialization memberSerialization)
|
||||
@@ -24,33 +21,18 @@ namespace KinopoiskUnofficialInfo.ApiClient
|
||||
var list = base.CreateProperties(type, memberSerialization);
|
||||
foreach (var property in list)
|
||||
{
|
||||
if (_allowNull.Any((config) => type == config.Item1
|
||||
&& (string.IsNullOrEmpty(config.Item2) || property.PropertyName == config.Item2)))
|
||||
foreach (var badConverter in _badConverters)
|
||||
{
|
||||
property.Required = Required.Default;
|
||||
property.DefaultValue = -1;
|
||||
|
||||
if (_integerConverter.CanConvert(property.PropertyType))
|
||||
if (badConverter.CanConvert(property.PropertyType))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = _integerConverter;
|
||||
}
|
||||
}
|
||||
property.Converter = badConverter;
|
||||
|
||||
var patchConverters = _patchConverters
|
||||
.Where((config) => (config.Item1 == typeof(object) || type == config.Item1)
|
||||
&& (string.IsNullOrEmpty(config.Item2) || property.PropertyName == config.Item2))
|
||||
.ToArray();
|
||||
foreach (var patchConverter in patchConverters)
|
||||
{
|
||||
if (patchConverter.Item3.CanConvert(property.PropertyType))
|
||||
{
|
||||
#pragma warning disable CS0618
|
||||
property.MemberConverter = null;
|
||||
#pragma warning restore CS0618
|
||||
property.Converter = patchConverter.Item3;
|
||||
property.Required = Required.Default;
|
||||
// property.DefaultValue = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user