From 97f48f935e9e15781734df13ccc2e649ed14dc9a Mon Sep 17 00:00:00 2001 From: Hristo Kolev Date: Sat, 22 Jan 2022 19:13:58 +0200 Subject: [PATCH] fixed json mappings --- increment-version.sh | 22 +++- src/TvDbSharper/TvDbClient.Generated.cs | 43 +++++-- src/TvDbSharper/TvDbSharper.csproj | 8 +- test/GenerateDto/CodeBuilder.cs | 149 +++++++++++++++++++++++- test/GenerateDto/GenerateDto.csproj | 4 +- test/ManualTests/Program.cs | 45 ++++--- 6 files changed, 225 insertions(+), 46 deletions(-) diff --git a/increment-version.sh b/increment-version.sh index 56e95d3..3b6168a 100755 --- a/increment-version.sh +++ b/increment-version.sh @@ -2,6 +2,16 @@ VERSION_POSITION=$1 +TMP_SOURCE="${BASH_SOURCE[0]}" +while [ -h "$TMP_SOURCE" ]; do + SCRIPT_PATH="$( cd -P "$( dirname "$TMP_SOURCE" )" >/dev/null 2>&1 && pwd )" + TMP_SOURCE="$(readlink "$TMP_SOURCE")" + [[ $TMP_SOURCE != /* ]] && TMP_SOURCE="$SCRIPT_PATH/$TMP_SOURCE" +done +SCRIPT_PATH="$( cd -P "$( dirname "$TMP_SOURCE" )" >/dev/null 2>&1 && pwd )" + +set -eu -o pipefail + # Accepts a version string and prints it incremented by one. # Usage: increment_version [] [] increment_version() { @@ -66,15 +76,15 @@ increment_version() { return 0 } -FIRST_PROJECT_FILE_PATH=$(find ./ -name '*.csproj' | head -n 1) -VERSION_NUMBER=$(cat $FIRST_PROJECT_FILE_PATH | grep -Eo '.+' | grep -Eo '[0-9]+.[0-9]+.[0-9]+') +FIRST_PROJECT_FILE_PATH=$(find "$SCRIPT_PATH" -name '*.csproj' | head -n 1) +VERSION_NUMBER=$(cat "$FIRST_PROJECT_FILE_PATH" | grep -Eo '.+' | grep -Eo '[0-9]+.[0-9]+.[0-9]+') INCREMENTED_VERSION=$(increment_version $VERSION_NUMBER $VERSION_POSITION) echo "$VERSION_NUMBER => $INCREMENTED_VERSION" -find ./ -name '*.csproj' -print0 | while read -d $'\0' file; do - sed -i -E "s,.+,$INCREMENTED_VERSION,g" $file - sed -i -E "s,.+,$INCREMENTED_VERSION,g" $file - sed -i -E "s,.+,$INCREMENTED_VERSION,g" $file +find "$SCRIPT_PATH" -name '*.csproj' -print0 | while read -d $'\0' file; do + sed -i -E "s,.+,$INCREMENTED_VERSION,g" "$file" + sed -i -E "s,.+,$INCREMENTED_VERSION,g" "$file" + sed -i -E "s,.+,$INCREMENTED_VERSION,g" "$file" done diff --git a/src/TvDbSharper/TvDbClient.Generated.cs b/src/TvDbSharper/TvDbClient.Generated.cs index 7ace5e9..48856d4 100644 --- a/src/TvDbSharper/TvDbClient.Generated.cs +++ b/src/TvDbSharper/TvDbClient.Generated.cs @@ -866,7 +866,7 @@ public class ArtworkExtendedRecordDto [JsonProperty("width")] public long Width { get; set; } - [JsonIgnore] + [JsonProperty("status")] public object Status { get; set; } } @@ -916,6 +916,30 @@ public class AwardBaseRecordDto [JsonProperty("name")] public string Name { get; set; } + + [JsonProperty("year")] + public string Year { get; set; } + + [JsonProperty("category")] + public string Category { get; set; } + + [JsonProperty("isWinner")] + public bool IsWinner { get; set; } + + [JsonProperty("details")] + public object Details { get; set; } + + [JsonProperty("series")] + public object Series { get; set; } + + [JsonProperty("movie")] + public object Movie { get; set; } + + [JsonProperty("episode")] + public object Episode { get; set; } + + [JsonProperty("character")] + public object Character { get; set; } } public class AwardCategoryBaseRecordDto @@ -1622,6 +1646,9 @@ public class MovieExtendedRecordDto [JsonProperty("companies")] public CompaniesDto Companies { get; set; } + [JsonProperty("translations")] + public TranslationExtendedDto Translations { get; set; } + [JsonProperty("runtime")] public int Runtime { get; set; } @@ -1727,8 +1754,8 @@ public class PeopleExtendedRecordDto [JsonProperty("overviewTranslations")] public string[] OverviewTranslations { get; set; } - [JsonIgnore] - public object Translations { get; set; } + [JsonProperty("translations")] + public TranslationExtendedDto Translations { get; set; } } public class PeopleTypeDto @@ -1951,8 +1978,8 @@ public class SeasonExtendedRecordDto [JsonProperty("tagOptions")] public TagOptionDto[] TagOptions { get; set; } - [JsonIgnore] - public TranslationDto[] Translations { get; set; } + [JsonProperty("translations")] + public TranslationExtendedDto Translations { get; set; } } public class SeasonTypeDto @@ -2156,7 +2183,7 @@ public class SeriesExtendedRecordDto public TrailerDto[] Trailers { get; set; } [JsonProperty("translations")] - public TranslationExtendedDto[] Translations { get; set; } + public TranslationExtendedDto Translations { get; set; } [JsonProperty("lastUpdated")] public string LastUpdated { get; set; } @@ -2308,8 +2335,8 @@ public class TranslationExtendedDto [JsonProperty("overviewTranslations")] public TranslationDto[] OverviewTranslations { get; set; } - [JsonProperty("alias")] - public string[] Alias { get; set; } + [JsonProperty("aliases")] + public string[] Aliases { get; set; } } public class TagOptionEntityDto diff --git a/src/TvDbSharper/TvDbSharper.csproj b/src/TvDbSharper/TvDbSharper.csproj index ac64ebe..8b63e2b 100644 --- a/src/TvDbSharper/TvDbSharper.csproj +++ b/src/TvDbSharper/TvDbSharper.csproj @@ -2,7 +2,7 @@ TvDbSharper is fully featured modern REST client for the TheTVDB API v4 - 4.0.6 + 4.0.7 HristoKolev netstandard1.1 $(NoWarn);1591 @@ -19,12 +19,12 @@ false false false - 4.0.6 - 4.0.6 + 4.0.7 + 4.0.7 - + diff --git a/test/GenerateDto/CodeBuilder.cs b/test/GenerateDto/CodeBuilder.cs index 99b23f0..5f814cf 100644 --- a/test/GenerateDto/CodeBuilder.cs +++ b/test/GenerateDto/CodeBuilder.cs @@ -359,6 +359,12 @@ public static class CodeBuilder OverrideType = "int?", }, new() + { + MatchClassName = "SeasonExtendedRecordDto", + MatchFieldName = "translations", + OverrideType = "TranslationExtendedDto", + }, + new() { MatchClassName = "StatusDto", MatchFieldName = "id", @@ -376,6 +382,47 @@ public static class CodeBuilder MatchFieldName = "averageRuntime", OverrideType = "int?", }, + new() + { + MatchClassName = "ParentCompanyDto", + MatchFieldName = "id", + OverrideType = "long?", + }, + new() + { + MatchClassName = "CompanyRelationShipDto", + MatchFieldName = "id", + OverrideType = "long?", + }, + new() + { + MatchClassName = "StudioBaseRecordDto", + MatchFieldName = "parentStudio", + OverrideType = "int?", + }, + new() + { + MatchClassName = "StudioBaseRecordDto", + MatchFieldName = "parentStudio", + OverrideType = "int?", + }, + new() + { + MatchClassName = "TranslationExtendedDto", + MatchFieldName = "alias", + OverrideFieldName = "aliases", + OverridePropertyName = "Aliases", + OverridePropertyAttributes = new List + { + "[JsonProperty(\"aliases\")]", + }, + }, + new() + { + MatchClassName = "SeriesExtendedRecordDto", + MatchFieldName = "translations", + OverrideType = "TranslationExtendedDto", + }, }; private static readonly Dictionary> ExtraProperties = new() @@ -390,7 +437,7 @@ public static class CodeBuilder PropertyType = "object", PropertyAttributes = new List { - "[JsonIgnore]", + "[JsonProperty(\"status\")]", }, }, } @@ -508,6 +555,16 @@ public static class CodeBuilder { "MovieExtendedRecordDto", new List { + new() + { + FieldName = "translations", + PropertyName = "Translations", + PropertyType = "TranslationExtendedDto", + PropertyAttributes = new List + { + "[JsonProperty(\"translations\")]", + }, + }, new() { FieldName = "runtime", @@ -518,6 +575,7 @@ public static class CodeBuilder "[JsonProperty(\"runtime\")]", }, }, + new() { FieldName = "lastUpdated", @@ -557,10 +615,10 @@ public static class CodeBuilder { FieldName = "translations", PropertyName = "Translations", - PropertyType = "object", + PropertyType = "TranslationExtendedDto", PropertyAttributes = new List { - "[JsonIgnore]", + "[JsonProperty(\"translations\")]", }, }, } @@ -670,6 +728,91 @@ public static class CodeBuilder }, } }, + { + "AwardBaseRecordDto", new List + { + new() + { + FieldName = "year", + PropertyName = "Year", + PropertyType = "string", + PropertyAttributes = new List + { + "[JsonProperty(\"year\")]", + }, + }, + new() + { + FieldName = "category", + PropertyName = "Category", + PropertyType = "string", + PropertyAttributes = new List + { + "[JsonProperty(\"category\")]", + }, + }, + new() + { + FieldName = "isWinner", + PropertyName = "IsWinner", + PropertyType = "bool", + PropertyAttributes = new List + { + "[JsonProperty(\"isWinner\")]", + }, + }, + new() + { + FieldName = "details", + PropertyName = "Details", + PropertyType = "object", + PropertyAttributes = new List + { + "[JsonProperty(\"details\")]", + }, + }, + new() + { + FieldName = "series", + PropertyName = "Series", + PropertyType = "object", + PropertyAttributes = new List + { + "[JsonProperty(\"series\")]", + }, + }, + new() + { + FieldName = "movie", + PropertyName = "Movie", + PropertyType = "object", + PropertyAttributes = new List + { + "[JsonProperty(\"movie\")]", + }, + }, + new() + { + FieldName = "episode", + PropertyName = "Episode", + PropertyType = "object", + PropertyAttributes = new List + { + "[JsonProperty(\"episode\")]", + }, + }, + new() + { + FieldName = "character", + PropertyName = "Character", + PropertyType = "object", + PropertyAttributes = new List + { + "[JsonProperty(\"character\")]", + }, + }, + } + }, }; private static readonly Dictionary MethodReturnTypeOverrides = new() diff --git a/test/GenerateDto/GenerateDto.csproj b/test/GenerateDto/GenerateDto.csproj index af4574d..b172b51 100644 --- a/test/GenerateDto/GenerateDto.csproj +++ b/test/GenerateDto/GenerateDto.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/test/ManualTests/Program.cs b/test/ManualTests/Program.cs index 8189a6f..66a7363 100644 --- a/test/ManualTests/Program.cs +++ b/test/ManualTests/Program.cs @@ -14,84 +14,83 @@ private static async Task Main() var client = new TvDbClient(); var authData = JsonConvert.DeserializeObject(await File.ReadAllTextAsync("../../../auth.json")); await client.Login(authData!.ApiKey, authData.Pin); - + // Artwork Test("Artwork(62803637)", await client.Artwork(62803637)); Test("ArtworkExtended(62803637)", await client.ArtworkExtended(62803637)); - + // Artwork Statuses Test("ArtworkStatuses", await client.ArtworkStatuses()); - + // Artwork Types Test("ArtworkTypes", await client.ArtworkTypes()); - + // Awards Test("Awards", await client.Awards()); Test("Award(1)", await client.Award(1)); Test("AwardExtended(1)", await client.AwardExtended(1)); - + // Award Categories Test("AwardCategory(1)", await client.AwardCategory(1)); Test("AwardCategoryExtended(1)", await client.AwardCategoryExtended(1)); - + // Characters Test("Character(67482807)", await client.Character(67482807)); - + // Companies Test("Companies", await client.Companies()); Test("CompanyTypes", await client.CompanyTypes()); Test("Company(1)", await client.Company(1)); - + // Content Ratings Test("ContentRatings()", await client.ContentRatings()); - + // Countries Test("Countries()", await client.Countries()); - + // Entity Types Test("EntityTypes()", await client.EntityTypes()); - + // Episodes Test("Episode(7676782)", await client.Episode(7676782)); Test("EpisodeExtended(7676782)", await client.EpisodeExtended(7676782)); Test("EpisodeTranslation(7676782, 'deu')", await client.EpisodeTranslation(7676782, "deu")); - + // Genders Test("Genders()", await client.Genders()); - + // Genres Test("Genres()", await client.Genres()); Test("Genre(31)", await client.Genre(31)); - + // InspirationTypes Test("InspirationTypes()", await client.InspirationTypes()); - + // Languages Test("Languages()", await client.Languages()); - + // Lists Test("Lists()", await client.Lists()); Test("Lists(6007)", await client.List(6007)); Test("ListExtended(6007)", await client.ListExtended(6007)); Test("ListTranslation(6007, 'eng')", await client.ListTranslation(6007, "eng")); - + // Movies Test("Movies()", await client.Movies()); Test("Movie(165)", await client.Movie(503)); - Test("MovieExtended(165)", await client.MovieExtended(165)); + Test("MovieExtended(165)", await client.MovieExtended(165, new MovieExtendedOptionalParams { Meta = "translations" })); Test("MovieTranslation(165, 'eng')", await client.MovieTranslation(165, "eng")); // Movie Statuses Test("MovieStatuses()", await client.MovieStatuses()); - // People Test("People(310602)", await client.People(310602)); - Test("PeopleExtended(310602)", await client.PeopleExtended(310602)); + Test("PeopleExtended(310602)", await client.PeopleExtended(310602, new PeopleExtendedOptionalParams { Meta = "translations" })); // Test("PeopleTranslation(310602, 'eng')", await client.PeopleTranslation(310602, "eng")); // Search - Test("Search(Query = stargate)", await client.Search(new SearchOptionalParams { Query = "stargate"})); + Test("Search(Query = stargate)", await client.Search(new SearchOptionalParams { Query = "stargate" })); // Seasons Test("Seasons()", await client.Seasons()); @@ -102,8 +101,8 @@ private static async Task Main() // Series Test("AllSeries()", await client.AllSeries()); - Test("Series(379858)", await client.Series(379858)); - Test("SeriesExtended(379858)", await client.SeriesExtended(379858)); + Test("Series(379858)", await client.Series(379858)); + Test("SeriesExtended(379858)", await client.SeriesExtended(379858, new SeriesExtendedOptionalParams { Meta = "translations" })); Test("SeriesEpisodes(379858, 'official')", await client.SeriesEpisodes(379858, "official")); Test("SeriesSeasonEpisodesTranslated(379858, 'official', 'eng')", await client.SeriesSeasonEpisodesTranslated(379858, "official", "eng")); Test("SeriesTranslation(379858, 'eng')", await client.SeriesTranslation(379858, "eng"));