diff --git a/CHANGELOG.md b/CHANGELOG.md index c7e1bdb..43055c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,15 @@ - Reduced Newtonsoft.Json dependency while maintaining backward compatibility for non-migrated functionality - Added comprehensive STJ migration testing and validation infrastructure - Added/updated unit and integration test coverage for all migrated modules including Client, User, Organization, Stack, ContentType, Assets, Environment, Global Field, Entry, Entry Variant, and Variant Group - - **Note**: This is a beta release and APIs/modules may continue evolving during migration stabilization + - Migrated Locale and Bulk Operations modules to System.Text.Json + - Re-enabled `Stack.Locale()` and `Stack.BulkOperation()` methods + - Migrated all Bulk Operation services (Publish, Unpublish, Delete, AddItems, UpdateItems, ReleaseItems, WorkflowUpdate) to STJ + - Migrated `LocaleModel` and `BulkOperationModels` to use `System.Text.Json` attributes + - Added/updated unit and integration test coverage for Locale and Bulk Operations + - Upgraded target framework to .NET 10 and removed all build warnings + - **Note**: + - This is a beta release and APIs/modules may continue evolving during migration stabilization + - Release and Workflow setup within Bulk Operations module are currently commented out and will be uncommented once the Release and Workflow modules are migrated to System.Text.Json ## [v0.10.0](https://github.com/contentstack/contentstack-management-dotnet/tree/v0.9.0) - Feat diff --git a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj index 2ae7e80..ad6ede9 100644 --- a/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj +++ b/Contentstack.Management.Core.Tests/Contentstack.Management.Core.Tests.csproj @@ -24,7 +24,6 @@ - @@ -54,10 +53,11 @@ + + - diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs index fb64b28..f9cf4b1 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack001_LoginTest.cs @@ -1514,7 +1514,7 @@ public void Test088_Should_Handle_TOTP_Token_Format_Variations_Sync() { client.Login(credentials, token); } - catch (ArgumentException ex) when (token.Length != 6 || token.Any(c => !char.IsDigit(c))) + catch (ArgumentException) when (token.Length != 6 || token.Any(c => !char.IsDigit(c))) { AssertLogger.IsTrue(true, $"ArgumentException for invalid token format: '{token}'"); } diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs index b4eb6cf..a9d5a4a 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack003_StackTest.cs @@ -983,7 +983,7 @@ public void Test055_Should_Fail_UpdateUserRole_Empty_List_API() { AssertStackValidationError(ex, "Stack_UpdateUserRole_Empty"); } - catch (ArgumentException ex) + catch (ArgumentException) { AssertLogger.IsTrue(true, "SDK or API rejected empty list", "Stack_UpdateUserRole_Empty_Argument"); } diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs index 4a0487b..84f61d4 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack013_AssetTest.cs @@ -476,7 +476,7 @@ public async Task Test006_Should_Fetch_Asset() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -511,7 +511,7 @@ public async Task Test007_Should_Fetch_Asset_Async() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -546,7 +546,7 @@ public async Task Test008_Should_Update_Asset() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -584,7 +584,7 @@ public async Task Test009_Should_Update_Asset_Async() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -680,7 +680,7 @@ public async Task Test012_Should_Delete_Asset() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -791,7 +791,7 @@ public async Task Test015_Should_Create_Subfolder() { if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -826,7 +826,7 @@ public async Task Test016_Should_Fetch_Folder() { if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -861,7 +861,7 @@ public async Task Test017_Should_Fetch_Folder_Async() { if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -896,7 +896,7 @@ public async Task Test018_Should_Update_Folder() { if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -932,7 +932,7 @@ public async Task Test019_Should_Update_Folder_Async() // First create a folder if we don't have one if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -968,7 +968,7 @@ public async Task Test022_Should_Delete_Folder() // First create a folder if we don't have one if (string.IsNullOrEmpty(_testFolderUid)) { - Test014_Should_Create_Folder(); + await Test014_Should_Create_Folder(); } if (!string.IsNullOrEmpty(_testFolderUid)) @@ -1236,7 +1236,7 @@ public async Task Test031_Should_Fetch_Asset_With_Locale_Parameter() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -1273,7 +1273,7 @@ public async Task Test032_Should_Fetch_Asset_Async_With_Locale_Parameter() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (!string.IsNullOrEmpty(_testAssetUid)) @@ -1343,7 +1343,7 @@ public async Task Test034_Should_Handle_Fetch_With_Invalid_Locale_Parameter() { if (string.IsNullOrEmpty(_testAssetUid)) { - Test005_Should_Create_Asset_Async(); + await Test005_Should_Create_Asset_Async(); } if (string.IsNullOrEmpty(_testAssetUid)) diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack014_EntryTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack014_EntryTest.cs index b156559..d77c221 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack014_EntryTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack014_EntryTest.cs @@ -924,7 +924,7 @@ public async Task Test021_Should_Fail_With_Invalid_Entry_UID_Formats() { Console.WriteLine($"✅ SDK validation caught malformed UID: {ex.Message}"); } - catch (System.Text.Json.JsonException ex) + catch (System.Text.Json.JsonException) { // API returned HTML error page instead of JSON for path traversal/malicious UIDs Console.WriteLine($"✅ API blocked malicious entry UID with HTML response: {invalidUID}"); @@ -1118,7 +1118,7 @@ public async Task Test026_Should_Handle_Invalid_Content_Type_UIDs() { Console.WriteLine($"✅ SDK caught invalid content type: {ex.Message}"); } - catch (System.Text.Json.JsonException ex) + catch (System.Text.Json.JsonException) { // API returned HTML error page instead of JSON for special characters/malicious content types Console.WriteLine($"✅ API blocked malicious content type UID with HTML response: {invalidContentType}"); @@ -2298,7 +2298,7 @@ public async Task Test049_Should_Block_Entry_Access_With_Malformed_Tokens() { Console.WriteLine($"✅ SDK caught malformed token: {ex.Message}"); } - catch (System.Text.Json.JsonException ex) + catch (System.Text.Json.JsonException) { // API returned HTML error page instead of JSON for malformed tokens Console.WriteLine($"✅ API blocked malformed token with HTML response: {malformedToken.Substring(0, Math.Min(20, malformedToken.Length))}..."); diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs index 0f43eb1..da6030b 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack015_BulkOperationTest.cs @@ -5,7 +5,6 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; -using System.Threading.Tasks; using Contentstack.Management.Core.Exceptions; using Contentstack.Management.Core.Models; using Contentstack.Management.Core.Tests.Helpers; @@ -13,8 +12,9 @@ using Contentstack.Management.Core.Tests.Model; using Contentstack.Management.Core.Abstractions; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Tests.IntegrationTest { @@ -29,10 +29,13 @@ public class Contentstack015_BulkOperationTest private Stack _stack; private string _contentTypeUid = "bulk_test_content_type"; private string _testEnvironmentUid = "bulk_test_environment"; +#pragma warning disable CS0414 private string _testReleaseUid = "bulk_test_release"; +#pragma warning restore CS0414 private List _createdEntries = new List(); // Workflow and publishing rule for bulk tests (static so one create/delete across all test instances) +#pragma warning disable CS0649 private static string _bulkTestWorkflowUid; private static string _bulkTestWorkflowStageUid; // Stage 2 (Complete) – used by publish rule and backward compat private static string _bulkTestWorkflowStage1Uid; // Stage 1 (Review) @@ -40,6 +43,7 @@ public class Contentstack015_BulkOperationTest private static string _bulkTestPublishRuleUid; private static string _bulkTestEnvironmentUid; // Environment used for workflow/publish rule (ensured in ClassInitialize or Test000b/000c) private static string _bulkTestWorkflowSetupError; // Reason workflow setup failed (so workflow_tests can show it) +#pragma warning restore CS0649 /// /// Fails the test with a clear message from ContentstackErrorException or generic exception. @@ -190,15 +194,16 @@ private static Stack GetStack() public static void ClassInitialize(TestContext context) { _client = Contentstack.CreateAuthenticatedClient(); - try - { - Stack stack = GetStack(); - EnsureBulkTestWorkflowAndPublishingRuleAsync(stack).GetAwaiter().GetResult(); - } - catch (Exception) - { - // Workflow/publish rule setup failed (e.g. auth, plan limits); tests can still run without them - } + // Stack.Workflow() not yet migrated — commented out + //try + //{ + // Stack stack = GetStack(); + // EnsureBulkTestWorkflowAndPublishingRuleAsync(stack).GetAwaiter().GetResult(); + //} + //catch (Exception) + //{ + // // Workflow/publish rule setup failed (e.g. auth, plan limits); tests can still run without them + //} } [ClassCleanup] @@ -226,231 +231,231 @@ public async Task Initialize() Console.WriteLine($"[Initialize] CreateTestEnvironment skipped: HTTP {(int)ex.StatusCode} ({ex.StatusCode}). ErrorCode: {ex.ErrorCode}. Message: {ex.ErrorMessage ?? ex.Message}"); } - try - { - await CreateTestRelease(); - } - catch (ContentstackErrorException ex) - { - // Release may already exist on this stack; no action needed - Console.WriteLine($"[Initialize] CreateTestRelease skipped: HTTP {(int)ex.StatusCode} ({ex.StatusCode}). ErrorCode: {ex.ErrorCode}. Message: {ex.ErrorMessage ?? ex.Message}"); - } - - // Ensure workflow (and bulk env) is initialized when running on a new stack - if (string.IsNullOrEmpty(_bulkTestWorkflowUid)) - { - try - { - EnsureBulkTestWorkflowAndPublishingRuleAsync(_stack).GetAwaiter().GetResult(); - } - catch (Exception ex) - { - // Workflow setup failed (e.g. auth, plan limits); record the reason so workflow-based tests can surface it - _bulkTestWorkflowSetupError = ex is ContentstackErrorException cex - ? $"HTTP {(int)cex.StatusCode} ({cex.StatusCode}). ErrorCode: {cex.ErrorCode}. Message: {cex.ErrorMessage ?? cex.Message}" - : ex.Message; - Console.WriteLine($"[Initialize] Workflow setup failed: {_bulkTestWorkflowSetupError}"); - } - } - } - - [TestMethod] - [DoNotParallelize] - public void Test000a_Should_Create_Workflow_With_Two_Stages() - { - TestOutputLogger.LogContext("TestScenario", "CreateWorkflowWithTwoStages"); - try - { - const string workflowName = "workflow_test"; - - // Check if a workflow with the same name already exists (e.g. from a previous test run) - try - { - ContentstackResponse listResponse = _stack.Workflow().FindAll(); - if (listResponse.IsSuccessStatusCode) - { - var listJson = listResponse.OpenJObjectResponse(); - var existing = (listJson["workflows"] as JArray) ?? (listJson["workflow"] as JArray); - if (existing != null) - { - foreach (var wf in existing) - { - if (wf["name"]?.ToString() == workflowName && wf["uid"] != null) - { - _bulkTestWorkflowUid = wf["uid"].ToString(); - var existingStages = wf["workflow_stages"] as JArray; - if (existingStages != null && existingStages.Count >= 2) - { - _bulkTestWorkflowStage1Uid = existingStages[0]["uid"]?.ToString(); - _bulkTestWorkflowStage2Uid = existingStages[1]["uid"]?.ToString(); - _bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; - AssertLogger.IsNotNull(_bulkTestWorkflowStage1Uid, "Stage1Uid"); - AssertLogger.IsNotNull(_bulkTestWorkflowStage2Uid, "Stage2Uid"); - return; // Already exists with stages – nothing more to do - } - } - } - } - } - } - catch { /* If listing fails, proceed to create */ } - - var sysAcl = new Dictionary - { - ["roles"] = new Dictionary { ["uids"] = new List() }, - ["users"] = new Dictionary { ["uids"] = new List { "$all" } }, - ["others"] = new Dictionary() - }; - - var workflowModel = new WorkflowModel - { - Name = workflowName, - Enabled = true, - Branches = new List { "main" }, - ContentTypes = new List { "$all" }, - AdminUsers = new Dictionary { ["users"] = new List() }, - WorkflowStages = new List - { - new WorkflowStage - { - Name = "New stage 1", - Color = "#fe5cfb", - SystemACL = sysAcl, - NextAvailableStages = new List { "$all" }, - AllStages = true, - AllUsers = true, - SpecificStages = false, - SpecificUsers = false, - EntryLock = "$none" - }, - new WorkflowStage - { - Name = "New stage 2", - Color = "#3688bf", - SystemACL = new Dictionary - { - ["roles"] = new Dictionary { ["uids"] = new List() }, - ["users"] = new Dictionary { ["uids"] = new List { "$all" } }, - ["others"] = new Dictionary() - }, - NextAvailableStages = new List { "$all" }, - AllStages = true, - AllUsers = true, - SpecificStages = false, - SpecificUsers = false, - EntryLock = "$none" - } - } - }; - - // Print what we are sending so failures show the exact request JSON - string sentJson = JsonConvert.SerializeObject(new { workflow = workflowModel }, Formatting.Indented); - - ContentstackResponse response = _stack.Workflow().Create(workflowModel); - string responseBody = null; - try { responseBody = response.OpenResponse(); } catch { } - - AssertLogger.IsNotNull(response, "workflowCreateResponse"); - AssertLogger.IsTrue(response.IsSuccessStatusCode, - $"Workflow create failed: HTTP {(int)response.StatusCode}.\n--- REQUEST BODY ---\n{sentJson}\n--- RESPONSE BODY ---\n{responseBody}", "workflowCreateSuccess"); - - var responseJson = JObject.Parse(responseBody ?? "{}"); - var workflowObj = responseJson["workflow"]; - AssertLogger.IsNotNull(workflowObj, "workflowObj"); - AssertLogger.IsFalse(string.IsNullOrEmpty(workflowObj["uid"]?.ToString()), "Workflow UID is empty.", "workflowUid"); - - _bulkTestWorkflowUid = workflowObj["uid"].ToString(); - TestOutputLogger.LogContext("WorkflowUid", _bulkTestWorkflowUid); - var stages = workflowObj["workflow_stages"] as JArray; - AssertLogger.IsNotNull(stages, "workflow_stages"); - AssertLogger.IsTrue(stages.Count >= 2, $"Expected at least 2 stages, got {stages.Count}.", "stagesCount"); - _bulkTestWorkflowStage1Uid = stages[0]["uid"].ToString(); // New stage 1 - _bulkTestWorkflowStage2Uid = stages[1]["uid"].ToString(); // New stage 2 - _bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; - } - catch (Exception ex) - { - FailWithError("Create workflow with two stages", ex); - } + // Stack.Release() not yet migrated — commented out + //try + //{ + // await CreateTestRelease(); + //} + //catch (ContentstackErrorException ex) + //{ + // Console.WriteLine($"[Initialize] CreateTestRelease skipped: HTTP {(int)ex.StatusCode} ({ex.StatusCode}). ErrorCode: {ex.ErrorCode}. Message: {ex.ErrorMessage ?? ex.Message}"); + //} + + // Stack.Workflow() not yet migrated — commented out + //if (string.IsNullOrEmpty(_bulkTestWorkflowUid)) + //{ + // try + // { + // EnsureBulkTestWorkflowAndPublishingRuleAsync(_stack).GetAwaiter().GetResult(); + // } + // catch (Exception ex) + // { + // _bulkTestWorkflowSetupError = ex is ContentstackErrorException cex + // ? $"HTTP {(int)cex.StatusCode} ({cex.StatusCode}). ErrorCode: {cex.ErrorCode}. Message: {cex.ErrorMessage ?? cex.Message}" + // : ex.Message; + // Console.WriteLine($"[Initialize] Workflow setup failed: {_bulkTestWorkflowSetupError}"); + // } + //} } - [TestMethod] - [DoNotParallelize] - public void Test000b_Should_Create_Publishing_Rule_For_Workflow_Stage2() - { - TestOutputLogger.LogContext("TestScenario", "CreatePublishingRuleForWorkflowStage2"); - try - { - AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestWorkflowUid), "Workflow UID not set. Run Test000a first.", "WorkflowUid"); - AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestWorkflowStage2Uid), "Workflow Stage 2 UID not set. Run Test000a first.", "WorkflowStage2Uid"); - - if (string.IsNullOrEmpty(_bulkTestEnvironmentUid)) - EnsureBulkTestEnvironment(_stack); - AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestEnvironmentUid), "No environment. Run Test000c or ensure ClassInitialize ran (ensure environment failed).", "EnvironmentUid"); - TestOutputLogger.LogContext("WorkflowUid", _bulkTestWorkflowUid ?? ""); - TestOutputLogger.LogContext("EnvironmentUid", _bulkTestEnvironmentUid ?? ""); - - // Find existing publish rule for this workflow + stage + environment (e.g. from a previous run) - try - { - ContentstackResponse listResponse = _stack.Workflow().PublishRule().FindAll(); - if (listResponse.IsSuccessStatusCode) - { - var listJson = listResponse.OpenJObjectResponse(); - var rules = (listJson["publishing_rules"] as JArray) ?? (listJson["publishing_rule"] as JArray); - if (rules != null) - { - foreach (var rule in rules) - { - if (rule["workflow"]?.ToString() == _bulkTestWorkflowUid - && rule["workflow_stage"]?.ToString() == _bulkTestWorkflowStage2Uid - && rule["environment"]?.ToString() == _bulkTestEnvironmentUid - && rule["uid"] != null) - { - _bulkTestPublishRuleUid = rule["uid"].ToString(); - return; // Already exists - } - } - } - } - } - catch { /* If listing fails, proceed to create */ } - - var publishRuleModel = new PublishRuleModel - { - WorkflowUid = _bulkTestWorkflowUid, - WorkflowStageUid = _bulkTestWorkflowStage2Uid, - Environment = _bulkTestEnvironmentUid, - Branches = new List { "main" }, - ContentTypes = new List { "$all" }, - Locales = new List { "en-us" }, - Actions = new List(), - Approvers = new Approvals { Users = new List(), Roles = new List() }, - DisableApproval = false - }; - - string sentJson = JsonConvert.SerializeObject(new { publishing_rule = publishRuleModel }, Formatting.Indented); - - ContentstackResponse response = _stack.Workflow().PublishRule().Create(publishRuleModel); - string responseBody = null; - try { responseBody = response.OpenResponse(); } catch { } - - AssertLogger.IsNotNull(response, "publishRuleResponse"); - AssertLogger.IsTrue(response.IsSuccessStatusCode, - $"Publish rule create failed: HTTP {(int)response.StatusCode}.\n--- REQUEST BODY ---\n{sentJson}\n--- RESPONSE BODY ---\n{responseBody}", "publishRuleCreateSuccess"); - - var responseJson = JObject.Parse(responseBody ?? "{}"); - var ruleObj = responseJson["publishing_rule"]; - AssertLogger.IsNotNull(ruleObj, "publishing_rule"); - AssertLogger.IsFalse(string.IsNullOrEmpty(ruleObj["uid"]?.ToString()), "Publishing rule UID is empty.", "publishRuleUid"); - - _bulkTestPublishRuleUid = ruleObj["uid"].ToString(); - } - catch (Exception ex) - { - FailWithError("Create publishing rule for workflow stage 2", ex); - } - } + // Stack.Workflow() not yet migrated — Test000a commented out + //[TestMethod] + //[DoNotParallelize] + //public void Test000a_Should_Create_Workflow_With_Two_Stages() + //{ + // TestOutputLogger.LogContext("TestScenario", "CreateWorkflowWithTwoStages"); + // try + // { + // const string workflowName = "workflow_test"; + + //// Check if a workflow with the same name already exists (e.g. from a previous test run) + //try + //{ + //ContentstackResponse listResponse = _stack.Workflow().FindAll(); + //if (listResponse.IsSuccessStatusCode) + //{ + //var listJson = listResponse.OpenJsonObjectResponse(); + //var existing = (listJson["workflows"]?.AsArray()) ?? (listJson["workflow"]?.AsArray()); + //if (existing != null) + //{ + //foreach (var wf in existing) + //{ + //if (wf["name"]?.ToString() == workflowName && wf["uid"] != null) + //{ + //_bulkTestWorkflowUid = wf["uid"].ToString(); + //var existingStages = wf["workflow_stages"]?.AsArray(); + //if (existingStages != null && existingStages.Count >= 2) + //{ + //_bulkTestWorkflowStage1Uid = existingStages[0]["uid"]?.ToString(); + //_bulkTestWorkflowStage2Uid = existingStages[1]["uid"]?.ToString(); + //_bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; + //AssertLogger.IsNotNull(_bulkTestWorkflowStage1Uid, "Stage1Uid"); + //AssertLogger.IsNotNull(_bulkTestWorkflowStage2Uid, "Stage2Uid"); + //return; // Already exists with stages – nothing more to do + //} + //} + //} + //} + //} + //} + //catch { /* If listing fails, proceed to create */ } + // + //var sysAcl = new Dictionary + //{ + //["roles"] = new Dictionary { ["uids"] = new List() }, + //["users"] = new Dictionary { ["uids"] = new List { "$all" } }, + //["others"] = new Dictionary() + //}; + // + //var workflowModel = new WorkflowModel + //{ + //Name = workflowName, + //Enabled = true, + //Branches = new List { "main" }, + //ContentTypes = new List { "$all" }, + //AdminUsers = new Dictionary { ["users"] = new List() }, + //WorkflowStages = new List + //{ + //new WorkflowStage + //{ + //Name = "New stage 1", + //Color = "#fe5cfb", + //SystemACL = sysAcl, + //NextAvailableStages = new List { "$all" }, + //AllStages = true, + //AllUsers = true, + //SpecificStages = false, + //SpecificUsers = false, + //EntryLock = "$none" + //}, + //new WorkflowStage + //{ + //Name = "New stage 2", + //Color = "#3688bf", + //SystemACL = new Dictionary + //{ + //["roles"] = new Dictionary { ["uids"] = new List() }, + //["users"] = new Dictionary { ["uids"] = new List { "$all" } }, + //["others"] = new Dictionary() + //}, + //NextAvailableStages = new List { "$all" }, + //AllStages = true, + //AllUsers = true, + //SpecificStages = false, + //SpecificUsers = false, + //EntryLock = "$none" + //} + //} + //}; + // + //// Print what we are sending so failures show the exact request JSON + //string sentJson = JsonSerializer.Serialize(new { workflow = workflowModel }); + // + //ContentstackResponse response = _stack.Workflow().Create(workflowModel); + //string responseBody = null; + //try { responseBody = response.OpenResponse(); } catch { } + // + //AssertLogger.IsNotNull(response, "workflowCreateResponse"); + //AssertLogger.IsTrue(response.IsSuccessStatusCode, + //$"Workflow create failed: HTTP {(int)response.StatusCode}.\n--- REQUEST BODY ---\n{sentJson}\n--- RESPONSE BODY ---\n{responseBody}", "workflowCreateSuccess"); + // + //var responseJson = JsonNode.Parse(responseBody ?? "{}")!.AsObject(); + //var workflowObj = responseJson["workflow"]; + //AssertLogger.IsNotNull(workflowObj, "workflowObj"); + //AssertLogger.IsFalse(string.IsNullOrEmpty(workflowObj["uid"]?.ToString()), "Workflow UID is empty.", "workflowUid"); + // + //_bulkTestWorkflowUid = workflowObj["uid"].ToString(); + //TestOutputLogger.LogContext("WorkflowUid", _bulkTestWorkflowUid); + //var stages = workflowObj["workflow_stages"]?.AsArray(); + //AssertLogger.IsNotNull(stages, "workflow_stages"); + //AssertLogger.IsTrue(stages.Count >= 2, $"Expected at least 2 stages, got {stages.Count}.", "stagesCount"); + //_bulkTestWorkflowStage1Uid = stages[0]["uid"].ToString(); // New stage 1 + //_bulkTestWorkflowStage2Uid = stages[1]["uid"].ToString(); // New stage 2 + //_bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; + //} + //catch (Exception ex) + //{ + //FailWithError("Create workflow with two stages", ex); + //} + //} + // + //[TestMethod] + //[DoNotParallelize] + //public void Test000b_Should_Create_Publishing_Rule_For_Workflow_Stage2() + //{ + //TestOutputLogger.LogContext("TestScenario", "CreatePublishingRuleForWorkflowStage2"); + //try + //{ + //AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestWorkflowUid), "Workflow UID not set. Run Test000a first.", "WorkflowUid"); + //AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestWorkflowStage2Uid), "Workflow Stage 2 UID not set. Run Test000a first.", "WorkflowStage2Uid"); + // + //if (string.IsNullOrEmpty(_bulkTestEnvironmentUid)) + //EnsureBulkTestEnvironment(_stack); + //AssertLogger.IsFalse(string.IsNullOrEmpty(_bulkTestEnvironmentUid), "No environment. Run Test000c or ensure ClassInitialize ran (ensure environment failed).", "EnvironmentUid"); + //TestOutputLogger.LogContext("WorkflowUid", _bulkTestWorkflowUid ?? ""); + //TestOutputLogger.LogContext("EnvironmentUid", _bulkTestEnvironmentUid ?? ""); + // + //// Find existing publish rule for this workflow + stage + environment (e.g. from a previous run) + //try + //{ + //ContentstackResponse listResponse = _stack.Workflow().PublishRule().FindAll(); + //if (listResponse.IsSuccessStatusCode) + //{ + //var listJson = listResponse.OpenJsonObjectResponse(); + //var rules = (listJson["publishing_rules"]?.AsArray()) ?? (listJson["publishing_rule"]?.AsArray()); + //if (rules != null) + //{ + //foreach (var rule in rules) + //{ + //if (rule["workflow"]?.ToString() == _bulkTestWorkflowUid + //&& rule["workflow_stage"]?.ToString() == _bulkTestWorkflowStage2Uid + //&& rule["environment"]?.ToString() == _bulkTestEnvironmentUid + //&& rule["uid"] != null) + //{ + //_bulkTestPublishRuleUid = rule["uid"].ToString(); + //return; // Already exists + //} + //} + //} + //} + //} + //catch { /* If listing fails, proceed to create */ } + // + //var publishRuleModel = new PublishRuleModel + //{ + //WorkflowUid = _bulkTestWorkflowUid, + //WorkflowStageUid = _bulkTestWorkflowStage2Uid, + //Environment = _bulkTestEnvironmentUid, + //Branches = new List { "main" }, + //ContentTypes = new List { "$all" }, + //Locales = new List { "en-us" }, + //Actions = new List(), + //Approvers = new Approvals { Users = new List(), Roles = new List() }, + //DisableApproval = false + //}; + // + //string sentJson = JsonSerializer.Serialize(new { publishing_rule = publishRuleModel }); + // + //ContentstackResponse response = _stack.Workflow().PublishRule().Create(publishRuleModel); + //string responseBody = null; + //try { responseBody = response.OpenResponse(); } catch { } + // + //AssertLogger.IsNotNull(response, "publishRuleResponse"); + //AssertLogger.IsTrue(response.IsSuccessStatusCode, + //$"Publish rule create failed: HTTP {(int)response.StatusCode}.\n--- REQUEST BODY ---\n{sentJson}\n--- RESPONSE BODY ---\n{responseBody}", "publishRuleCreateSuccess"); + // + //var responseJson = JsonNode.Parse(responseBody ?? "{}")!.AsObject(); + //var ruleObj = responseJson["publishing_rule"]; + //AssertLogger.IsNotNull(ruleObj, "publishing_rule"); + //AssertLogger.IsFalse(string.IsNullOrEmpty(ruleObj["uid"]?.ToString()), "Publishing rule UID is empty.", "publishRuleUid"); + // + //_bulkTestPublishRuleUid = ruleObj["uid"].ToString(); + //} + //catch (Exception ex) + //{ + //FailWithError("Create publishing rule for workflow stage 2", ex); + //} + //} [TestMethod] @@ -484,7 +489,7 @@ public async Task Test001_Should_Create_Content_Type_With_Title_Field() // Create the content type ContentstackResponse response = _stack.ContentType().Create(contentModelling); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(response, "createContentTypeResponse"); AssertLogger.IsTrue(response.IsSuccessStatusCode, "contentTypeCreateSuccess"); @@ -544,7 +549,7 @@ public async Task Test002_Should_Create_Five_Entries() { var entry = new SimpleEntry { Title = title }; ContentstackResponse response = _stack.ContentType(_contentTypeUid).Entry().Create(entry); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(response, "createEntryResponse"); AssertLogger.IsTrue(response.IsSuccessStatusCode, "entryCreateSuccess"); @@ -601,7 +606,7 @@ public async Task Test003_Should_Perform_Bulk_Publish_Operation() // Perform bulk publish; skipWorkflowStage=true bypasses publish rules enforced by workflow stages ContentstackResponse response = _stack.BulkOperation().Publish(publishDetails, skipWorkflowStage: true, approvals: true); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(response, "bulkPublishResponse"); AssertLogger.IsTrue(response.IsSuccessStatusCode, "bulkPublishSuccess"); @@ -648,7 +653,7 @@ public async Task Test004_Should_Perform_Bulk_Unpublish_Operation() // Perform bulk unpublish; skipWorkflowStage=true bypasses publish rules enforced by workflow stages ContentstackResponse response = _stack.BulkOperation().Unpublish(unpublishDetails, skipWorkflowStage: true, approvals: true); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(response, "bulkUnpublishResponse"); AssertLogger.IsTrue(response.IsSuccessStatusCode, "bulkUnpublishSuccess"); @@ -700,7 +705,7 @@ public async Task Test003a_Should_Perform_Bulk_Publish_With_SkipWorkflowStage_An AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Bulk publish failed with status {(int)response.StatusCode} ({response.StatusCode}).", "bulkPublishSuccess"); AssertLogger.AreEqual(HttpStatusCode.OK, response.StatusCode, $"Expected 200 OK, got {(int)response.StatusCode}.", "statusCode"); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(responseJson, "responseJson"); } catch (Exception ex) @@ -708,7 +713,7 @@ public async Task Test003a_Should_Perform_Bulk_Publish_With_SkipWorkflowStage_An if (ex is ContentstackErrorException cex) { string errorsJson = cex.Errors != null && cex.Errors.Count > 0 - ? JsonConvert.SerializeObject(cex.Errors, Formatting.Indented) + ? JsonSerializer.Serialize(cex.Errors) : "(none)"; string failMessage = string.Format( "Bulk publish with skipWorkflowStage and approvals failed. HTTP {0} ({1}). ErrorCode: {2}. Message: {3}. Errors: {4}", @@ -765,7 +770,7 @@ public async Task Test004a_Should_Perform_Bulk_UnPublish_With_SkipWorkflowStage_ AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Bulk publish failed with status {(int)response.StatusCode} ({response.StatusCode}).", "bulkUnpublishSuccess"); AssertLogger.AreEqual(HttpStatusCode.OK, response.StatusCode, $"Expected 200 OK, got {(int)response.StatusCode}.", "statusCode"); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(responseJson, "responseJson"); } catch (Exception ex) @@ -773,7 +778,7 @@ public async Task Test004a_Should_Perform_Bulk_UnPublish_With_SkipWorkflowStage_ if (ex is ContentstackErrorException cex) { string errorsJson = cex.Errors != null && cex.Errors.Count > 0 - ? JsonConvert.SerializeObject(cex.Errors, Formatting.Indented) + ? JsonSerializer.Serialize(cex.Errors) : "(none)"; string failMessage = string.Format( "Bulk unpublish with skipWorkflowStage and approvals failed. HTTP {0} ({1}). ErrorCode: {2}. Message: {3}. Errors: {4}", @@ -829,7 +834,7 @@ public async Task Test003b_Should_Perform_Bulk_Publish_With_ApiVersion_3_2_With_ AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Bulk publish with api_version 3.2 failed with status {(int)response.StatusCode} ({response.StatusCode}).", "bulkPublishSuccess"); AssertLogger.AreEqual(HttpStatusCode.OK, response.StatusCode, $"Expected 200 OK, got {(int)response.StatusCode}.", "statusCode"); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(responseJson, "responseJson"); } catch (Exception ex) @@ -873,7 +878,7 @@ public async Task Test004b_Should_Perform_Bulk_UnPublish_With_ApiVersion_3_2_Wit AssertLogger.IsTrue(response.IsSuccessStatusCode, $"Bulk unpublish with api_version 3.2 failed with status {(int)response.StatusCode} ({response.StatusCode}).", "bulkUnpublishSuccess"); AssertLogger.AreEqual(HttpStatusCode.OK, response.StatusCode, $"Expected 200 OK, got {(int)response.StatusCode}.", "statusCode"); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(responseJson, "responseJson"); } catch (Exception ex) @@ -881,134 +886,134 @@ public async Task Test004b_Should_Perform_Bulk_UnPublish_With_ApiVersion_3_2_Wit FailWithError("Bulk unpublish with api_version 3.2", ex); } } - - - [TestMethod] - [DoNotParallelize] - public async Task Test005_Should_Perform_Bulk_Release_Operations() - { - TestOutputLogger.LogContext("TestScenario", "BulkReleaseOperations"); - TestOutputLogger.LogContext("ContentType", _contentTypeUid); - try - { - // Fetch existing entries from the content type - List availableEntries = await FetchExistingEntries(); - AssertLogger.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation", "availableEntriesCount"); - - // Fetch an available release - string availableReleaseUid = await FetchAvailableRelease(); - AssertLogger.IsFalse(string.IsNullOrEmpty(availableReleaseUid), "No release available for bulk operations", "availableReleaseUid"); - if (!string.IsNullOrEmpty(availableReleaseUid)) - TestOutputLogger.LogContext("ReleaseUid", availableReleaseUid); - - // First, add items to the release - var addItemsData = new BulkAddItemsData - { - Items = availableEntries.Select(e => new BulkAddItem - { - Uid = e.Uid, - ContentType = _contentTypeUid - }).ToList() - }; - - // Now perform bulk release operations using AddItems in deployment mode (only 4 entries) - var releaseData = new BulkAddItemsData - { - Release = availableReleaseUid, - Action = "publish", - Locale = new List { "en-us" }, - Reference = false, - Items = availableEntries.Take(4).Select(e => new BulkAddItem - { - Uid = e.Uid, - ContentType = _contentTypeUid, - ContentTypeUid = _contentTypeUid, - Version = e.Version, - Locale = "en-us", - Title = e.Title - }).ToList() - }; - - // Perform bulk release using AddItems in deployment mode - ContentstackResponse releaseResponse = _stack.BulkOperation().AddItems(releaseData, "2.0"); - var releaseResponseJson = releaseResponse.OpenJObjectResponse(); - - AssertLogger.IsNotNull(releaseResponse, "releaseResponse"); - AssertLogger.IsTrue(releaseResponse.IsSuccessStatusCode, "releaseAddItemsSuccess"); - - // Check if job was created - AssertLogger.IsNotNull(releaseResponseJson["job_id"], "job_id"); - string jobId = releaseResponseJson["job_id"].ToString(); - - // Wait a bit and check job status - await Task.Delay(2000); - await CheckBulkJobStatus(jobId,"2.0"); - } - catch (Exception ex) - { - FailWithError("Bulk release operations", ex); - } - } - - [TestMethod] - [DoNotParallelize] - public async Task Test006_Should_Update_Items_In_Release() - { - TestOutputLogger.LogContext("TestScenario", "UpdateItemsInRelease"); - TestOutputLogger.LogContext("ContentType", _contentTypeUid); - try - { - // Fetch existing entries from the content type - List availableEntries = await FetchExistingEntries(); - AssertLogger.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation", "availableEntriesCount"); - - // Fetch an available release - string availableReleaseUid = await FetchAvailableRelease(); - AssertLogger.IsFalse(string.IsNullOrEmpty(availableReleaseUid), "No release available for bulk operations", "availableReleaseUid"); - if (!string.IsNullOrEmpty(availableReleaseUid)) - TestOutputLogger.LogContext("ReleaseUid", availableReleaseUid); - - // Alternative: Test bulk update items with version 2.0 for release items - var releaseData = new BulkAddItemsData - { - Release = availableReleaseUid, - Action = "publish", - Locale = new List { "en-us" }, - Reference = false, - Items = availableEntries.Skip(4).Take(1).Select(e => new BulkAddItem - { - Uid = e.Uid, - ContentType = _contentTypeUid, - ContentTypeUid = _contentTypeUid, - Version = e.Version, - Locale = "en-us", - Title = e.Title - }).ToList() - }; - - ContentstackResponse bulkUpdateResponse = _stack.BulkOperation().UpdateItems(releaseData, "2.0"); - var bulkUpdateResponseJson = bulkUpdateResponse.OpenJObjectResponse(); - - AssertLogger.IsNotNull(bulkUpdateResponse, "bulkUpdateResponse"); - AssertLogger.IsTrue(bulkUpdateResponse.IsSuccessStatusCode, "bulkUpdateSuccess"); - - if (bulkUpdateResponseJson["job_id"] != null) - { - string bulkJobId = bulkUpdateResponseJson["job_id"].ToString(); - - // Check job status - await Task.Delay(2000); - await CheckBulkJobStatus(bulkJobId, "2.0"); - } - } - catch (Exception ex) - { - FailWithError("Update items in release", ex); - } - } - - [TestMethod] - [DoNotParallelize] + // + // + //[TestMethod] + //[DoNotParallelize] + //public async Task Test005_Should_Perform_Bulk_Release_Operations() + //{ + //TestOutputLogger.LogContext("TestScenario", "BulkReleaseOperations"); + //TestOutputLogger.LogContext("ContentType", _contentTypeUid); + //try + //{ + //// Fetch existing entries from the content type + //List availableEntries = await FetchExistingEntries(); + //AssertLogger.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation", "availableEntriesCount"); + // + //// Fetch an available release + //string availableReleaseUid = await FetchAvailableRelease(); + //AssertLogger.IsFalse(string.IsNullOrEmpty(availableReleaseUid), "No release available for bulk operations", "availableReleaseUid"); + //if (!string.IsNullOrEmpty(availableReleaseUid)) + //TestOutputLogger.LogContext("ReleaseUid", availableReleaseUid); + // + //// First, add items to the release + //var addItemsData = new BulkAddItemsData + //{ + //Items = availableEntries.Select(e => new BulkAddItem + //{ + //Uid = e.Uid, + //ContentType = _contentTypeUid + //}).ToList() + //}; + // + //// Now perform bulk release operations using AddItems in deployment mode (only 4 entries) + //var releaseData = new BulkAddItemsData + //{ + //Release = availableReleaseUid, + //Action = "publish", + //Locale = new List { "en-us" }, + //Reference = false, + //Items = availableEntries.Take(4).Select(e => new BulkAddItem + //{ + //Uid = e.Uid, + //ContentType = _contentTypeUid, + //ContentTypeUid = _contentTypeUid, + //Version = e.Version, + //Locale = "en-us", + //Title = e.Title + //}).ToList() + //}; + // + //// Perform bulk release using AddItems in deployment mode + //ContentstackResponse releaseResponse = _stack.BulkOperation().AddItems(releaseData, "2.0"); + //var releaseResponseJson = releaseResponse.OpenJsonObjectResponse(); + // + //AssertLogger.IsNotNull(releaseResponse, "releaseResponse"); + //AssertLogger.IsTrue(releaseResponse.IsSuccessStatusCode, "releaseAddItemsSuccess"); + // + //// Check if job was created + //AssertLogger.IsNotNull(releaseResponseJson["job_id"], "job_id"); + //string jobId = releaseResponseJson["job_id"].ToString(); + // + //// Wait a bit and check job status + //await Task.Delay(2000); + //await CheckBulkJobStatus(jobId,"2.0"); + //} + //catch (Exception ex) + //{ + //FailWithError("Bulk release operations", ex); + //} + //} + // + //[TestMethod] + //[DoNotParallelize] + //public async Task Test006_Should_Update_Items_In_Release() + //{ + //TestOutputLogger.LogContext("TestScenario", "UpdateItemsInRelease"); + //TestOutputLogger.LogContext("ContentType", _contentTypeUid); + //try + //{ + //// Fetch existing entries from the content type + //List availableEntries = await FetchExistingEntries(); + //AssertLogger.IsTrue(availableEntries.Count > 0, "No entries available for bulk operation", "availableEntriesCount"); + // + //// Fetch an available release + //string availableReleaseUid = await FetchAvailableRelease(); + //AssertLogger.IsFalse(string.IsNullOrEmpty(availableReleaseUid), "No release available for bulk operations", "availableReleaseUid"); + //if (!string.IsNullOrEmpty(availableReleaseUid)) + //TestOutputLogger.LogContext("ReleaseUid", availableReleaseUid); + // + //// Alternative: Test bulk update items with version 2.0 for release items + //var releaseData = new BulkAddItemsData + //{ + //Release = availableReleaseUid, + //Action = "publish", + //Locale = new List { "en-us" }, + //Reference = false, + //Items = availableEntries.Skip(4).Take(1).Select(e => new BulkAddItem + //{ + //Uid = e.Uid, + //ContentType = _contentTypeUid, + //ContentTypeUid = _contentTypeUid, + //Version = e.Version, + //Locale = "en-us", + //Title = e.Title + //}).ToList() + //}; + // + //ContentstackResponse bulkUpdateResponse = _stack.BulkOperation().UpdateItems(releaseData, "2.0"); + //var bulkUpdateResponseJson = bulkUpdateResponse.OpenJsonObjectResponse(); + // + //AssertLogger.IsNotNull(bulkUpdateResponse, "bulkUpdateResponse"); + //AssertLogger.IsTrue(bulkUpdateResponse.IsSuccessStatusCode, "bulkUpdateSuccess"); + // + //if (bulkUpdateResponseJson["job_id"] != null) + //{ + //string bulkJobId = bulkUpdateResponseJson["job_id"].ToString(); + // + //// Check job status + //await Task.Delay(2000); + //await CheckBulkJobStatus(bulkJobId, "2.0"); + //} + //} + //catch (Exception ex) + //{ + //FailWithError("Update items in release", ex); + //} + //} + // + //[TestMethod] + //[DoNotParallelize] public async Task Test007_Should_Perform_Bulk_Delete_Operation() { TestOutputLogger.LogContext("TestScenario", "BulkDeleteOperation"); @@ -1071,7 +1076,7 @@ public async Task Test008_Should_Perform_Bulk_Workflow_Operations() }; ContentstackResponse response = _stack.BulkOperation().Update(workflowUpdateBody); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); AssertLogger.IsNotNull(response, "bulkWorkflowResponse"); AssertLogger.IsTrue(response.IsSuccessStatusCode, "bulkWorkflowSuccess"); @@ -1129,24 +1134,24 @@ public void Test009_Should_Cleanup_Test_Resources() } } - // 3. Delete the workflow and publishing rule - CleanupBulkTestWorkflowAndPublishingRule(_stack); - Console.WriteLine("[Cleanup] Workflow and publishing rule cleanup done."); - - // 4. Delete the test release - if (!string.IsNullOrEmpty(_testReleaseUid)) - { - try - { - _stack.Release(_testReleaseUid).Delete(); - Console.WriteLine($"[Cleanup] Deleted release: {_testReleaseUid}"); - _testReleaseUid = null; - } - catch (Exception ex) - { - Console.WriteLine($"[Cleanup] Failed to delete release {_testReleaseUid}: {ex.Message}"); - } - } + // 3. Stack.Workflow() not yet migrated — commented out + //CleanupBulkTestWorkflowAndPublishingRule(_stack); + //Console.WriteLine("[Cleanup] Workflow and publishing rule cleanup done."); + + // 4. Stack.Release() not yet migrated — commented out + //if (!string.IsNullOrEmpty(_testReleaseUid)) + //{ + // try + // { + // _stack.Release(_testReleaseUid).Delete(); + // Console.WriteLine($"[Cleanup] Deleted release: {_testReleaseUid}"); + // _testReleaseUid = null; + // } + // catch (Exception ex) + // { + // Console.WriteLine($"[Cleanup] Failed to delete release {_testReleaseUid}: {ex.Message}"); + // } + //} // 5. Delete the test environment if (!string.IsNullOrEmpty(_testEnvironmentUid)) @@ -2971,7 +2976,7 @@ public async Task Test053_BulkOperations_Should_Handle_Job_Creation_Failures() var response = await _stack.BulkOperation().AddItemsAsync(problematicData); if (response.IsSuccessStatusCode) { - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (responseJson["job_id"] != null) { string jobId = responseJson["job_id"].ToString(); @@ -2983,7 +2988,7 @@ public async Task Test053_BulkOperations_Should_Handle_Job_Creation_Failures() try { var jobStatusResponse = await _stack.BulkOperation().JobStatusAsync(jobId); - var jobJson = jobStatusResponse.OpenJObjectResponse(); + var jobJson = jobStatusResponse.OpenJsonObjectResponse(); // Look for failure indicators in job status if (jobJson["status"]?.ToString() == "failed" || @@ -3113,7 +3118,7 @@ public async Task Test055_BulkOperations_Should_Handle_Concurrent_Job_Requests() var result = results[i]; if (result.IsSuccessStatusCode) { - var resultJson = result.OpenJObjectResponse(); + var resultJson = result.OpenJsonObjectResponse(); if (resultJson["job_id"] != null) { Console.WriteLine($"[Test055] Concurrent job {i + 1} created successfully: {resultJson["job_id"]}"); @@ -3181,7 +3186,7 @@ public async Task Test056_BulkOperations_Should_Handle_Job_Status_Polling_Errors var response = await _stack.BulkOperation().UpdateAsync(workflowBody); if (response.IsSuccessStatusCode) { - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (responseJson["job_id"] != null) { string jobId = responseJson["job_id"].ToString(); @@ -3603,12 +3608,12 @@ private async Task CheckBulkJobStatus(string jobId, string bulkVersion = null) try { ContentstackResponse statusResponse = await _stack.BulkOperation().JobStatusAsync(jobId, bulkVersion); - var statusJson = statusResponse.OpenJObjectResponse(); + var statusJson = statusResponse.OpenJsonObjectResponse(); AssertLogger.IsNotNull(statusResponse, "jobStatusResponse"); AssertLogger.IsTrue(statusResponse.IsSuccessStatusCode, "jobStatusSuccess"); } - catch (Exception e) + catch (Exception) { // Failed to check job status } @@ -3633,14 +3638,14 @@ private async Task CreateTestEnvironment() }; ContentstackResponse response = _stack.Environment().Create(environmentModel); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environment"] != null) { _testEnvironmentUid = responseJson["environment"]["uid"].ToString(); } } - catch (Exception e) + catch (Exception) { // Don't fail the test if environment creation fails } @@ -3648,29 +3653,23 @@ private async Task CreateTestEnvironment() private async Task CreateTestRelease() { - try - { - // Create test release - var releaseModel = new ReleaseModel - { - Name = "bulk_test_release", - Description = "Release for testing bulk operations", - Locked = false, - Archived = false - }; - - ContentstackResponse response = _stack.Release().Create(releaseModel); - var responseJson = response.OpenJObjectResponse(); - - if (response.IsSuccessStatusCode && responseJson["release"] != null) - { - _testReleaseUid = responseJson["release"]["uid"].ToString(); - } - } - catch (Exception e) - { - // Don't fail the test if release creation fails - } + // Stack.Release() not yet migrated — commented out + //try + //{ + // var releaseModel = new ReleaseModel + // { + // Name = "bulk_test_release", + // Description = "Release for testing bulk operations", + // Locked = false, + // Archived = false + // }; + // ContentstackResponse response = _stack.Release().Create(releaseModel); + // var responseJson = response.OpenJsonObjectResponse(); + // if (response.IsSuccessStatusCode && responseJson["release"] != null) + // _testReleaseUid = responseJson["release"]["uid"].ToString(); + //} + //catch (Exception e) { } + await Task.CompletedTask; } private async Task> GetAvailableEnvironments() @@ -3698,11 +3697,11 @@ private async Task> GetAvailableEnvironments() try { ContentstackResponse response = _stack.Environment().Query().Find(); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environments"] != null) { - var environments = responseJson["environments"] as JArray; + var environments = responseJson["environments"]?.AsArray(); if (environments != null && environments.Count > 0) { var environmentUids = new List(); @@ -3717,7 +3716,7 @@ private async Task> GetAvailableEnvironments() } } } - catch (Exception e) + catch (Exception) { // Failed to get environments } @@ -3725,7 +3724,7 @@ private async Task> GetAvailableEnvironments() // Fallback to empty list if no environments found return new List(); } - catch (Exception e) + catch (Exception) { return new List(); } @@ -3779,7 +3778,7 @@ private async Task EnsureBulkTestContentTypeAndEntriesAsync() { var entry = new SimpleEntry { Title = "Bulk test entry" }; ContentstackResponse createResponse = _stack.ContentType(_contentTypeUid).Entry().Create(entry); - var responseJson = createResponse.OpenJObjectResponse(); + var responseJson = createResponse.OpenJsonObjectResponse(); if (createResponse.IsSuccessStatusCode && responseJson["entry"] != null && responseJson["entry"]["uid"] != null) { _createdEntries.Add(new EntryInfo @@ -3805,10 +3804,10 @@ private static List GetAvailableEnvironments(Stack stack) try { ContentstackResponse response = stack.Environment().Query().Find(); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environments"] != null) { - var environments = responseJson["environments"] as JArray; + var environments = responseJson["environments"]?.AsArray(); if (environments != null && environments.Count > 0) { var uids = new List(); @@ -3833,10 +3832,10 @@ private static async Task> GetAvailableEnvironmentsAsync(Stack stac try { ContentstackResponse response = stack.Environment().Query().Find(); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environments"] != null) { - var environments = responseJson["environments"] as JArray; + var environments = responseJson["environments"]?.AsArray(); if (environments != null && environments.Count > 0) { var uids = new List(); @@ -3881,7 +3880,7 @@ private static void EnsureBulkTestEnvironment(Stack stack) }; ContentstackResponse response = stack.Environment().Create(environmentModel); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environment"]?["uid"] != null) _bulkTestEnvironmentUid = responseJson["environment"]["uid"].ToString(); } @@ -3916,7 +3915,7 @@ private static async Task EnsureBulkTestEnvironmentAsync(Stack stack) }; ContentstackResponse response = stack.Environment().Create(environmentModel); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["environment"]?["uid"] != null) _bulkTestEnvironmentUid = responseJson["environment"]["uid"].ToString(); } @@ -3929,191 +3928,8 @@ private static async Task EnsureBulkTestEnvironmentAsync(Stack stack) /// private static async Task EnsureBulkTestWorkflowAndPublishingRuleAsync(Stack stack) { - _bulkTestWorkflowSetupError = null; - const string workflowName = "workflow_test"; - try - { - await EnsureBulkTestEnvironmentAsync(stack); - if (string.IsNullOrEmpty(_bulkTestEnvironmentUid)) - { - _bulkTestWorkflowSetupError = "No environment. Ensure environment failed (none found and create failed)."; - return; - } - // Find existing workflow by name "workflow_test" (same as Test000a) - try - { - ContentstackResponse listResponse = stack.Workflow().FindAll(); - if (listResponse.IsSuccessStatusCode) - { - var listJson = listResponse.OpenJObjectResponse(); - var existing = (listJson["workflows"] as JArray) ?? (listJson["workflow"] as JArray); - if (existing != null) - { - foreach (var wf in existing) - { - if (wf["name"]?.ToString() == workflowName && wf["uid"] != null) - { - _bulkTestWorkflowUid = wf["uid"].ToString(); - var existingStages = wf["workflow_stages"] as JArray; - if (existingStages != null && existingStages.Count >= 2) - { - _bulkTestWorkflowStage1Uid = existingStages[0]["uid"]?.ToString(); - _bulkTestWorkflowStage2Uid = existingStages[1]["uid"]?.ToString(); - _bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; - break; // Found; skip create - } - } - } - } - } - } - catch { /* If listing fails, proceed to create */ } - - // Create workflow only if not found (same payload as Test000a / final curl) - if (string.IsNullOrEmpty(_bulkTestWorkflowUid)) - { - var sysAcl = new Dictionary - { - ["roles"] = new Dictionary { ["uids"] = new List() }, - ["users"] = new Dictionary { ["uids"] = new List { "$all" } }, - ["others"] = new Dictionary() - }; - - var workflowModel = new WorkflowModel - { - Name = workflowName, - Enabled = true, - Branches = new List { "main" }, - ContentTypes = new List { "$all" }, - AdminUsers = new Dictionary { ["users"] = new List() }, - WorkflowStages = new List - { - new WorkflowStage - { - Name = "New stage 1", - Color = "#fe5cfb", - SystemACL = sysAcl, - NextAvailableStages = new List { "$all" }, - AllStages = true, - AllUsers = true, - SpecificStages = false, - SpecificUsers = false, - EntryLock = "$none" - }, - new WorkflowStage - { - Name = "New stage 2", - Color = "#3688bf", - SystemACL = new Dictionary - { - ["roles"] = new Dictionary { ["uids"] = new List() }, - ["users"] = new Dictionary { ["uids"] = new List { "$all" } }, - ["others"] = new Dictionary() - }, - NextAvailableStages = new List { "$all" }, - AllStages = true, - AllUsers = true, - SpecificStages = false, - SpecificUsers = false, - EntryLock = "$none" - } - } - }; - - ContentstackResponse workflowResponse = stack.Workflow().Create(workflowModel); - if (!workflowResponse.IsSuccessStatusCode) - { - string body = null; - try { body = workflowResponse.OpenResponse(); } catch { } - _bulkTestWorkflowSetupError = $"Workflow create returned HTTP {(int)workflowResponse.StatusCode} ({workflowResponse.StatusCode}). Response: {body ?? "(null)"}"; - return; - } - - var workflowJson = workflowResponse.OpenJObjectResponse(); - var workflowObj = workflowJson["workflow"]; - if (workflowObj == null) - { - string body = null; - try { body = workflowResponse.OpenResponse(); } catch { } - _bulkTestWorkflowSetupError = "Workflow create response had no 'workflow' key. Response: " + (body ?? "(null)"); - return; - } - - _bulkTestWorkflowUid = workflowObj["uid"]?.ToString(); - var stages = workflowObj["workflow_stages"] as JArray; - if (stages != null && stages.Count >= 2) - { - _bulkTestWorkflowStage1Uid = stages[0]?["uid"]?.ToString(); - _bulkTestWorkflowStage2Uid = stages[1]?["uid"]?.ToString(); - _bulkTestWorkflowStageUid = _bulkTestWorkflowStage2Uid; - } - } - - if (string.IsNullOrEmpty(_bulkTestWorkflowUid) || string.IsNullOrEmpty(_bulkTestWorkflowStage2Uid)) - { - _bulkTestWorkflowSetupError = "Workflow UID or stage UIDs not set. Find or create failed."; - return; - } - - // Find existing publish rule for this workflow + stage + environment - try - { - ContentstackResponse ruleListResponse = stack.Workflow().PublishRule().FindAll(); - if (ruleListResponse.IsSuccessStatusCode) - { - var ruleListJson = ruleListResponse.OpenJObjectResponse(); - var rules = (ruleListJson["publishing_rules"] as JArray) ?? (ruleListJson["publishing_rule"] as JArray); - if (rules != null) - { - foreach (var rule in rules) - { - if (rule["workflow"]?.ToString() == _bulkTestWorkflowUid - && rule["workflow_stage"]?.ToString() == _bulkTestWorkflowStage2Uid - && rule["environment"]?.ToString() == _bulkTestEnvironmentUid - && rule["uid"] != null) - { - _bulkTestPublishRuleUid = rule["uid"].ToString(); - return; // Publish rule already exists - } - } - } - } - } - catch { /* If listing fails, proceed to create */ } - - var publishRuleModel = new PublishRuleModel - { - WorkflowUid = _bulkTestWorkflowUid, - WorkflowStageUid = _bulkTestWorkflowStage2Uid, - Environment = _bulkTestEnvironmentUid, - Branches = new List { "main" }, - ContentTypes = new List { "$all" }, - Locales = new List { "en-us" }, - Actions = new List(), - Approvers = new Approvals { Users = new List(), Roles = new List() }, - DisableApproval = false - }; - - ContentstackResponse ruleResponse = stack.Workflow().PublishRule().Create(publishRuleModel); - if (!ruleResponse.IsSuccessStatusCode) - { - string body = null; - try { body = ruleResponse.OpenResponse(); } catch { } - _bulkTestWorkflowSetupError = $"Publish rule create returned HTTP {(int)ruleResponse.StatusCode} ({ruleResponse.StatusCode}). Response: {body ?? "(null)"}"; - return; - } - - var ruleJson = ruleResponse.OpenJObjectResponse(); - _bulkTestPublishRuleUid = ruleJson["publishing_rule"]?["uid"]?.ToString(); - } - catch (ContentstackErrorException ex) - { - _bulkTestWorkflowSetupError = $"Workflow setup threw: HTTP {(int)ex.StatusCode} ({ex.StatusCode}), ErrorCode: {ex.ErrorCode}, Message: {ex.ErrorMessage ?? ex.Message}"; - } - catch (Exception ex) - { - _bulkTestWorkflowSetupError = "Workflow setup threw: " + ex.Message; - } + // Stack.Workflow() not yet migrated — commented out + await Task.CompletedTask; } /// @@ -4121,35 +3937,20 @@ private static async Task EnsureBulkTestWorkflowAndPublishingRuleAsync(Stack sta /// private static void CleanupBulkTestWorkflowAndPublishingRule(Stack stack) { - if (!string.IsNullOrEmpty(_bulkTestPublishRuleUid)) - { - try - { - stack.Workflow().PublishRule(_bulkTestPublishRuleUid).Delete(); - } - catch - { - // Ignore cleanup failure - } - _bulkTestPublishRuleUid = null; - } - - if (!string.IsNullOrEmpty(_bulkTestWorkflowUid)) - { - try - { - stack.Workflow(_bulkTestWorkflowUid).Delete(); - } - catch - { - // Ignore cleanup failure - } - _bulkTestWorkflowUid = null; - } - - _bulkTestWorkflowStageUid = null; - _bulkTestWorkflowStage1Uid = null; - _bulkTestWorkflowStage2Uid = null; + // Stack.Workflow() not yet migrated — commented out + //if (!string.IsNullOrEmpty(_bulkTestPublishRuleUid)) + //{ + // try { stack.Workflow().PublishRule(_bulkTestPublishRuleUid).Delete(); } catch { } + // _bulkTestPublishRuleUid = null; + //} + //if (!string.IsNullOrEmpty(_bulkTestWorkflowUid)) + //{ + // try { stack.Workflow(_bulkTestWorkflowUid).Delete(); } catch { } + // _bulkTestWorkflowUid = null; + //} + //_bulkTestWorkflowStageUid = null; + //_bulkTestWorkflowStage1Uid = null; + //_bulkTestWorkflowStage2Uid = null; } /// @@ -4177,7 +3978,7 @@ private async Task AssignEntriesToWorkflowStagesAsync(List entries) ContentstackResponse r = _stack.BulkOperation().Update(body); if (r.IsSuccessStatusCode) { - var j = r.OpenJObjectResponse(); + var j = r.OpenJsonObjectResponse(); if (j?["job_id"] != null) { await Task.Delay(2000); await CheckBulkJobStatus(j["job_id"].ToString()); } } } @@ -4191,11 +3992,11 @@ private async Task> FetchExistingEntries() { // Query entries from the content type ContentstackResponse response = _stack.ContentType(_contentTypeUid).Entry().Query().Find(); - var responseJson = response.OpenJObjectResponse(); + var responseJson = response.OpenJsonObjectResponse(); if (response.IsSuccessStatusCode && responseJson["entries"] != null) { - var entries = responseJson["entries"] as JArray; + var entries = responseJson["entries"]?.AsArray(); if (entries != null && entries.Count > 0) { var entryList = new List(); @@ -4217,7 +4018,7 @@ private async Task> FetchExistingEntries() return new List(); } - catch (Exception e) + catch (Exception) { return new List(); } @@ -4225,116 +4026,72 @@ private async Task> FetchExistingEntries() private async Task> GetAvailableReleases() { - try - { - // First try to use our test release - if (!string.IsNullOrEmpty(_testReleaseUid)) - { - try - { - ContentstackResponse fetchResponse = _stack.Release(_testReleaseUid).Fetch(); - if (fetchResponse.IsSuccessStatusCode) - { - return new List { _testReleaseUid }; - } - } - catch - { - // Test release doesn't exist, fall back to available releases - } - } - - // Try to get available releases - try - { - ContentstackResponse response = _stack.Release().Query().Find(); - var responseJson = response.OpenJObjectResponse(); - - if (response.IsSuccessStatusCode && responseJson["releases"] != null) - { - var releases = responseJson["releases"] as JArray; - if (releases != null && releases.Count > 0) - { - var releaseUids = new List(); - foreach (var release in releases) - { - if (release["uid"] != null) - { - releaseUids.Add(release["uid"].ToString()); - } - } - return releaseUids; - } - } - } - catch (Exception e) - { - // Failed to get releases - } - - // Fallback to empty list if no releases found - return new List(); - } - catch (Exception e) - { - return new List(); - } + // Stack.Release() not yet migrated — commented out + //try + //{ + // if (!string.IsNullOrEmpty(_testReleaseUid)) + // { + // try + // { + // ContentstackResponse fetchResponse = _stack.Release(_testReleaseUid).Fetch(); + // if (fetchResponse.IsSuccessStatusCode) + // return new List { _testReleaseUid }; + // } + // catch { } + // } + // ContentstackResponse response = _stack.Release().Query().Find(); + // var responseJson = response.OpenJsonObjectResponse(); + // if (response.IsSuccessStatusCode && responseJson["releases"] != null) + // { + // var releases = responseJson["releases"]?.AsArray(); + // if (releases != null && releases.Count > 0) + // { + // var releaseUids = new List(); + // foreach (var release in releases) + // if (release["uid"] != null) + // releaseUids.Add(release["uid"].ToString()); + // return releaseUids; + // } + // } + //} + //catch (Exception e) { } + return new List(); } private async Task FetchAvailableRelease() { - try - { - // First try to use our test release if it exists - if (!string.IsNullOrEmpty(_testReleaseUid)) - { - try - { - ContentstackResponse fetchResponse = _stack.Release(_testReleaseUid).Fetch(); - if (fetchResponse.IsSuccessStatusCode) - { - return _testReleaseUid; - } - } - catch - { - // Test release not found, look for other releases - } - } - - // Query for available releases - ContentstackResponse response = _stack.Release().Query().Find(); - var responseJson = response.OpenJObjectResponse(); - - if (response.IsSuccessStatusCode && responseJson["releases"] != null) - { - var releases = responseJson["releases"] as JArray; - if (releases != null && releases.Count > 0) - { - // Get the first available release - var firstRelease = releases[0]; - if (firstRelease["uid"] != null) - { - string releaseUid = firstRelease["uid"].ToString(); - return releaseUid; - } - } - } - - return null; - } - catch (Exception e) - { - return null; - } + // Stack.Release() not yet migrated — commented out + //try + //{ + // if (!string.IsNullOrEmpty(_testReleaseUid)) + // { + // try + // { + // ContentstackResponse fetchResponse = _stack.Release(_testReleaseUid).Fetch(); + // if (fetchResponse.IsSuccessStatusCode) + // return _testReleaseUid; + // } + // catch { } + // } + // ContentstackResponse response = _stack.Release().Query().Find(); + // var responseJson = response.OpenJsonObjectResponse(); + // if (response.IsSuccessStatusCode && responseJson["releases"] != null) + // { + // var releases = responseJson["releases"]?.AsArray(); + // if (releases != null && releases.Count > 0 && releases[0]["uid"] != null) + // return releases[0]["uid"].ToString(); + // } + //} + //catch (Exception e) { } + return null; } public class SimpleEntry : IEntry { - [JsonProperty(propertyName: "title")] + [JsonPropertyName("title")] public string Title { get; set; } - [JsonProperty(propertyName: "_variant")] + [JsonPropertyName("_variant")] public object Variant { get; set; } } diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs index 4630eca..e6c9e8b 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack021_EntryVariantTest.cs @@ -1905,8 +1905,6 @@ public void Test048_Should_Fail_Delete_Variant_With_Active_Dependencies_Sync() TestOutputLogger.LogContext("TestScenario", "Test048_Should_Fail_Delete_Variant_With_Active_Dependencies_Sync"); - string createdVariantEntryUid = null; - try { // First create a variant to establish dependency diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs index 9fea19e..141f95f 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack022_VariantGroupTest.cs @@ -1031,7 +1031,7 @@ public async Task Test112_Should_Fail_Unlink_With_Invalid_Parameter_Types() AssertValidationError(ex.StatusCode, "InvalidParameterTypesException"); Console.WriteLine($"✅ API properly handled invalid parameter types: {ex.ErrorMessage}"); } - catch (ArgumentException ex) + catch (ArgumentException) { AssertLogger.IsTrue(true, "SDK validation caught invalid parameter types as expected", "InvalidParameterTypes"); } @@ -1237,7 +1237,7 @@ public async Task Test117_Should_Fail_With_Empty_String_UIDs() AssertValidationError(ex.StatusCode, "EmptyStringUIDsException"); Console.WriteLine($"✅ API properly handled empty string UIDs: {ex.ErrorMessage}"); } - catch (ArgumentException ex) + catch (ArgumentException) { AssertLogger.IsTrue(true, "SDK validation caught empty string UIDs as expected", "EmptyStringUIDs"); } diff --git a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack999_LogoutTest.cs b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack999_LogoutTest.cs index 08a88f5..8e1614e 100644 --- a/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack999_LogoutTest.cs +++ b/Contentstack.Management.Core.Tests/IntegrationTest/Contentstack999_LogoutTest.cs @@ -629,7 +629,7 @@ public void Test037_Should_Handle_Logout_With_Different_Token_Than_Stored() AssertLogger.AreEqual(storedToken, client.contentstackOptions.Authtoken, "StoredTokenUnchanged"); AssertLogger.IsNotNull(response, "LogoutResponseReceived"); } - catch (Exception e) + catch (Exception) { // If it fails, the stored token should still remain unchanged AssertLogger.AreEqual(storedToken, client.contentstackOptions.Authtoken, "StoredTokenUnchangedAfterFailure"); diff --git a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj index fa0a3b9..4af9382 100644 --- a/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj +++ b/Contentstack.Management.Core.Unit.Tests/Contentstack.Management.Core.Unit.Tests.csproj @@ -20,7 +20,6 @@ - @@ -56,8 +55,6 @@ - - @@ -75,17 +72,6 @@ - - - - - - - - - - - diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs index d0e230d..ee2ad94 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkAddItemsServiceTest.cs @@ -6,14 +6,14 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkAddItemsServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs index 11f05c1..8c864cc 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkDeleteServiceTest.cs @@ -6,14 +6,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkDeleteServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -233,10 +234,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var details = new BulkDeleteDetails(); - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkDeleteService(customSerializer, new Management.Core.Models.Stack(null), details); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs index 2bb416b..577ce58 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkJobStatusServiceTest.cs @@ -5,14 +5,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkJobStatusServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -242,10 +243,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var jobId = "test-job-id"; - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkJobStatusService(customSerializer, new Management.Core.Models.Stack(null), jobId); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs index 73284a2..7f7ded4 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkPublishServiceTest.cs @@ -6,14 +6,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkPublishServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -257,10 +258,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var details = new BulkPublishDetails(); - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkPublishService(customSerializer, new Management.Core.Models.Stack(null), details); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs index 22dc90b..c9e73a6 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkReleaseItemsServiceTest.cs @@ -6,14 +6,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkReleaseItemsServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -271,10 +272,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var data = new BulkReleaseItemsData(); - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkReleaseItemsService(customSerializer, new Management.Core.Models.Stack(null), data); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs index ff9b709..c179f6e 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUnpublishServiceTest.cs @@ -6,14 +6,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkUnpublishServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -257,10 +258,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var details = new BulkPublishDetails(); - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkUnpublishService(customSerializer, new Management.Core.Models.Stack(null), details); diff --git a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs index fc28d12..67c24c9 100644 --- a/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Core/Services/Stack/BulkUpdateItemsServiceTest.cs @@ -6,14 +6,15 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core.Services; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Unit.Tests.Core.Services.Stack { [TestClass] public class BulkUpdateItemsServiceTest { - private JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings()); + private JsonSerializerOptions serializer = new JsonSerializerOptions(); private readonly IFixture _fixture = new Fixture() .Customize(new AutoMoqCustomization()); @@ -281,10 +282,7 @@ public void Should_Verify_Service_Properties_Are_Set() public void Should_Verify_Service_Can_Be_Instantiated_With_Different_Serializers() { var data = new BulkAddItemsData(); - var customSerializer = JsonSerializer.Create(new JsonSerializerSettings - { - NullValueHandling = NullValueHandling.Ignore - }); + var customSerializer = new JsonSerializerOptions { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; var service = new BulkUpdateItemsService(customSerializer, new Management.Core.Models.Stack(null), data); diff --git a/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationModelsTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationModelsTest.cs index 0e5a8b5..45284f1 100644 --- a/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationModelsTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationModelsTest.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; -using Newtonsoft.Json; +using System.Text.Json; using Contentstack.Management.Core.Models; namespace Contentstack.Management.Core.Unit.Tests.Models.BulkOperation @@ -9,6 +9,7 @@ namespace Contentstack.Management.Core.Unit.Tests.Models.BulkOperation [TestClass] public class BulkOperationModelsTest { + private static readonly JsonSerializerOptions _options = new JsonSerializerOptions(); [TestMethod] public void BulkPublishDetails_Serialization_Test() { @@ -42,8 +43,8 @@ public void BulkPublishDetails_Serialization_Test() }; - var json = JsonConvert.SerializeObject(details); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(details, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Entries.Count); @@ -74,8 +75,8 @@ public void BulkPublishEntry_WithContentType_Serialization_Test() }; - var json = JsonConvert.SerializeObject(entry); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(entry, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual("entry_uid", deserialized.Uid); @@ -113,8 +114,8 @@ public void BulkDeleteDetails_Serialization_Test() }; - var json = JsonConvert.SerializeObject(details); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(details, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Entries.Count); @@ -168,8 +169,8 @@ public void BulkWorkflowUpdateBody_Serialization_Test() }; - var json = JsonConvert.SerializeObject(updateBody); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(updateBody, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Entries.Count); @@ -220,8 +221,8 @@ public void BulkAddItemsData_Serialization_Test() }; - var json = JsonConvert.SerializeObject(data); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(data, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Items.Count); @@ -242,16 +243,14 @@ public void BulkPublishDetails_EmptyCollections_Test() }; - var json = JsonConvert.SerializeObject(details); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(details, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); - // Collections may be null after deserialization due to ShouldSerialize methods - // Initialize them if they're null deserialized.Entries = deserialized.Entries ?? new List(); deserialized.Assets = deserialized.Assets ?? new List(); - Assert.IsNotNull(deserialized.Locales); - Assert.IsNotNull(deserialized.Environments); + deserialized.Locales = deserialized.Locales ?? new List(); + deserialized.Environments = deserialized.Environments ?? new List(); Assert.AreEqual(0, deserialized.Entries.Count); Assert.AreEqual(0, deserialized.Assets.Count); Assert.AreEqual(0, deserialized.Locales.Count); @@ -285,8 +284,8 @@ public void BulkPublishDetails_WithRulesAndScheduling_Test() }; - var json = JsonConvert.SerializeObject(details); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(details, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Entries.Count); @@ -317,14 +316,12 @@ public void BulkWorkflowStage_EmptyCollections_Test() }; - var json = JsonConvert.SerializeObject(workflowStage); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(workflowStage, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual("test_uid", deserialized.Uid); Assert.AreEqual("test_comment", deserialized.Comment); - // Collections may be null after deserialization due to ShouldSerialize methods - // Initialize them if they're null deserialized.AssignedTo = deserialized.AssignedTo ?? new List(); deserialized.AssignedByRoles = deserialized.AssignedByRoles ?? new List(); Assert.AreEqual(0, deserialized.AssignedTo.Count); @@ -342,8 +339,8 @@ public void BulkPublishEntry_NullValues_Test() }; - var json = JsonConvert.SerializeObject(entry); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(entry, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual("entry_uid", deserialized.Uid); diff --git a/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationsUnitTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationsUnitTest.cs index da37367..9ca2f74 100644 --- a/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationsUnitTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Models/BulkOperation/BulkOperationsUnitTest.cs @@ -1,13 +1,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Contentstack.Management.Core.Models; using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json; namespace Contentstack.Management.Core.Unit.Tests.Models.BulkOperation { [TestClass] public class BulkOperationsUnitTest { + private static readonly JsonSerializerOptions _options = new JsonSerializerOptions(); [TestMethod] public void Test001_BulkReleaseItemsData_Serialization() { @@ -32,7 +33,7 @@ public void Test001_BulkReleaseItemsData_Serialization() }; - var json = JsonConvert.SerializeObject(releaseData); + var json = JsonSerializer.Serialize(releaseData, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("release")); @@ -60,7 +61,7 @@ public void Test002_BulkReleaseItem_Serialization() }; - var json = JsonConvert.SerializeObject(item); + var json = JsonSerializer.Serialize(item, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("content_type_uid")); @@ -91,7 +92,7 @@ public void Test003_BulkReleaseItemsData_Deserialization() }"; - var releaseData = JsonConvert.DeserializeObject(json); + var releaseData = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(releaseData); Assert.AreEqual("release_uid", releaseData.Release); @@ -120,7 +121,7 @@ public void Test004_BulkReleaseItem_Deserialization() }"; - var item = JsonConvert.DeserializeObject(json); + var item = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(item); Assert.AreEqual("ct_1", item.ContentTypeUid); @@ -141,7 +142,7 @@ public void Test005_BulkReleaseItemsData_Empty_Collections() }; - var json = JsonConvert.SerializeObject(releaseData); + var json = JsonSerializer.Serialize(releaseData, _options); Assert.IsNotNull(json); Assert.IsNotNull(releaseData.Locale); @@ -182,8 +183,8 @@ public void Test006_BulkReleaseItemsData_Multiple_Items() }; - var json = JsonConvert.SerializeObject(releaseData); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(releaseData, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Items.Count); @@ -217,8 +218,8 @@ public void Test007_BulkReleaseItemsData_Different_Actions() }; - var publishJson = JsonConvert.SerializeObject(publishData); - var unpublishJson = JsonConvert.SerializeObject(unpublishData); + var publishJson = JsonSerializer.Serialize(publishData, _options); + var unpublishJson = JsonSerializer.Serialize(unpublishData, _options); Assert.IsTrue(publishJson.Contains("publish")); Assert.IsTrue(publishJson.Contains("true")); @@ -253,7 +254,7 @@ public void Test008_BulkPublishDetails_Serialization() }; - var json = JsonConvert.SerializeObject(publishDetails); + var json = JsonSerializer.Serialize(publishDetails, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("entries")); @@ -288,7 +289,7 @@ public void Test009_BulkPublishDetails_Deserialization() }"; - var publishDetails = JsonConvert.DeserializeObject(json); + var publishDetails = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(publishDetails); Assert.AreEqual(1, publishDetails.Entries.Count); @@ -319,7 +320,7 @@ public void Test010_BulkPublishEntry_Serialization() }; - var json = JsonConvert.SerializeObject(entry); + var json = JsonSerializer.Serialize(entry, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("uid")); @@ -338,7 +339,7 @@ public void Test011_BulkPublishRules_Serialization() }; - var json = JsonConvert.SerializeObject(rules); + var json = JsonSerializer.Serialize(rules, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("approvals")); @@ -354,7 +355,7 @@ public void Test012_BulkPublishRules_Deserialization() }"; - var rules = JsonConvert.DeserializeObject(json); + var rules = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(rules); Assert.AreEqual("false", rules.Approvals); @@ -396,8 +397,8 @@ public void Test013_BulkPublishDetails_Multiple_Entries() }; - var json = JsonConvert.SerializeObject(publishDetails); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(publishDetails, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(3, deserialized.Entries.Count); @@ -434,8 +435,8 @@ public void Test014_BulkPublishDetails_With_Assets() }; - var json = JsonConvert.SerializeObject(publishDetails); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(publishDetails, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(1, deserialized.Entries.Count); @@ -453,7 +454,7 @@ public void Test015_BulkPublishAsset_Serialization() }; - var json = JsonConvert.SerializeObject(asset); + var json = JsonSerializer.Serialize(asset, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("uid")); @@ -471,16 +472,14 @@ public void Test016_BulkPublishDetails_Empty_Collections() }; - var json = JsonConvert.SerializeObject(publishDetails); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(publishDetails, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); - // Collections may be null after deserialization due to ShouldSerialize methods - // Initialize them if they're null deserialized.Entries = deserialized.Entries ?? new List(); deserialized.Assets = deserialized.Assets ?? new List(); - Assert.IsNotNull(deserialized.Locales); - Assert.IsNotNull(deserialized.Environments); + deserialized.Locales = deserialized.Locales ?? new List(); + deserialized.Environments = deserialized.Environments ?? new List(); Assert.AreEqual(0, deserialized.Entries.Count); Assert.AreEqual(0, deserialized.Assets.Count); Assert.AreEqual(0, deserialized.Locales.Count); @@ -508,7 +507,7 @@ public void Test017_BulkReleaseItemsData_Null_Values() }; - var json = JsonConvert.SerializeObject(releaseData); + var json = JsonSerializer.Serialize(releaseData, _options); Assert.IsNotNull(json); // Should handle null values gracefully @@ -534,7 +533,7 @@ public void Test018_BulkPublishDetails_Null_Values() }; - var json = JsonConvert.SerializeObject(publishDetails); + var json = JsonSerializer.Serialize(publishDetails, _options); Assert.IsNotNull(json); // Should handle null values gracefully @@ -579,8 +578,8 @@ public void Test019_BulkReleaseItemsData_Complex_Scenario() }; - var json = JsonConvert.SerializeObject(releaseData); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(releaseData, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(3, deserialized.Locale.Count); @@ -631,8 +630,8 @@ public void Test020_BulkPublishDetails_Complex_Scenario() }; - var json = JsonConvert.SerializeObject(publishDetails); - var deserialized = JsonConvert.DeserializeObject(json); + var json = JsonSerializer.Serialize(publishDetails, _options); + var deserialized = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(deserialized); Assert.AreEqual(2, deserialized.Entries.Count); diff --git a/Contentstack.Management.Core.Unit.Tests/Models/BulkReleaseItemsTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/BulkReleaseItemsTest.cs index f1987f8..8fbd0c5 100644 --- a/Contentstack.Management.Core.Unit.Tests/Models/BulkReleaseItemsTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Models/BulkReleaseItemsTest.cs @@ -1,13 +1,14 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Contentstack.Management.Core.Models; using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json; namespace Contentstack.Management.Core.Unit.Tests.Models { [TestClass] public class BulkReleaseItemsTest { + private static readonly JsonSerializerOptions _options = new JsonSerializerOptions(); [TestMethod] public void Test001_BulkReleaseItemsData_Serialization() { @@ -32,7 +33,7 @@ public void Test001_BulkReleaseItemsData_Serialization() }; - var json = JsonConvert.SerializeObject(releaseData); + var json = JsonSerializer.Serialize(releaseData, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("release")); @@ -60,7 +61,7 @@ public void Test002_BulkReleaseItem_Serialization() }; - var json = JsonConvert.SerializeObject(item); + var json = JsonSerializer.Serialize(item, _options); Assert.IsNotNull(json); Assert.IsTrue(json.Contains("content_type_uid")); @@ -91,7 +92,7 @@ public void Test003_BulkReleaseItemsData_Deserialization() }"; - var releaseData = JsonConvert.DeserializeObject(json); + var releaseData = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(releaseData); Assert.AreEqual("release_uid", releaseData.Release); @@ -120,7 +121,7 @@ public void Test004_BulkReleaseItem_Deserialization() }"; - var item = JsonConvert.DeserializeObject(json); + var item = JsonSerializer.Deserialize(json, _options); Assert.IsNotNull(item); Assert.AreEqual("ct_1", item.ContentTypeUid); @@ -141,7 +142,7 @@ public void Test005_BulkReleaseItemsData_Empty_Collections() }; - var json = JsonConvert.SerializeObject(releaseData); + var json = JsonSerializer.Serialize(releaseData, _options); Assert.IsNotNull(json); Assert.IsNotNull(releaseData.Locale); diff --git a/Contentstack.Management.Core.Unit.Tests/Models/LocaleTest.cs b/Contentstack.Management.Core.Unit.Tests/Models/LocaleTest.cs index a5989f0..813ff73 100644 --- a/Contentstack.Management.Core.Unit.Tests/Models/LocaleTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Models/LocaleTest.cs @@ -31,12 +31,12 @@ public void Initialize_Locale() Assert.IsNull(locale.Uid); Assert.AreEqual($"/locales", locale.resourcePath); - Assert.ThrowsException(() => locale.Fetch()); - Assert.ThrowsExceptionAsync(() => locale.FetchAsync()); - Assert.ThrowsException(() => locale.Update(_fixture.Create())); - Assert.ThrowsExceptionAsync(() => locale.UpdateAsync(_fixture.Create())); - Assert.ThrowsException(() => locale.Delete()); - Assert.ThrowsExceptionAsync(() => locale.DeleteAsync()); + Assert.ThrowsException(() => locale.Fetch()); + Assert.ThrowsExceptionAsync(() => locale.FetchAsync()); + Assert.ThrowsException(() => locale.Update(_fixture.Create())); + Assert.ThrowsExceptionAsync(() => locale.UpdateAsync(_fixture.Create())); + Assert.ThrowsException(() => locale.Delete()); + Assert.ThrowsExceptionAsync(() => locale.DeleteAsync()); Assert.AreEqual(locale.Query().GetType(), typeof(Query)); } diff --git a/Contentstack.Management.Core.Unit.Tests/Runtime/Pipeline/RetryHandler/RetryDelayCalculatorTest.cs b/Contentstack.Management.Core.Unit.Tests/Runtime/Pipeline/RetryHandler/RetryDelayCalculatorTest.cs index 39ff621..396d3df 100644 --- a/Contentstack.Management.Core.Unit.Tests/Runtime/Pipeline/RetryHandler/RetryDelayCalculatorTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Runtime/Pipeline/RetryHandler/RetryDelayCalculatorTest.cs @@ -99,15 +99,13 @@ public void CalculateNetworkRetryDelay_Includes_Jitter() }; // Run multiple times to verify jitter is added - bool foundVariation = false; var firstDelay = calculator.CalculateNetworkRetryDelay(1, config); - + for (int i = 0; i < 10; i++) { var delay = calculator.CalculateNetworkRetryDelay(1, config); if (delay != firstDelay) { - foundVariation = true; break; } } diff --git a/Contentstack.Management.Core.Unit.Tests/Services/BulkOperationServicesTest.cs b/Contentstack.Management.Core.Unit.Tests/Services/BulkOperationServicesTest.cs index f2ccf92..040cf15 100644 --- a/Contentstack.Management.Core.Unit.Tests/Services/BulkOperationServicesTest.cs +++ b/Contentstack.Management.Core.Unit.Tests/Services/BulkOperationServicesTest.cs @@ -3,7 +3,7 @@ using Contentstack.Management.Core.Services.Stack.BulkOperation; using Contentstack.Management.Core; using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json; using System.Text; namespace Contentstack.Management.Core.Unit.Tests.Services @@ -11,13 +11,13 @@ namespace Contentstack.Management.Core.Unit.Tests.Services [TestClass] public class BulkOperationServicesTest { - private JsonSerializer _serializer; + private JsonSerializerOptions _serializer; private Stack _stack; [TestInitialize] public void Setup() { - _serializer = new JsonSerializer(); + _serializer = new JsonSerializerOptions(); var client = new ContentstackClient("test_token", "test_host"); _stack = client.Stack("test_api_key"); } diff --git a/Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs b/Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs index fd0d249..af70298 100644 --- a/Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs +++ b/Contentstack.Management.Core/Attributes/CSMJsonConverterAttribute.cs @@ -71,7 +71,7 @@ private static void GetType(Assembly assembly, List types) { foreach (var attr in type.GetCustomAttributes(typeof(CsmJsonConverterAttribute))) { - CsmJsonConverterAttribute ctdAttr = attr as CsmJsonConverterAttribute; + CsmJsonConverterAttribute? ctdAttr = attr as CsmJsonConverterAttribute; Trace.Assert(ctdAttr != null, "cast is null"); if (ctdAttr.isAutoloadEnable) { diff --git a/Contentstack.Management.Core/ContentstackClient.cs b/Contentstack.Management.Core/ContentstackClient.cs index 0cbf678..2d152fc 100644 --- a/Contentstack.Management.Core/ContentstackClient.cs +++ b/Contentstack.Management.Core/ContentstackClient.cs @@ -28,11 +28,11 @@ namespace Contentstack.Management.Core /// public class ContentstackClient : IContentstackClient { - internal ContentstackRuntimePipeline ContentstackPipeline { get; set; } + internal ContentstackRuntimePipeline? ContentstackPipeline { get; set; } internal ContentstackClientOptions contentstackOptions; #region Private - private HttpClient _httpClient; + private HttpClient _httpClient = null!; private bool _disposed = false; private string Version => "0.5.0"; @@ -41,13 +41,12 @@ public class ContentstackClient : IContentstackClient // OAuth token storage // private readonly Dictionary _oauthTokens = new Dictionary(); - private bool _isRefreshingToken = false; #endregion #region Public - public LogManager LogManager { get; set; } + public LogManager? LogManager { get; set; } /// /// Get and Set method for deserialization. /// @@ -226,7 +225,7 @@ protected void BuildPipeline() { httpClientHandler, new RetryHandler(retryPolicy) - }, LogManager); + }, LogManager!); } internal ContentstackResponse InvokeSync(TRequest request, bool addAcceptMediaHeader = false, string? apiVersion = null) where TRequest : IContentstackService @@ -243,7 +242,7 @@ internal ContentstackResponse InvokeSync(TRequest request, bool addAcc }, new ResponseContext()); - return (ContentstackResponse)ContentstackPipeline.InvokeSync(context, addAcceptMediaHeader, apiVersion).httpResponse; + return (ContentstackResponse)ContentstackPipeline!.InvokeSync(context, addAcceptMediaHeader, apiVersion).httpResponse!; } internal async Task InvokeAsync(TRequest request, bool addAcceptMediaHeader = false, string? apiVersion = null) @@ -267,7 +266,7 @@ internal async Task InvokeAsync(TRequest request service = request }, new ResponseContext()); - return await ContentstackPipeline.InvokeAsync(context, addAcceptMediaHeader, apiVersion); + return await ContentstackPipeline!.InvokeAsync(context, addAcceptMediaHeader, apiVersion); } #region Dispose methods @@ -436,8 +435,8 @@ internal void ThrowIfNotLoggedIn() /// The public ContentstackResponse Logout(string? authtoken = null) { - string token = authtoken ?? contentstackOptions.Authtoken; - LogoutService logout = new LogoutService(SerializerOptions, token); + string? token = authtoken ?? contentstackOptions.Authtoken; + LogoutService logout = new LogoutService(SerializerOptions, token!); return InvokeSync(logout); } @@ -454,8 +453,8 @@ public ContentstackResponse Logout(string? authtoken = null) /// The Task. public Task LogoutAsync(string? authtoken = null) { - string token = authtoken ?? contentstackOptions.Authtoken; - LogoutService logout = new LogoutService(SerializerOptions, token); + string? token = authtoken ?? contentstackOptions.Authtoken; + LogoutService logout = new LogoutService(SerializerOptions, token!); return InvokeAsync(logout); } diff --git a/Contentstack.Management.Core/ContentstackClientOptions.cs b/Contentstack.Management.Core/ContentstackClientOptions.cs index f5946ce..9447bb8 100644 --- a/Contentstack.Management.Core/ContentstackClientOptions.cs +++ b/Contentstack.Management.Core/ContentstackClientOptions.cs @@ -15,7 +15,7 @@ public class ContentstackClientOptions /// /// An Authtoken is a read-write token used to make authorized CMA requests. /// - public string Authtoken { get; set; } + public string? Authtoken { get; set; } /// /// Indicates whether the current authtoken is an OAuth Bearer token. @@ -32,7 +32,7 @@ public class ContentstackClientOptions /// /// The EarlyAccess used to set early access headers for the Contentstack Management API. /// - public string[] EarlyAccess { get; set; } + public string[]? EarlyAccess { get; set; } /// /// The Host used to set host url for the Contentstack Management API. @@ -86,7 +86,7 @@ public class ContentstackClientOptions /// The retry policy which specifies when /// a retry should be performed. /// - public RetryPolicy RetryPolicy { get; set; } + public RetryPolicy? RetryPolicy { get; set; } /// /// When set to true, the client will retry on network failures. @@ -139,12 +139,12 @@ public class ContentstackClientOptions /// /// Options for retry delay calculation. /// - public RetryDelayOptions RetryDelayOptions { get; set; } + public RetryDelayOptions? RetryDelayOptions { get; set; } /// /// Host for the Proxy. /// - public string ProxyHost { get; set; } + public string? ProxyHost { get; set; } /// /// Port for the Proxy. @@ -154,18 +154,18 @@ public class ContentstackClientOptions /// /// Credentials to use with a proxy. /// - public ICredentials ProxyCredentials { get; set; } + public ICredentials? ProxyCredentials { get; set; } /// /// Returns a WebProxy instance configured to match the proxy settings /// in the configuration. /// /// - public IWebProxy GetWebProxy() + public IWebProxy? GetWebProxy() { const string httpPrefix = "http://"; - WebProxy webProxy = null; + WebProxy? webProxy = null; if (!string.IsNullOrEmpty(ProxyHost) && ProxyPort != -1) { var host = ProxyHost.StartsWith(httpPrefix, StringComparison.OrdinalIgnoreCase) diff --git a/Contentstack.Management.Core/ContentstackResponse.cs b/Contentstack.Management.Core/ContentstackResponse.cs index 607a7a9..5d192c4 100644 --- a/Contentstack.Management.Core/ContentstackResponse.cs +++ b/Contentstack.Management.Core/ContentstackResponse.cs @@ -17,9 +17,9 @@ public class ContentstackResponse : IResponse, IDisposable { private bool _disposed = false; - string[] _headerNames; - Dictionary _headers; - HashSet _headerNamesSet; + string[] _headerNames = null!; + Dictionary _headers = null!; + HashSet _headerNamesSet = null!; private readonly HttpResponseMessage _response; private readonly JsonSerializerOptions _serializerOptions; @@ -32,7 +32,7 @@ public class ContentstackResponse : IResponse, IDisposable /// /// Gets the property ContentType. /// - public string ContentType { get; private set; } + public string? ContentType { get; private set; } /// /// The HTTP status code from the HTTP response. @@ -70,7 +70,7 @@ public string[] GetHeaderNames() /// The string public string GetHeaderValue(string headerName) { - string headerValue; + string? headerValue; if (_headers.TryGetValue(headerName, out headerValue)) return headerValue; @@ -89,9 +89,9 @@ public bool IsHeaderPresent(string headerName) #endregion #region Private - private string GetFirstHeaderValue(HttpHeaders headers, string key) + private string? GetFirstHeaderValue(HttpHeaders headers, string key) { - IEnumerable headerValues = null; + IEnumerable? headerValues = null; if (headers.TryGetValues(key, out headerValues)) return headerValues.FirstOrDefault(); @@ -107,7 +107,7 @@ private void CopyHeaderValues(HttpResponseMessage response) { headerNames.Add(key); var headerValue = GetFirstHeaderValue(response.Headers, key); - _headers.Add(key, headerValue); + _headers.Add(key, headerValue ?? string.Empty); } if (response.Content != null) @@ -118,7 +118,7 @@ private void CopyHeaderValues(HttpResponseMessage response) { headerNames.Add(key); var headerValue = GetFirstHeaderValue(response.Content.Headers, key); - _headers.Add(key, headerValue); + _headers.Add(key, headerValue ?? string.Empty); } } } @@ -138,7 +138,7 @@ internal ContentstackResponse(HttpResponseMessage response, JsonSerializerOption if (response.Content.Headers.ContentType != null) { - this.ContentType = response.Content.Headers.ContentType.MediaType; + this.ContentType = response.Content.Headers.ContentType.MediaType ?? string.Empty; } CopyHeaderValues(response); @@ -180,7 +180,7 @@ public string OpenResponse() /// /// The type to serialize the response into. /// - public TResponse OpenTResponse() + public TResponse? OpenTResponse() { ThrowIfDisposed(); string json = OpenResponse(); diff --git a/Contentstack.Management.Core/Exceptions/ContentstackErrorException.cs b/Contentstack.Management.Core/Exceptions/ContentstackErrorException.cs index 63d1f5d..3064656 100644 --- a/Contentstack.Management.Core/Exceptions/ContentstackErrorException.cs +++ b/Contentstack.Management.Core/Exceptions/ContentstackErrorException.cs @@ -26,17 +26,17 @@ public class ContentstackErrorException: Exception /// /// This is http response Header of REST request to Contentstack. /// - public HttpResponseHeaders Header { get; set; } + public HttpResponseHeaders? Header { get; set; } /// /// This is http response phrase code of REST request to Contentstack. /// - public string ReasonPhrase { get; set; } + public string? ReasonPhrase { get; set; } /// /// This is error message. /// - public new string Message { get; set; } + public new string? Message { get; set; } /// /// This is error message. @@ -66,7 +66,7 @@ public string ErrorMessage /// Set of errors in detail. /// [JsonPropertyName("errors")] - public Dictionary Errors { get; set; } + public Dictionary? Errors { get; set; } /// /// Number of retry attempts made before this exception was thrown. @@ -76,7 +76,7 @@ public string ErrorMessage /// /// The original exception that caused this error, if this is a network error wrapped in an HTTP exception. /// - public Exception OriginalError { get; set; } + public Exception? OriginalError { get; set; } /// /// Indicates whether this error originated from a network failure. @@ -86,12 +86,12 @@ public string ErrorMessage public static ContentstackErrorException CreateException(HttpResponseMessage response) { var stringResponse = response.Content.ReadAsStringAsync().Result; - ContentstackErrorException exception = null; + ContentstackErrorException? exception = null; if (!string.IsNullOrEmpty(stringResponse)) { try { - exception = JsonSerializer.Deserialize(stringResponse); + exception = JsonSerializer.Deserialize(stringResponse) ?? new ContentstackErrorException(); } catch (JsonException) { @@ -131,7 +131,7 @@ public static ContentstackErrorException CreateException(HttpResponseMessage res exception = new ContentstackErrorException(); } - exception.StatusCode = response.StatusCode; + exception!.StatusCode = response.StatusCode; exception.Header = response.Headers; exception.ReasonPhrase = response.ReasonPhrase; return exception; diff --git a/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs b/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs index 8a7950d..fb06075 100644 --- a/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs +++ b/Contentstack.Management.Core/Http/ContentstackHttpRequest.cs @@ -33,7 +33,7 @@ public HttpMethod Method /// /// The request URI. /// - public Uri RequestUri { get; set; } + public Uri RequestUri { get; set; } = null!; /// /// The underlying HttpClient @@ -106,7 +106,7 @@ public IResponse GetResponse() } catch (AggregateException e) { - throw e.InnerException; + throw e.InnerException!; } } @@ -171,7 +171,7 @@ public void WriteToRequestBody(HttpContent content) /// Gets a handle to the request content. /// /// The . - public HttpContent GetRequestContent() + public HttpContent? GetRequestContent() { ThrowIfDisposed(); return System.Threading.Tasks.Task.FromResult(_request.Content).Result; @@ -191,7 +191,7 @@ public void WriteToRequestBody(HttpContent content, IDictionary private void WriteContentHeaders(IDictionary contentHeaders) { - _request.Content.Headers.ContentType = + _request.Content!.Headers.ContentType = MediaTypeHeaderValue.Parse(contentHeaders[HeadersKey.ContentTypeHeader]); } } diff --git a/Contentstack.Management.Core/Http/IHttpRequest.cs b/Contentstack.Management.Core/Http/IHttpRequest.cs index fce7d19..6a79074 100644 --- a/Contentstack.Management.Core/Http/IHttpRequest.cs +++ b/Contentstack.Management.Core/Http/IHttpRequest.cs @@ -26,7 +26,7 @@ public interface IHttpRequest: IDisposable /// Returns the HTTP response. /// /// - HttpContent GetRequestContent(); + HttpContent? GetRequestContent(); /// /// Returns the HTTP response. diff --git a/Contentstack.Management.Core/IResponse.cs b/Contentstack.Management.Core/IResponse.cs index 41ecff2..bb80386 100644 --- a/Contentstack.Management.Core/IResponse.cs +++ b/Contentstack.Management.Core/IResponse.cs @@ -11,7 +11,7 @@ namespace Contentstack.Management.Core public interface IResponse { long ContentLength { get; } - string ContentType { get; } + string? ContentType { get; } HttpStatusCode StatusCode { get; } bool IsSuccessStatusCode { get; } string[] GetHeaderNames(); @@ -28,6 +28,6 @@ public interface IResponse [Obsolete("Use OpenJsonObjectResponse() instead. This method will be removed in future versions.")] JObject OpenJObjectResponse(); - TResponse OpenTResponse(); + TResponse? OpenTResponse(); } } diff --git a/Contentstack.Management.Core/Log/LogConsole.cs b/Contentstack.Management.Core/Log/LogConsole.cs index 660a2b3..d2a6cf6 100644 --- a/Contentstack.Management.Core/Log/LogConsole.cs +++ b/Contentstack.Management.Core/Log/LogConsole.cs @@ -44,9 +44,9 @@ public override void InfoFormat(string message, params object[] arguments) this.Log(LogLevel.Info, string.Format(message, arguments), null); } - private void Log(LogLevel logLevel, string message, Exception ex) + private void Log(LogLevel logLevel, string message, Exception? ex) { - string formatted = null; + string? formatted = null; string loglevelString = logLevel.ToString().ToUpper(); string dt = DateTime.UtcNow.ToLocalTime().ToString(); diff --git a/Contentstack.Management.Core/Models/Asset.cs b/Contentstack.Management.Core/Models/Asset.cs index 10d0426..8ddc7b8 100644 --- a/Contentstack.Management.Core/Models/Asset.cs +++ b/Contentstack.Management.Core/Models/Asset.cs @@ -8,10 +8,10 @@ namespace Contentstack.Management.Core.Models { public class Asset { - internal Stack stack; - public string Uid { get; set; } + internal Stack stack = null!; + public string? Uid { get; set; } - internal string resourcePath; + internal string resourcePath = null!; internal Asset(Stack stack, string? uid = null) { diff --git a/Contentstack.Management.Core/Models/AssetModel.cs b/Contentstack.Management.Core/Models/AssetModel.cs index bc96b09..3e946e7 100644 --- a/Contentstack.Management.Core/Models/AssetModel.cs +++ b/Contentstack.Management.Core/Models/AssetModel.cs @@ -8,25 +8,25 @@ namespace Contentstack.Management.Core.Models { public class AssetModel: IUploadInterface { - public string Title { get; set; } - public string Description { get; set; } - public string ParentUID { get; set; } - public string Tags { get; set; } - public string FileName { get; set; } - public string ContentType { get; set; } + public string? Title { get; set; } + public string? Description { get; set; } + public string? ParentUID { get; set; } + public string? Tags { get; set; } + public string FileName { get; set; } = null!; + public string ContentType { get; set; } = null!; - internal ByteArrayContent byteArray; + internal ByteArrayContent byteArray = null!; - public AssetModel(string fileName, string filePath, string contentType, string title = null, string description = null, string parentUID = null, string tags = null): + public AssetModel(string fileName, string filePath, string contentType, string? title = null, string? description = null, string? parentUID = null, string? tags = null): this(fileName, File.OpenRead(filePath), contentType, title, description, parentUID, tags){ } - public AssetModel(string fileName, Stream stream, string contentType, string title = null, string description = null, string parentUID = null, string tags = null): + public AssetModel(string fileName, Stream stream, string contentType, string? title = null, string? description = null, string? parentUID = null, string? tags = null): this(fileName, getBytes(stream), contentType, title, description, parentUID, tags){ } - public AssetModel(string fileName, byte[] bytes, string contentType, string title = null, string description = null, string parentUID = null, string tags = null) : + public AssetModel(string fileName, byte[] bytes, string contentType, string? title = null, string? description = null, string? parentUID = null, string? tags = null) : this(fileName, getByteArray(bytes), contentType, title, description, parentUID, tags){ } - public AssetModel(string fileName, ByteArrayContent byteArray, string contentType, string title = null, string description = null, string parentUID = null, string tags = null) + public AssetModel(string fileName, ByteArrayContent byteArray, string contentType, string? title = null, string? description = null, string? parentUID = null, string? tags = null) { if (fileName == null) { @@ -50,7 +50,7 @@ public AssetModel(string fileName, ByteArrayContent byteArray, string contentTyp static private byte[] getBytes(Stream stream) { byte[] bytes = new byte[stream.Length]; - stream.Read(bytes, 0, (int)stream.Length); + stream.ReadExactly(bytes, 0, (int)stream.Length); return bytes; } diff --git a/Contentstack.Management.Core/Models/BaseModel.cs b/Contentstack.Management.Core/Models/BaseModel.cs index 7be25d7..f537206 100644 --- a/Contentstack.Management.Core/Models/BaseModel.cs +++ b/Contentstack.Management.Core/Models/BaseModel.cs @@ -8,11 +8,11 @@ namespace Contentstack.Management.Core.Models { public class BaseModel { - internal Stack stack; - internal string fieldName; - internal string resourcePath; + internal Stack stack = null!; + internal string fieldName = null!; + internal string resourcePath = null!; - public string Uid { get; set; } + public string? Uid { get; set; } public BaseModel(Stack stack, string fieldName, string? uid = null) diff --git a/Contentstack.Management.Core/Models/BulkOperationModels.cs b/Contentstack.Management.Core/Models/BulkOperationModels.cs index 5b14e62..b5653f3 100644 --- a/Contentstack.Management.Core/Models/BulkOperationModels.cs +++ b/Contentstack.Management.Core/Models/BulkOperationModels.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Newtonsoft.Json; +using System.Text.Json.Serialization; namespace Contentstack.Management.Core.Models { @@ -11,62 +11,50 @@ public class BulkPublishDetails /// /// Gets or sets the list of entries to publish/unpublish. /// - [JsonProperty(propertyName: "entries")] - public List Entries { get; set; } + [JsonPropertyName("entries")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Entries { get; set; } /// /// Gets or sets the list of assets to publish/unpublish. /// - [JsonProperty(propertyName: "assets")] - public List Assets { get; set; } + [JsonPropertyName("assets")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Assets { get; set; } /// /// Gets or sets the list of locales. /// - [JsonProperty(propertyName: "locales")] - public List Locales { get; set; } = new List(); + [JsonPropertyName("locales")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Locales { get; set; } /// /// Gets or sets the list of environments. /// - [JsonProperty(propertyName: "environments")] - public List Environments { get; set; } = new List(); + [JsonPropertyName("environments")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Environments { get; set; } /// /// Gets or sets the rules for the bulk operation. /// - [JsonProperty(propertyName: "rules")] - public BulkPublishRules Rules { get; set; } + [JsonPropertyName("rules")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public BulkPublishRules? Rules { get; set; } /// /// Gets or sets the scheduled time for the operation. /// - [JsonProperty(propertyName: "scheduled_at")] - public string ScheduledAt { get; set; } + [JsonPropertyName("scheduled_at")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? ScheduledAt { get; set; } /// /// Gets or sets whether to publish with reference. /// - [JsonProperty(propertyName: "publish_with_reference")] + [JsonPropertyName("publish_with_reference")] public bool PublishWithReference { get; set; } - - /// - /// Determines whether to serialize the Entries property. - /// - /// True if Entries should be serialized, false otherwise. - public bool ShouldSerializeEntries() - { - return Entries != null && Entries.Count > 0; - } - - /// - /// Determines whether to serialize the Assets property. - /// - /// True if Assets should be serialized, false otherwise. - public bool ShouldSerializeAssets() - { - return Assets != null && Assets.Count > 0; - } } /// @@ -77,26 +65,26 @@ public class BulkPublishEntry /// /// Gets or sets the entry UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the content type. /// - [JsonProperty(propertyName: "content_type")] - public string ContentType { get; set; } + [JsonPropertyName("content_type")] + public string? ContentType { get; set; } /// /// Gets or sets the version number. /// - [JsonProperty(propertyName: "version")] + [JsonPropertyName("version")] public int Version { get; set; } /// /// Gets or sets the locale. /// - [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + [JsonPropertyName("locale")] + public string? Locale { get; set; } } /// @@ -107,8 +95,8 @@ public class BulkPublishRules /// /// Gets or sets the approvals setting. /// - [JsonProperty(propertyName: "approvals")] - public string Approvals { get; set; } + [JsonPropertyName("approvals")] + public string? Approvals { get; set; } } /// @@ -119,8 +107,8 @@ public class BulkPublishAsset /// /// Gets or sets the asset UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } } /// @@ -131,32 +119,16 @@ public class BulkDeleteDetails /// /// Gets or sets the list of entries to delete. /// - [JsonProperty(propertyName: "entries")] - public List Entries { get; set; } + [JsonPropertyName("entries")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Entries { get; set; } /// /// Gets or sets the list of assets to delete. /// - [JsonProperty(propertyName: "assets")] - public List Assets { get; set; } - - /// - /// Determines whether to serialize the Entries property. - /// - /// True if Entries should be serialized, false otherwise. - public bool ShouldSerializeEntries() - { - return Entries != null && Entries.Count > 0; - } - - /// - /// Determines whether to serialize the Assets property. - /// - /// True if Assets should be serialized, false otherwise. - public bool ShouldSerializeAssets() - { - return Assets != null && Assets.Count > 0; - } + [JsonPropertyName("assets")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Assets { get; set; } } /// @@ -167,20 +139,20 @@ public class BulkDeleteEntry /// /// Gets or sets the entry UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the content type. /// - [JsonProperty(propertyName: "content_type")] - public string ContentType { get; set; } + [JsonPropertyName("content_type")] + public string? ContentType { get; set; } /// /// Gets or sets the locale. /// - [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + [JsonPropertyName("locale")] + public string? Locale { get; set; } } /// @@ -191,8 +163,8 @@ public class BulkDeleteAsset /// /// Gets or sets the asset UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } } /// @@ -203,23 +175,16 @@ public class BulkWorkflowUpdateBody /// /// Gets or sets the list of entries to update. /// - [JsonProperty(propertyName: "entries")] - public List Entries { get; set; } + [JsonPropertyName("entries")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Entries { get; set; } /// /// Gets or sets the workflow stage information. /// - [JsonProperty(propertyName: "workflow")] - public BulkWorkflowStage Workflow { get; set; } - - /// - /// Determines whether to serialize the Entries property. - /// - /// True if Entries should be serialized, false otherwise. - public bool ShouldSerializeEntries() - { - return Entries != null && Entries.Count > 0; - } + [JsonPropertyName("workflow")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public BulkWorkflowStage? Workflow { get; set; } } /// @@ -230,20 +195,20 @@ public class BulkWorkflowEntry /// /// Gets or sets the entry UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the content type. /// - [JsonProperty(propertyName: "content_type")] - public string ContentType { get; set; } + [JsonPropertyName("content_type")] + public string? ContentType { get; set; } /// /// Gets or sets the locale. /// - [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + [JsonPropertyName("locale")] + public string? Locale { get; set; } } /// @@ -254,56 +219,42 @@ public class BulkWorkflowStage /// /// Gets or sets the workflow stage UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the comment. /// - [JsonProperty(propertyName: "comment")] - public string Comment { get; set; } + [JsonPropertyName("comment")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Comment { get; set; } /// /// Gets or sets the due date. /// - [JsonProperty(propertyName: "due_date")] - public string DueDate { get; set; } + [JsonPropertyName("due_date")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? DueDate { get; set; } /// /// Gets or sets whether to notify. /// - [JsonProperty(propertyName: "notify")] + [JsonPropertyName("notify")] public bool Notify { get; set; } /// /// Gets or sets the list of assigned users. /// - [JsonProperty(propertyName: "assigned_to")] - public List AssignedTo { get; set; } + [JsonPropertyName("assigned_to")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? AssignedTo { get; set; } /// /// Gets or sets the list of assigned roles. /// - [JsonProperty(propertyName: "assigned_by_roles")] - public List AssignedByRoles { get; set; } - - /// - /// Determines whether to serialize the AssignedTo property. - /// - /// True if AssignedTo should be serialized, false otherwise. - public bool ShouldSerializeAssignedTo() - { - return AssignedTo != null && AssignedTo.Count > 0; - } - - /// - /// Determines whether to serialize the AssignedByRoles property. - /// - /// True if AssignedByRoles should be serialized, false otherwise. - public bool ShouldSerializeAssignedByRoles() - { - return AssignedByRoles != null && AssignedByRoles.Count > 0; - } + [JsonPropertyName("assigned_by_roles")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? AssignedByRoles { get; set; } } /// @@ -314,20 +265,20 @@ public class BulkWorkflowUser /// /// Gets or sets the user UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the user name. /// - [JsonProperty(propertyName: "name")] - public string Name { get; set; } + [JsonPropertyName("name")] + public string? Name { get; set; } /// /// Gets or sets the user email. /// - [JsonProperty(propertyName: "email")] - public string Email { get; set; } + [JsonPropertyName("email")] + public string? Email { get; set; } } /// @@ -338,14 +289,14 @@ public class BulkWorkflowRole /// /// Gets or sets the role UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the role name. /// - [JsonProperty(propertyName: "name")] - public string Name { get; set; } + [JsonPropertyName("name")] + public string? Name { get; set; } } /// @@ -357,82 +308,42 @@ public class BulkAddItemsData /// /// Gets or sets the list of items to add/update. /// - [JsonProperty(propertyName: "items")] - public List Items { get; set; } + [JsonPropertyName("items")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Items { get; set; } /// /// Gets or sets the release UID for deployment operations. /// When specified, this enables release deployment mode (like JavaScript SDK). /// - [JsonProperty(propertyName: "release")] - public string Release { get; set; } + [JsonPropertyName("release")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Release { get; set; } /// /// Gets or sets the action to perform during deployment (publish, unpublish, etc.). /// Only used when Release is specified. /// - [JsonProperty(propertyName: "action")] - public string Action { get; set; } + [JsonPropertyName("action")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Action { get; set; } /// /// Gets or sets the list of locales for deployment. /// Only used when Release is specified. /// - [JsonProperty(propertyName: "locale")] - public List Locale { get; set; } + [JsonPropertyName("locale")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Locale { get; set; } /// /// Gets or sets the reference flag for deployment. /// Only used when Release is specified. /// - [JsonProperty(propertyName: "reference")] + [JsonPropertyName("reference")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public bool? Reference { get; set; } - /// - /// Determines whether to serialize the Items property. - /// - /// True if Items should be serialized, false otherwise. - public bool ShouldSerializeItems() - { - return Items != null && Items.Count > 0; - } - - /// - /// Determines whether to serialize the Release property. - /// - /// True if Release should be serialized, false otherwise. - public bool ShouldSerializeRelease() - { - return !string.IsNullOrEmpty(Release); - } - - /// - /// Determines whether to serialize the Action property. - /// - /// True if Action should be serialized, false otherwise. - public bool ShouldSerializeAction() - { - return !string.IsNullOrEmpty(Action); - } - - /// - /// Determines whether to serialize the Locale property. - /// - /// True if Locale should be serialized, false otherwise. - public bool ShouldSerializeLocale() - { - return Locale != null && Locale.Count > 0; - } - - /// - /// Determines whether to serialize the Reference property. - /// - /// True if Reference should be serialized, false otherwise. - public bool ShouldSerializeReference() - { - return Reference.HasValue; - } - /// /// Gets a value indicating whether this instance is configured for release deployment mode. /// @@ -452,78 +363,47 @@ public class BulkAddItem /// /// Gets or sets the item UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the content type. /// - [JsonProperty(propertyName: "content_type")] - public string ContentType { get; set; } + [JsonPropertyName("content_type")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? ContentType { get; set; } /// /// Gets or sets the content type UID for release deployment mode. /// This is an alias for ContentType with a different JSON property name. /// - [JsonProperty(propertyName: "content_type_uid")] - public string ContentTypeUid { get; set; } + [JsonPropertyName("content_type_uid")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? ContentTypeUid { get; set; } /// /// Gets or sets the version number for release deployment mode. /// Only used in enhanced release deployment operations. /// - [JsonProperty(propertyName: "version")] + [JsonPropertyName("version")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public int? Version { get; set; } /// /// Gets or sets the locale for release deployment mode. /// Only used in enhanced release deployment operations. /// - [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + [JsonPropertyName("locale")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Locale { get; set; } /// /// Gets or sets the title for release deployment mode. /// Only used in enhanced release deployment operations. /// - [JsonProperty(propertyName: "title")] - public string Title { get; set; } - - /// - /// Determines whether to serialize the ContentTypeUid property. - /// - /// True if ContentTypeUid should be serialized, false otherwise. - public bool ShouldSerializeContentTypeUid() - { - return !string.IsNullOrEmpty(ContentTypeUid); - } - - /// - /// Determines whether to serialize the Version property. - /// - /// True if Version should be serialized, false otherwise. - public bool ShouldSerializeVersion() - { - return Version.HasValue; - } - - /// - /// Determines whether to serialize the Locale property. - /// - /// True if Locale should be serialized, false otherwise. - public bool ShouldSerializeLocale() - { - return !string.IsNullOrEmpty(Locale); - } - - /// - /// Determines whether to serialize the Title property. - /// - /// True if Title should be serialized, false otherwise. - public bool ShouldSerializeTitle() - { - return !string.IsNullOrEmpty(Title); - } + [JsonPropertyName("title")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public string? Title { get; set; } } /// @@ -534,50 +414,34 @@ public class BulkReleaseItemsData /// /// Gets or sets the release UID. /// - [JsonProperty(propertyName: "release")] - public string Release { get; set; } + [JsonPropertyName("release")] + public string? Release { get; set; } /// /// Gets or sets the action to perform (publish, unpublish, etc.). /// - [JsonProperty(propertyName: "action")] - public string Action { get; set; } + [JsonPropertyName("action")] + public string? Action { get; set; } /// /// Gets or sets the list of locales. /// - [JsonProperty(propertyName: "locale")] - public List Locale { get; set; } + [JsonPropertyName("locale")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Locale { get; set; } /// /// Gets or sets the reference flag. /// - [JsonProperty(propertyName: "reference")] + [JsonPropertyName("reference")] public bool Reference { get; set; } /// /// Gets or sets the list of items to process. /// - [JsonProperty(propertyName: "items")] - public List Items { get; set; } - - /// - /// Determines whether to serialize the Locale property. - /// - /// True if Locale should be serialized, false otherwise. - public bool ShouldSerializeLocale() - { - return Locale != null && Locale.Count > 0; - } - - /// - /// Determines whether to serialize the Items property. - /// - /// True if Items should be serialized, false otherwise. - public bool ShouldSerializeItems() - { - return Items != null && Items.Count > 0; - } + [JsonPropertyName("items")] + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + public List? Items { get; set; } } /// @@ -588,31 +452,31 @@ public class BulkReleaseItem /// /// Gets or sets the content type UID. /// - [JsonProperty(propertyName: "content_type_uid")] - public string ContentTypeUid { get; set; } + [JsonPropertyName("content_type_uid")] + public string? ContentTypeUid { get; set; } /// /// Gets or sets the item UID. /// - [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + [JsonPropertyName("uid")] + public string? Uid { get; set; } /// /// Gets or sets the version number. /// - [JsonProperty(propertyName: "version")] + [JsonPropertyName("version")] public int Version { get; set; } /// /// Gets or sets the locale. /// - [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + [JsonPropertyName("locale")] + public string? Locale { get; set; } /// /// Gets or sets the title. /// - [JsonProperty(propertyName: "title")] - public string Title { get; set; } + [JsonPropertyName("title")] + public string? Title { get; set; } } -} \ No newline at end of file +} diff --git a/Contentstack.Management.Core/Models/ContentType.cs b/Contentstack.Management.Core/Models/ContentType.cs index 2d98cc3..7128520 100644 --- a/Contentstack.Management.Core/Models/ContentType.cs +++ b/Contentstack.Management.Core/Models/ContentType.cs @@ -5,7 +5,7 @@ namespace Contentstack.Management.Core.Models { public class ContentType: BaseModel { - internal ContentType(Stack stack, string uid) + internal ContentType(Stack stack, string? uid) : base(stack, "content_type", uid) { resourcePath = uid == null ? "/content_types" : $"/content_types/{uid}"; @@ -171,7 +171,7 @@ public override Task DeleteAsync(ParameterCollection? coll /// /// Optional entry uid for performing entry specific operation /// - public Entry Entry(string uid = null) + public Entry Entry(string? uid = null) { ThrowIfUidEmpty(); return new Entry(stack, Uid, uid); diff --git a/Contentstack.Management.Core/Models/Entry.cs b/Contentstack.Management.Core/Models/Entry.cs index 1749890..f78584e 100644 --- a/Contentstack.Management.Core/Models/Entry.cs +++ b/Contentstack.Management.Core/Models/Entry.cs @@ -11,12 +11,12 @@ namespace Contentstack.Management.Core.Models { public class Entry: BaseModel { - internal string contentTypeUid; + internal string contentTypeUid = null!; - internal Entry(Stack stack, string contentTyppe, string uid) + internal Entry(Stack stack, string? contentTyppe, string? uid) : base(stack, "entry", uid) { - contentTypeUid = contentTyppe; + contentTypeUid = contentTyppe!; resourcePath = uid == null ? $"/content_types/{contentTyppe}/entries" : $"/content_types/{contentTyppe}/entries/{uid}"; } @@ -41,7 +41,7 @@ public Query Query() /// /// The UID of the variant. /// The - public EntryVariant Variant(string uid = null) + public EntryVariant Variant(string? uid = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -77,7 +77,7 @@ public Version Version(int? versionNumber = null) /// /// IEntry for createing Entry. /// The . - public override ContentstackResponse Create(IEntry model, ParameterCollection collection = null) + public override ContentstackResponse Create(IEntry model, ParameterCollection? collection = null) { return base.Create(model, collection); } @@ -94,7 +94,7 @@ public override ContentstackResponse Create(IEntry model, ParameterCollection co /// /// IEntry for createing Entry. /// The Task. - public override Task CreateAsync(IEntry model, ParameterCollection collection = null) + public override Task CreateAsync(IEntry model, ParameterCollection? collection = null) { return base.CreateAsync(model, collection); } @@ -111,7 +111,7 @@ public override Task CreateAsync(IEntry model, ParameterCo /// /// IEntry for updating entry. /// The . - public override ContentstackResponse Update(IEntry model, ParameterCollection collection = null) + public override ContentstackResponse Update(IEntry model, ParameterCollection? collection = null) { return base.Update(model, collection); } @@ -128,7 +128,7 @@ public override ContentstackResponse Update(IEntry model, ParameterCollection co /// /// IEntry for updating entry. /// The Task. - public override Task UpdateAsync(IEntry model, ParameterCollection collection = null) + public override Task UpdateAsync(IEntry model, ParameterCollection? collection = null) { return base.UpdateAsync(model, collection); } @@ -143,7 +143,7 @@ public override Task UpdateAsync(IEntry model, ParameterCo /// /// /// The . - public override ContentstackResponse Fetch(ParameterCollection collection = null) + public override ContentstackResponse Fetch(ParameterCollection? collection = null) { return base.Fetch(collection); } @@ -158,7 +158,7 @@ public override ContentstackResponse Fetch(ParameterCollection collection = null /// /// /// The Task. - public override Task FetchAsync(ParameterCollection collection = null) + public override Task FetchAsync(ParameterCollection? collection = null) { return base.FetchAsync(collection); } @@ -173,7 +173,7 @@ public override Task FetchAsync(ParameterCollection collec /// /// /// The . - public override ContentstackResponse Delete(ParameterCollection collection = null) + public override ContentstackResponse Delete(ParameterCollection? collection = null) { return base.Delete(collection); } @@ -188,7 +188,7 @@ public override ContentstackResponse Delete(ParameterCollection collection = nul /// /// /// The Task. - public override Task DeleteAsync(ParameterCollection collection = null) + public override Task DeleteAsync(ParameterCollection? collection = null) { return base.DeleteAsync(collection); } @@ -389,7 +389,7 @@ public Task LocalesAsync() /// /// /// The . - public ContentstackResponse References(ParameterCollection collection = null) + public ContentstackResponse References(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -408,7 +408,7 @@ public ContentstackResponse References(ParameterCollection collection = null) /// /// /// The Task - public Task ReferencesAsync(ParameterCollection collection = null) + public Task ReferencesAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -429,7 +429,7 @@ public Task ReferencesAsync(ParameterCollection collection /// Publish/Unpublish details. /// Locale for entry to be publish /// The . - public virtual ContentstackResponse Publish(PublishUnpublishDetails details, string locale = null, string apiVersion = null) + public virtual ContentstackResponse Publish(PublishUnpublishDetails details, string? locale = null, string? apiVersion = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -450,7 +450,7 @@ public virtual ContentstackResponse Publish(PublishUnpublishDetails details, str /// Publish/Unpublish details. /// Locale for entry to be publish /// The Task - public virtual Task PublishAsync(PublishUnpublishDetails details, string locale = null, string apiVersion = null) + public virtual Task PublishAsync(PublishUnpublishDetails details, string? locale = null, string? apiVersion = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -471,7 +471,7 @@ public virtual Task PublishAsync(PublishUnpublishDetails d /// Publish/Unpublish details. /// Locale for entry to be publish /// The . - public virtual ContentstackResponse Unpublish(PublishUnpublishDetails details, string locale = null, string apiVersion = null) + public virtual ContentstackResponse Unpublish(PublishUnpublishDetails details, string? locale = null, string? apiVersion = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -492,7 +492,7 @@ public virtual ContentstackResponse Unpublish(PublishUnpublishDetails details, s /// Publish/Unpublish details. /// Locale for entry to be publish /// The Task - public virtual Task UnpublishAsync(PublishUnpublishDetails details, string locale = null, string apiVersion = null) + public virtual Task UnpublishAsync(PublishUnpublishDetails details, string? locale = null, string? apiVersion = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -514,7 +514,7 @@ public virtual Task UnpublishAsync(PublishUnpublishDetails /// Path to file you want to import /// Query parameter. /// The . - public ContentstackResponse Import(string filePath, ParameterCollection collection = null) + public ContentstackResponse Import(string filePath, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); @@ -538,7 +538,7 @@ public ContentstackResponse Import(string filePath, ParameterCollection collecti /// Path to file you want to import /// Query parameter. /// The Task - public Task ImportAsync(string filePath, ParameterCollection collection = null) + public Task ImportAsync(string filePath, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -561,7 +561,7 @@ public Task ImportAsync(string filePath, ParameterCollecti /// Path to file you want to export entry. /// Query parameter. /// The . - public ContentstackResponse Export(string filePath, ParameterCollection collection = null) + public ContentstackResponse Export(string filePath, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -597,7 +597,7 @@ public ContentstackResponse Export(string filePath, ParameterCollection collecti /// object. /// Query parameter. /// The . - public ContentstackResponse SetWorkflow(EntryWorkflowStage model, ParameterCollection collection = null) + public ContentstackResponse SetWorkflow(EntryWorkflowStage model, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -622,7 +622,7 @@ public ContentstackResponse SetWorkflow(EntryWorkflowStage model, ParameterColle /// object. /// Query parameter. /// The Task. - public Task SetWorkflowAsync(EntryWorkflowStage model, ParameterCollection collection = null) + public Task SetWorkflowAsync(EntryWorkflowStage model, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -647,7 +647,7 @@ public Task SetWorkflowAsync(EntryWorkflowStage model, Par /// object. /// Query parameter. /// - public ContentstackResponse PublishRequest(EntryPublishAction publishAction, ParameterCollection collection = null) + public ContentstackResponse PublishRequest(EntryPublishAction publishAction, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -671,7 +671,7 @@ public ContentstackResponse PublishRequest(EntryPublishAction publishAction, Par /// object. /// Query parameter. /// - public Task PublishRequestAsync(EntryPublishAction publishAction, ParameterCollection collection = null) + public Task PublishRequestAsync(EntryPublishAction publishAction, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); diff --git a/Contentstack.Management.Core/Models/EntryVariant.cs b/Contentstack.Management.Core/Models/EntryVariant.cs index dc125d2..dd73957 100644 --- a/Contentstack.Management.Core/Models/EntryVariant.cs +++ b/Contentstack.Management.Core/Models/EntryVariant.cs @@ -11,16 +11,16 @@ namespace Contentstack.Management.Core.Models /// public class EntryVariant { - internal Stack stack; - internal string resourcePath; + internal Stack stack = null!; + internal string resourcePath = null!; /// /// Gets the UID of the variant. /// - public string Uid { get; private set; } + public string? Uid { get; private set; } #region Constructor - internal EntryVariant(Stack stack, string contentTypeUid, string entryUid, string uid = null) + internal EntryVariant(Stack stack, string contentTypeUid, string? entryUid, string? uid = null) { if (stack == null) { @@ -44,7 +44,7 @@ internal EntryVariant(Stack stack, string contentTypeUid, string entryUid, strin /// /// Query parameters. /// The . - public ContentstackResponse Find(ParameterCollection collection = null) + public ContentstackResponse Find(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidNotEmpty(); @@ -62,7 +62,7 @@ public ContentstackResponse Find(ParameterCollection collection = null) /// /// Query parameters. /// The Task. - public Task FindAsync(ParameterCollection collection = null) + public Task FindAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidNotEmpty(); @@ -81,7 +81,7 @@ public Task FindAsync(ParameterCollection collection = nul /// The variant entry data including _variant metadata. /// Query parameters. /// The . - public ContentstackResponse Create(object model, ParameterCollection collection = null) + public ContentstackResponse Create(object model, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -96,7 +96,7 @@ public ContentstackResponse Create(object model, ParameterCollection collection /// The variant entry data including _variant metadata. /// Query parameters. /// The Task. - public Task CreateAsync(object model, ParameterCollection collection = null) + public Task CreateAsync(object model, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -111,7 +111,7 @@ public Task CreateAsync(object model, ParameterCollection /// The variant entry data including _variant metadata. /// Query parameters. /// The . - public ContentstackResponse Update(object model, ParameterCollection collection = null) + public ContentstackResponse Update(object model, ParameterCollection? collection = null) { return Create(model, collection); } @@ -122,7 +122,7 @@ public ContentstackResponse Update(object model, ParameterCollection collection /// The variant entry data including _variant metadata. /// Query parameters. /// The Task. - public Task UpdateAsync(object model, ParameterCollection collection = null) + public Task UpdateAsync(object model, ParameterCollection? collection = null) { return CreateAsync(model, collection); } @@ -132,7 +132,7 @@ public Task UpdateAsync(object model, ParameterCollection /// /// Query parameters. /// The . - public ContentstackResponse Fetch(ParameterCollection collection = null) + public ContentstackResponse Fetch(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -146,7 +146,7 @@ public ContentstackResponse Fetch(ParameterCollection collection = null) /// /// Query parameters. /// The Task. - public Task FetchAsync(ParameterCollection collection = null) + public Task FetchAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -160,7 +160,7 @@ public Task FetchAsync(ParameterCollection collection = nu /// /// Query parameters. /// The . - public ContentstackResponse Delete(ParameterCollection collection = null) + public ContentstackResponse Delete(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -174,7 +174,7 @@ public ContentstackResponse Delete(ParameterCollection collection = null) /// /// Query parameters. /// The Task. - public Task DeleteAsync(ParameterCollection collection = null) + public Task DeleteAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); diff --git a/Contentstack.Management.Core/Models/EntryWorkflowStage.cs b/Contentstack.Management.Core/Models/EntryWorkflowStage.cs index 84700db..b623180 100644 --- a/Contentstack.Management.Core/Models/EntryWorkflowStage.cs +++ b/Contentstack.Management.Core/Models/EntryWorkflowStage.cs @@ -5,45 +5,45 @@ namespace Contentstack.Management.Core.Models public class EntryWorkflowStage { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("comment")] - public string Comment { get; set; } + public string? Comment { get; set; } [JsonPropertyName("due_date")] - public string DueDate { get; set; } + public string? DueDate { get; set; } [JsonPropertyName("notify")] public bool Notify { get; set; } = true; [JsonPropertyName("assigned_to")] - public List AssignedTo { get; set; } + public List? AssignedTo { get; set; } [JsonPropertyName("assigned_by_roles")] - public List AssignedByRoles { get; set; } + public List? AssignedByRoles { get; set; } } public class AssignToUser { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonPropertyName("email")] - public string Email { get; set; } + public string? Email { get; set; } } public class AssignByRole { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } } public class EntryPublishAction { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("action")] - public string Action { get; set; } + public string? Action { get; set; } [JsonPropertyName("comment")] - public string Comment { get; set; } + public string? Comment { get; set; } [JsonPropertyName("notify")] public bool Notify { get; set; } = true; [JsonPropertyName("status")] diff --git a/Contentstack.Management.Core/Models/Environment.cs b/Contentstack.Management.Core/Models/Environment.cs index df7ceb0..240d6a8 100644 --- a/Contentstack.Management.Core/Models/Environment.cs +++ b/Contentstack.Management.Core/Models/Environment.cs @@ -5,7 +5,7 @@ namespace Contentstack.Management.Core.Models { public class Environment : BaseModel { - internal Environment(Stack stack, string uid = null) + internal Environment(Stack stack, string? uid = null) : base(stack, "environment", uid) { resourcePath = uid == null ? "/environments" : $"/environments/{uid}"; @@ -39,7 +39,7 @@ public Query Query() /// /// Environment Model for creating Environment. /// The . - public override ContentstackResponse Create(EnvironmentModel model, ParameterCollection collection = null) + public override ContentstackResponse Create(EnvironmentModel model, ParameterCollection? collection = null) { return base.Create(model, collection); } @@ -56,7 +56,7 @@ public override ContentstackResponse Create(EnvironmentModel model, ParameterCol /// /// Environment Model for creating Environment. /// The Task. - public override Task CreateAsync(EnvironmentModel model, ParameterCollection collection = null) + public override Task CreateAsync(EnvironmentModel model, ParameterCollection? collection = null) { return base.CreateAsync(model, collection); } @@ -73,7 +73,7 @@ public override Task CreateAsync(EnvironmentModel model, P /// /// Environment Model for creating Environment. /// The . - public override ContentstackResponse Update(EnvironmentModel model, ParameterCollection collection = null) + public override ContentstackResponse Update(EnvironmentModel model, ParameterCollection? collection = null) { return base.Update(model, collection); } @@ -90,7 +90,7 @@ public override ContentstackResponse Update(EnvironmentModel model, ParameterCol /// /// Environment Model for creating Environment. /// The Task. - public override Task UpdateAsync(EnvironmentModel model, ParameterCollection collection = null) + public override Task UpdateAsync(EnvironmentModel model, ParameterCollection? collection = null) { return base.UpdateAsync(model, collection); } @@ -105,7 +105,7 @@ public override Task UpdateAsync(EnvironmentModel model, P /// /// /// The . - public override ContentstackResponse Fetch(ParameterCollection collection = null) + public override ContentstackResponse Fetch(ParameterCollection? collection = null) { return base.Fetch(collection); } @@ -120,7 +120,7 @@ public override ContentstackResponse Fetch(ParameterCollection collection = null /// /// /// The Task. - public override Task FetchAsync(ParameterCollection collection = null) + public override Task FetchAsync(ParameterCollection? collection = null) { return base.FetchAsync(collection); } @@ -135,7 +135,7 @@ public override Task FetchAsync(ParameterCollection collec /// /// /// The . - public override ContentstackResponse Delete(ParameterCollection collection = null) + public override ContentstackResponse Delete(ParameterCollection? collection = null) { return base.Delete(collection); } @@ -150,7 +150,7 @@ public override ContentstackResponse Delete(ParameterCollection collection = nul /// /// /// The Task. - public override Task DeleteAsync(ParameterCollection collection = null) + public override Task DeleteAsync(ParameterCollection? collection = null) { return base.DeleteAsync(collection); } diff --git a/Contentstack.Management.Core/Models/EnvironmentModel.cs b/Contentstack.Management.Core/Models/EnvironmentModel.cs index 460d430..f95c45e 100644 --- a/Contentstack.Management.Core/Models/EnvironmentModel.cs +++ b/Contentstack.Management.Core/Models/EnvironmentModel.cs @@ -6,13 +6,13 @@ namespace Contentstack.Management.Core.Models public class EnvironmentModel { [JsonPropertyName("name")] - public string Name { get; set; } - + public string? Name { get; set; } + [JsonPropertyName("servers")] - public List Servers { get; set; } - + public List? Servers { get; set; } + [JsonPropertyName("urls")] - public List Urls { get; set; } + public List? Urls { get; set; } [JsonPropertyName("deploy_content")] public bool DeployContent { get; set; } = true; @@ -21,15 +21,15 @@ public class EnvironmentModel public class Server { [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } } public class LocalesUrl { [JsonPropertyName("url")] - public string Url { get; set; } - + public string? Url { get; set; } + [JsonPropertyName("locale")] - public string Locale { get; set; } + public string? Locale { get; set; } } } diff --git a/Contentstack.Management.Core/Models/ExtensionModel.cs b/Contentstack.Management.Core/Models/ExtensionModel.cs index f2b2033..51f7a15 100644 --- a/Contentstack.Management.Core/Models/ExtensionModel.cs +++ b/Contentstack.Management.Core/Models/ExtensionModel.cs @@ -7,28 +7,28 @@ namespace Contentstack.Management.Core.Models public class ExtensionModel { [JsonProperty(propertyName: "title")] - public string Title { get; set; } + public string? Title { get; set; } [JsonProperty(propertyName: "data_type")] - public string DataType { get; set; } + public string? DataType { get; set; } [JsonProperty(propertyName: "tags")] - public List Tags { get; set; } + public List? Tags { get; set; } [JsonProperty(propertyName: "src")] - public string Src { get; set; } + public string? Src { get; set; } [JsonProperty(propertyName: "srcdoc")] - public string Srcdoc { get; set; } + public string? Srcdoc { get; set; } [JsonProperty(propertyName: "type")] - public string Type { get; set; } + public string? Type { get; set; } [JsonProperty(propertyName: "config")] - public string Config { get; set; } + public string? Config { get; set; } [JsonProperty(propertyName: "multiple")] public bool Multiple { get; set; } [JsonProperty(propertyName: "scope")] - public ExtensionScope Scope { get; set; } + public ExtensionScope? Scope { get; set; } } public class ExtensionScope { [JsonProperty(propertyName: "content_types")] - public List ContentTypes { get; set; } + public List? ContentTypes { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/DateField.cs b/Contentstack.Management.Core/Models/Fields/DateField.cs index 1712ed1..9842f1d 100644 --- a/Contentstack.Management.Core/Models/Fields/DateField.cs +++ b/Contentstack.Management.Core/Models/Fields/DateField.cs @@ -6,8 +6,8 @@ namespace Contentstack.Management.Core.Models.Fields public class DateField : Field { [JsonPropertyName("startDate")] - public string StartDate { get; set; } + public string? StartDate { get; set; } [JsonPropertyName("endDate")] - public string EndDate { get; set; } + public string? EndDate { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/ExtensionField.cs b/Contentstack.Management.Core/Models/Fields/ExtensionField.cs index abc4996..1c7bcb3 100644 --- a/Contentstack.Management.Core/Models/Fields/ExtensionField.cs +++ b/Contentstack.Management.Core/Models/Fields/ExtensionField.cs @@ -8,8 +8,8 @@ namespace Contentstack.Management.Core.Models.Fields public class ExtensionField : Field { [JsonPropertyName("extension_uid")] - public string extension_uid { get; set; } + public string? extension_uid { get; set; } [JsonPropertyName("config")] - public Dictionary config { get; set; } + public Dictionary? config { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/FileField.cs b/Contentstack.Management.Core/Models/Fields/FileField.cs index 6b24cb1..8acf584 100644 --- a/Contentstack.Management.Core/Models/Fields/FileField.cs +++ b/Contentstack.Management.Core/Models/Fields/FileField.cs @@ -7,7 +7,7 @@ namespace Contentstack.Management.Core.Models.Fields public class FileField : Field { [JsonPropertyName("extensions")] - public List Extensions { get; set; } + public List? Extensions { get; set; } [JsonPropertyName("max")] public int? Maxsize { get; set; } [JsonPropertyName("min")] @@ -17,18 +17,18 @@ public class FileField : Field public class ImageField : FileField { [JsonPropertyName("dimension")] - public Dimension Dimensions { get; set; } + public Dimension? Dimensions { get; set; } /// /// Allows you to enter additional data about a field. Also, you can add additional values under ‘field_metadata’. /// [JsonPropertyName("field_metadata")] - public new FileFieldMetadata FieldMetadata { get; set; } + public new FileFieldMetadata? FieldMetadata { get; set; } } public class Dimension { [JsonPropertyName("height")] - public Dictionary Height { get; set; } + public Dictionary? Height { get; set; } [JsonPropertyName("width")] - public Dictionary Width { get; set; } + public Dictionary? Width { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/GroupField.cs b/Contentstack.Management.Core/Models/Fields/GroupField.cs index 0458972..7a0c5e5 100644 --- a/Contentstack.Management.Core/Models/Fields/GroupField.cs +++ b/Contentstack.Management.Core/Models/Fields/GroupField.cs @@ -7,9 +7,9 @@ namespace Contentstack.Management.Core.Models.Fields public class GroupField : Field { [JsonPropertyName("format")] - public string Format { get; set; } + public string? Format { get; set; } [JsonPropertyName("schema")] - public List Schema { get; set; } + public List? Schema { get; set; } [JsonPropertyName("max_instance")] public int? MaxInstance { get; set; } } diff --git a/Contentstack.Management.Core/Models/Fields/ModularBlockField.cs b/Contentstack.Management.Core/Models/Fields/ModularBlockField.cs index 871d091..d91a78b 100644 --- a/Contentstack.Management.Core/Models/Fields/ModularBlockField.cs +++ b/Contentstack.Management.Core/Models/Fields/ModularBlockField.cs @@ -7,20 +7,20 @@ namespace Contentstack.Management.Core.Models.Fields public class ModularBlockField : Field { [JsonPropertyName("blocks")] - public List blocks { get; set; } + public List? blocks { get; set; } } public class Block { [JsonPropertyName("title")] - public string Title { get; set; } + public string? Title { get; set; } [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("autoEdit")] public bool AutoEdit { get; set; } [JsonPropertyName("blockType")] public bool BlockType { get; set; } [JsonPropertyName("schema")] - public List Schema { get; set; } + public List? Schema { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/ReferenceField.cs b/Contentstack.Management.Core/Models/Fields/ReferenceField.cs index 569de5f..f593154 100644 --- a/Contentstack.Management.Core/Models/Fields/ReferenceField.cs +++ b/Contentstack.Management.Core/Models/Fields/ReferenceField.cs @@ -10,6 +10,6 @@ public class ReferenceField : Field [JsonPropertyName("reference_to")] public JsonElement? ReferenceTo { get; set; } [JsonPropertyName("plugins")] - public List Plugins { get; set; } + public List? Plugins { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/SelectField.cs b/Contentstack.Management.Core/Models/Fields/SelectField.cs index ca03fe7..dec0307 100644 --- a/Contentstack.Management.Core/Models/Fields/SelectField.cs +++ b/Contentstack.Management.Core/Models/Fields/SelectField.cs @@ -8,7 +8,7 @@ namespace Contentstack.Management.Core.Models.Fields public class SelectField : Field { [JsonPropertyName("enum")] - public SelectEnum Enum { get; set; } + public SelectEnum? Enum { get; set; } } @@ -18,7 +18,7 @@ public class SelectEnum public bool Advanced { get; set; } [JsonPropertyName("choices")] - public List> Choices { get; set; } + public List>? Choices { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Fields/TaxonomyField.cs b/Contentstack.Management.Core/Models/Fields/TaxonomyField.cs index f700e2b..20d2e9f 100644 --- a/Contentstack.Management.Core/Models/Fields/TaxonomyField.cs +++ b/Contentstack.Management.Core/Models/Fields/TaxonomyField.cs @@ -9,7 +9,7 @@ namespace Contentstack.Management.Core.Models.Fields public class TaxonomyField : Field { [JsonPropertyName("taxonomies")] - public List Taxonomies { get; set; } + public List? Taxonomies { get; set; } } /// @@ -18,7 +18,7 @@ public class TaxonomyField : Field public class TaxonomyFieldBinding { [JsonPropertyName("taxonomy_uid")] - public string TaxonomyUid { get; set; } + public string? TaxonomyUid { get; set; } [JsonPropertyName("max_terms")] public int? MaxTerms { get; set; } diff --git a/Contentstack.Management.Core/Models/Fields/TextboxField.cs b/Contentstack.Management.Core/Models/Fields/TextboxField.cs index cdd2fdc..82b49b4 100644 --- a/Contentstack.Management.Core/Models/Fields/TextboxField.cs +++ b/Contentstack.Management.Core/Models/Fields/TextboxField.cs @@ -7,9 +7,9 @@ namespace Contentstack.Management.Core.Models.Fields public class TextboxField : Field { [JsonPropertyName("format")] - public string Format { get; set; } + public string? Format { get; set; } [JsonPropertyName("error_messages")] - public Dictionary ErrorMessages { get; set; } + public Dictionary? ErrorMessages { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Folder.cs b/Contentstack.Management.Core/Models/Folder.cs index 9aa9daa..8ffbee7 100644 --- a/Contentstack.Management.Core/Models/Folder.cs +++ b/Contentstack.Management.Core/Models/Folder.cs @@ -8,13 +8,13 @@ namespace Contentstack.Management.Core.Models { public class Folder { - internal Stack stack; - internal string resourcePath; + internal Stack stack = null!; + internal string resourcePath = null!; - public string Uid { get; set; } + public string? Uid { get; set; } - internal Folder(Stack stack, string uid = null) + internal Folder(Stack stack, string? uid = null) { stack.ThrowIfAPIKeyEmpty(); @@ -36,7 +36,7 @@ internal Folder(Stack stack, string uid = null) /// /// /// The . - public virtual ContentstackResponse Create(string name, string parentUid = null) + public virtual ContentstackResponse Create(string name, string? parentUid = null) { ThrowIfUidNotEmpty(); @@ -56,7 +56,7 @@ public virtual ContentstackResponse Create(string name, string parentUid = null) /// /// /// The Task. - public virtual Task CreateAsync(string name, string parentUid = null) + public virtual Task CreateAsync(string name, string? parentUid = null) { ThrowIfUidNotEmpty(); stack.ThrowIfNotLoggedIn(); @@ -77,7 +77,7 @@ public virtual Task CreateAsync(string name, string parent /// /// /// The . - public virtual ContentstackResponse Update(string name, string parentUid = null) + public virtual ContentstackResponse Update(string name, string? parentUid = null) { ThrowIfUidEmpty(); @@ -97,7 +97,7 @@ public virtual ContentstackResponse Update(string name, string parentUid = null) /// /// /// The . - public virtual Task UpdateAsync(string name, string parentUid = null) + public virtual Task UpdateAsync(string name, string? parentUid = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -117,7 +117,7 @@ public virtual Task UpdateAsync(string name, string parent /// /// /// The . - public virtual ContentstackResponse Fetch(ParameterCollection collection = null) + public virtual ContentstackResponse Fetch(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -137,7 +137,7 @@ public virtual ContentstackResponse Fetch(ParameterCollection collection = null) /// /// /// The . - public virtual Task FetchAsync(ParameterCollection collection = null) + public virtual Task FetchAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); diff --git a/Contentstack.Management.Core/Models/GlobalField.cs b/Contentstack.Management.Core/Models/GlobalField.cs index e5512d9..88290be 100644 --- a/Contentstack.Management.Core/Models/GlobalField.cs +++ b/Contentstack.Management.Core/Models/GlobalField.cs @@ -6,9 +6,9 @@ namespace Contentstack.Management.Core.Models { public class GlobalField : BaseModel { - private readonly string apiVersion; + private readonly string? apiVersion; - internal GlobalField(Stack stack, string uid = null, string apiVersion = null) + internal GlobalField(Stack stack, string? uid = null, string? apiVersion = null) : base(stack, "global_field", uid) { resourcePath = uid == null ? "/global_fields" : $"/global_fields/{uid}"; @@ -43,7 +43,7 @@ public Query Query() /// /// IGlobalField for updating Content Type. /// The . - public override ContentstackResponse Create(ContentModelling model, ParameterCollection collection = null) + public override ContentstackResponse Create(ContentModelling model, ParameterCollection? collection = null) { ThrowIfUidNotEmpty(); var service = new GlobalFieldService(stack.client.SerializerOptions, stack, resourcePath, model, this.fieldName, apiVersion, collection: collection); @@ -62,7 +62,7 @@ public override ContentstackResponse Create(ContentModelling model, ParameterCol /// /// IGlobalField for updating Content Type. /// The Task. - public override Task CreateAsync(ContentModelling model, ParameterCollection collection = null) + public override Task CreateAsync(ContentModelling model, ParameterCollection? collection = null) { ThrowIfUidNotEmpty(); stack.ThrowIfNotLoggedIn(); @@ -82,7 +82,7 @@ public override Task CreateAsync(ContentModelling model, P /// /// IGlobalField for updating Content Type. /// The . - public override ContentstackResponse Update(ContentModelling model, ParameterCollection collection = null) + public override ContentstackResponse Update(ContentModelling model, ParameterCollection? collection = null) { ThrowIfUidEmpty(); var service = new GlobalFieldService(stack.client.SerializerOptions, stack, resourcePath, model, this.fieldName, apiVersion, "PUT", collection: collection); @@ -101,7 +101,7 @@ public override ContentstackResponse Update(ContentModelling model, ParameterCol /// /// IGlobalField for updating Content Type. /// The Task. - public override Task UpdateAsync(ContentModelling model, ParameterCollection collection = null) + public override Task UpdateAsync(ContentModelling model, ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -119,7 +119,7 @@ public override Task UpdateAsync(ContentModelling model, P /// /// /// The . - public override ContentstackResponse Fetch(ParameterCollection collection = null) + public override ContentstackResponse Fetch(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -137,7 +137,7 @@ public override ContentstackResponse Fetch(ParameterCollection collection = null /// /// /// The Task. - public override Task FetchAsync(ParameterCollection collection = null) + public override Task FetchAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -155,7 +155,7 @@ public override Task FetchAsync(ParameterCollection collec /// /// /// The . - public override ContentstackResponse Delete(ParameterCollection collection = null) + public override ContentstackResponse Delete(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); @@ -173,7 +173,7 @@ public override ContentstackResponse Delete(ParameterCollection collection = nul /// /// /// The Task. - public override Task DeleteAsync(ParameterCollection collection = null) + public override Task DeleteAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidEmpty(); diff --git a/Contentstack.Management.Core/Models/LabelModel.cs b/Contentstack.Management.Core/Models/LabelModel.cs index c513136..0a5f372 100644 --- a/Contentstack.Management.Core/Models/LabelModel.cs +++ b/Contentstack.Management.Core/Models/LabelModel.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Newtonsoft.Json; namespace Contentstack.Management.Core.Models @@ -7,10 +7,10 @@ namespace Contentstack.Management.Core.Models public class LabelModel { [JsonProperty(propertyName: "name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonProperty(propertyName: "parent")] - public List Parent { get; set; } + public List? Parent { get; set; } [JsonProperty(propertyName: "content_types")] - public List ContentTypes { get; set; } + public List? ContentTypes { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Locale.cs b/Contentstack.Management.Core/Models/Locale.cs index 3d2abe5..acb80c2 100644 --- a/Contentstack.Management.Core/Models/Locale.cs +++ b/Contentstack.Management.Core/Models/Locale.cs @@ -7,7 +7,7 @@ namespace Contentstack.Management.Core.Models { public class Locale: BaseModel { - internal Locale(Stack stack, string code = null) + internal Locale(Stack stack, string? code = null) : base(stack, "locale", code) { resourcePath = code == null ? $"/locales" : $"/locales/{code}"; @@ -41,7 +41,7 @@ public Query Query() /// /// LocaleModel for createing Locale. /// The . - public override ContentstackResponse Create(LocaleModel model, ParameterCollection collection = null) + public override ContentstackResponse Create(LocaleModel model, ParameterCollection? collection = null) { return base.Create(model, collection); } @@ -58,7 +58,7 @@ public override ContentstackResponse Create(LocaleModel model, ParameterCollecti /// /// LocaleModel for createing Locale. /// The Task. - public override Task CreateAsync(LocaleModel model, ParameterCollection collection = null) + public override Task CreateAsync(LocaleModel model, ParameterCollection? collection = null) { return base.CreateAsync(model, collection); } @@ -75,7 +75,7 @@ public override Task CreateAsync(LocaleModel model, Parame /// /// LocaleModel for updating locale. /// The . - public override ContentstackResponse Update(LocaleModel model, ParameterCollection collection = null) + public override ContentstackResponse Update(LocaleModel model, ParameterCollection? collection = null) { return base.Update(model, collection); } @@ -92,7 +92,7 @@ public override ContentstackResponse Update(LocaleModel model, ParameterCollecti /// /// LocaleModel for updating locale. /// The Task. - public override Task UpdateAsync(LocaleModel model, ParameterCollection collection = null) + public override Task UpdateAsync(LocaleModel model, ParameterCollection? collection = null) { return base.UpdateAsync(model, collection); } @@ -107,7 +107,7 @@ public override Task UpdateAsync(LocaleModel model, Parame /// /// /// The . - public override ContentstackResponse Fetch(ParameterCollection collection = null) + public override ContentstackResponse Fetch(ParameterCollection? collection = null) { return base.Fetch(collection); } @@ -122,7 +122,7 @@ public override ContentstackResponse Fetch(ParameterCollection collection = null /// /// /// The Task. - public override Task FetchAsync(ParameterCollection collection = null) + public override Task FetchAsync(ParameterCollection? collection = null) { return base.FetchAsync(collection); } @@ -137,7 +137,7 @@ public override Task FetchAsync(ParameterCollection collec /// /// /// The . - public override ContentstackResponse Delete(ParameterCollection collection = null) + public override ContentstackResponse Delete(ParameterCollection? collection = null) { return base.Delete(collection); } @@ -152,7 +152,7 @@ public override ContentstackResponse Delete(ParameterCollection collection = nul /// /// /// The Task. - public override Task DeleteAsync(ParameterCollection collection = null) + public override Task DeleteAsync(ParameterCollection? collection = null) { return base.DeleteAsync(collection); } diff --git a/Contentstack.Management.Core/Models/LocaleModel.cs b/Contentstack.Management.Core/Models/LocaleModel.cs index 8fe452e..17df7f0 100644 --- a/Contentstack.Management.Core/Models/LocaleModel.cs +++ b/Contentstack.Management.Core/Models/LocaleModel.cs @@ -6,14 +6,14 @@ public class LocaleModel { [JsonPropertyName("name")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string Name { get; set; } + public string? Name { get; set; } [JsonPropertyName("code")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string Code { get; set; } + public string? Code { get; set; } [JsonPropertyName("fallback_locale")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public string FallbackLocale { get; set; } + public string? FallbackLocale { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Node.cs b/Contentstack.Management.Core/Models/Node.cs index a12a274..f373959 100644 --- a/Contentstack.Management.Core/Models/Node.cs +++ b/Contentstack.Management.Core/Models/Node.cs @@ -5,10 +5,10 @@ namespace Contentstack.Management.Core.Models { public class Node { - public string type { get; set; } + public string? type { get; set; } - public IDictionary attrs { get; set; } + public IDictionary? attrs { get; set; } - public List children { get; set; } + public List? children { get; set; } } } \ No newline at end of file diff --git a/Contentstack.Management.Core/Models/OAuthAppAuthorizationResponse.cs b/Contentstack.Management.Core/Models/OAuthAppAuthorizationResponse.cs index 6f875a7..e8fa02d 100644 --- a/Contentstack.Management.Core/Models/OAuthAppAuthorizationResponse.cs +++ b/Contentstack.Management.Core/Models/OAuthAppAuthorizationResponse.cs @@ -10,7 +10,7 @@ public class OAuthAppAuthorizationResponse { [JsonProperty("data")] - public OAuthAppAuthorizationData[] Data { get; set; } + public OAuthAppAuthorizationData[]? Data { get; set; } } /// @@ -20,11 +20,11 @@ public class OAuthAppAuthorizationData { [JsonProperty("authorization_uid")] - public string AuthorizationUid { get; set; } + public string? AuthorizationUid { get; set; } + - [JsonProperty("user")] - public OAuthUser User { get; set; } + public OAuthUser? User { get; set; } } @@ -32,7 +32,7 @@ public class OAuthUser { [JsonProperty("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } } } diff --git a/Contentstack.Management.Core/Models/OAuthOptions.cs b/Contentstack.Management.Core/Models/OAuthOptions.cs index e6b9862..0e084e7 100644 --- a/Contentstack.Management.Core/Models/OAuthOptions.cs +++ b/Contentstack.Management.Core/Models/OAuthOptions.cs @@ -26,7 +26,7 @@ public class OAuthOptions /// The OAuth client secret. If provided, PKCE flow will be skipped. /// If null or empty, PKCE flow will be used for enhanced security. /// - public string ClientSecret { get; set; } + public string? ClientSecret { get; set; } /// /// The OAuth response type. Defaults to "code" for authorization code flow. @@ -36,7 +36,7 @@ public class OAuthOptions /// /// The OAuth scopes to request. Optional array of permission scopes. /// - public string[] Scope { get; set; } + public string[]? Scope { get; set; } /// /// Indicates whether PKCE (Proof Key for Code Exchange) flow should be used. @@ -58,7 +58,7 @@ public bool IsValid() /// /// The validation error message if validation fails. /// True if the configuration is valid, false otherwise. - public bool IsValid(out string errorMessage) + public bool IsValid(out string? errorMessage) { errorMessage = null; @@ -122,7 +122,7 @@ public void Validate() { if (!IsValid(out var errorMessage)) { - throw new Exceptions.OAuthConfigurationException(errorMessage); + throw new Exceptions.OAuthConfigurationException(errorMessage!); } } diff --git a/Contentstack.Management.Core/Models/OAuthResponse.cs b/Contentstack.Management.Core/Models/OAuthResponse.cs index 714bc0d..5d5b1a0 100644 --- a/Contentstack.Management.Core/Models/OAuthResponse.cs +++ b/Contentstack.Management.Core/Models/OAuthResponse.cs @@ -10,11 +10,11 @@ public class OAuthResponse { [JsonProperty("access_token")] - public string AccessToken { get; set; } + public string? AccessToken { get; set; } + - [JsonProperty("refresh_token")] - public string RefreshToken { get; set; } + public string? RefreshToken { get; set; } [JsonProperty("expires_in")] @@ -22,11 +22,11 @@ public class OAuthResponse [JsonProperty("organization_uid")] - public string OrganizationUid { get; set; } + public string? OrganizationUid { get; set; } + - [JsonProperty("user_uid")] - public string UserUid { get; set; } + public string? UserUid { get; set; } } } diff --git a/Contentstack.Management.Core/Models/OAuthTokens.cs b/Contentstack.Management.Core/Models/OAuthTokens.cs index 4b83b37..462a55c 100644 --- a/Contentstack.Management.Core/Models/OAuthTokens.cs +++ b/Contentstack.Management.Core/Models/OAuthTokens.cs @@ -9,19 +9,19 @@ namespace Contentstack.Management.Core.Models public class OAuthTokens { - public string AccessToken { get; set; } + public string? AccessToken { get; set; } - public string RefreshToken { get; set; } + public string? RefreshToken { get; set; } public DateTime ExpiresAt { get; set; } - public string OrganizationUid { get; set; } + public string? OrganizationUid { get; set; } - public string UserUid { get; set; } + public string? UserUid { get; set; } - public string ClientId { get; set; } + public string? ClientId { get; set; } - public string AppId { get; set; } + public string? AppId { get; set; } public bool IsExpired => ExpiresAt == DateTime.MinValue || DateTime.UtcNow >= ExpiresAt; @@ -48,6 +48,7 @@ public bool NeedsRefresh } public bool IsValid => !string.IsNullOrEmpty(AccessToken) && !IsExpired; + } } diff --git a/Contentstack.Management.Core/Models/Organization.cs b/Contentstack.Management.Core/Models/Organization.cs index 9fff482..34b4ac3 100644 --- a/Contentstack.Management.Core/Models/Organization.cs +++ b/Contentstack.Management.Core/Models/Organization.cs @@ -20,7 +20,7 @@ public Organization(ContentstackClient contentstackClient, string? uid = null) #endregion #region Public - public string Uid { get; set; } + public string? Uid { get; set; } /// /// The Get all/single organizations call lists all organizations related to the system user in the order that they were created. diff --git a/Contentstack.Management.Core/Models/PublishRuleModel.cs b/Contentstack.Management.Core/Models/PublishRuleModel.cs index 11b6719..6b64049 100644 --- a/Contentstack.Management.Core/Models/PublishRuleModel.cs +++ b/Contentstack.Management.Core/Models/PublishRuleModel.cs @@ -6,21 +6,21 @@ namespace Contentstack.Management.Core.Models public class PublishRuleModel { [JsonProperty(propertyName: "workflow")] - public string WorkflowUid { get; set; } + public string? WorkflowUid { get; set; } [JsonProperty(propertyName: "actions")] - public List Actions { get; set; } + public List? Actions { get; set; } [JsonProperty(propertyName: "branches")] - public List Branches { get; set; } + public List? Branches { get; set; } [JsonProperty(propertyName: "content_types")] - public List ContentTypes { get; set; } + public List? ContentTypes { get; set; } [JsonProperty(propertyName: "locales")] - public List Locales { get; set; } + public List? Locales { get; set; } [JsonProperty(propertyName: "environment")] - public string Environment { get; set; } + public string? Environment { get; set; } [JsonProperty(propertyName: "approvers")] - public Approvals Approvers { get; set; } + public Approvals? Approvers { get; set; } [JsonProperty(propertyName: "workflow_stage")] - public string WorkflowStageUid { get; set; } + public string? WorkflowStageUid { get; set; } [JsonProperty(propertyName: "disable_approver_publishing")] public bool DisableApproval { get; set; } = false; } @@ -29,8 +29,8 @@ public class PublishRuleModel public class Approvals { [JsonProperty(propertyName: "users")] - public List Users { get; set; } + public List? Users { get; set; } [JsonProperty(propertyName: "roles")] - public List Roles { get; set; } + public List? Roles { get; set; } } } diff --git a/Contentstack.Management.Core/Models/PublishUnpublishDetails.cs b/Contentstack.Management.Core/Models/PublishUnpublishDetails.cs index ddeb98e..0fb2f51 100644 --- a/Contentstack.Management.Core/Models/PublishUnpublishDetails.cs +++ b/Contentstack.Management.Core/Models/PublishUnpublishDetails.cs @@ -4,17 +4,17 @@ namespace Contentstack.Management.Core.Models { public class PublishUnpublishDetails { - public List Locales { get; set; } + public List? Locales { get; set; } - public List Environments { get; set; } + public List? Environments { get; set; } - public List Variants { get; set; } + public List? Variants { get; set; } - public PublishVariantRules VariantRules { get; set; } + public PublishVariantRules? VariantRules { get; set; } public int? Version { get; set; } - public string ScheduledAt { get; set; } + public string? ScheduledAt { get; set; } } } diff --git a/Contentstack.Management.Core/Models/PublishVariant.cs b/Contentstack.Management.Core/Models/PublishVariant.cs index 4a974cb..f0a6f15 100644 --- a/Contentstack.Management.Core/Models/PublishVariant.cs +++ b/Contentstack.Management.Core/Models/PublishVariant.cs @@ -5,7 +5,7 @@ namespace Contentstack.Management.Core.Models public class PublishVariant { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("version")] public int? Version { get; set; } diff --git a/Contentstack.Management.Core/Models/ReleaseModel.cs b/Contentstack.Management.Core/Models/ReleaseModel.cs index 7042045..7bae018 100644 --- a/Contentstack.Management.Core/Models/ReleaseModel.cs +++ b/Contentstack.Management.Core/Models/ReleaseModel.cs @@ -6,10 +6,10 @@ namespace Contentstack.Management.Core.Models public class ReleaseModel { [JsonProperty(propertyName: "name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonProperty(propertyName: "description")] - public string Description { get; set; } + public string? Description { get; set; } [JsonProperty(propertyName: "locked")] public bool Locked { get; set; } @@ -23,16 +23,16 @@ public class ReleaseModel public class DeployModel { [JsonProperty(propertyName: "environments")] - public List Environments { get; set; } + public List? Environments { get; set; } [JsonProperty(propertyName: "locales")] - public List Locales { get; set; } + public List? Locales { get; set; } [JsonProperty(propertyName: "scheduledAt")] - public string ScheduledAt { get; set; } + public string? ScheduledAt { get; set; } [JsonProperty(propertyName: "action")] - public string Action { get; set; } + public string? Action { get; set; } } @@ -40,18 +40,18 @@ public class DeployModel public class ReleaseItemModel { [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonProperty(propertyName: "version")] public int Version { get; set; } [JsonProperty(propertyName: "locale")] - public string Locale { get; set; } + public string? Locale { get; set; } [JsonProperty(propertyName: "content_type_uid")] - public string ContentTypeUID { get; set; } + public string? ContentTypeUID { get; set; } [JsonProperty(propertyName: "action")] - public string Action { get; set; } + public string? Action { get; set; } } } diff --git a/Contentstack.Management.Core/Models/RoleModel.cs b/Contentstack.Management.Core/Models/RoleModel.cs index 3fb5ba1..13c0d25 100644 --- a/Contentstack.Management.Core/Models/RoleModel.cs +++ b/Contentstack.Management.Core/Models/RoleModel.cs @@ -6,13 +6,13 @@ namespace Contentstack.Management.Core.Models public class RoleModel { [JsonProperty(propertyName: "name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonProperty(propertyName: "description")] - public string Description { get; set; } + public string? Description { get; set; } [JsonProperty(propertyName: "rules")] - public List Rules { get; set; } + public List? Rules { get; set; } [JsonProperty(propertyName: "deploy_content")] public bool DeployContent { get; set; } = true; @@ -21,7 +21,7 @@ public class RoleModel public class Rule { [JsonProperty(propertyName: "acl")] - public Dictionary ACL { get; } + public Dictionary? ACL { get; } [JsonProperty(propertyName: "restrict")] public bool Restrict { get; } @@ -33,7 +33,7 @@ public class ContentTypeRules: Rule public string Module { get; } = "content_type"; [JsonProperty(propertyName: "content_types")] - public List ContentTypes { get; set; } + public List? ContentTypes { get; set; } } public class BranchRules : Rule @@ -42,7 +42,7 @@ public class BranchRules : Rule public string Module { get; } = "branch"; [JsonProperty(propertyName: "branches")] - public List Branches { get; set; } + public List? Branches { get; set; } } public class BranchAliasRules : Rule @@ -51,7 +51,7 @@ public class BranchAliasRules : Rule public string Module { get; } = "branch_alias"; [JsonProperty(propertyName: "branch_aliases")] - public List BranchAliases { get; set; } + public List? BranchAliases { get; set; } } public class AssetRules : Rule @@ -60,7 +60,7 @@ public class AssetRules : Rule public string Module { get; } = "asset"; [JsonProperty(propertyName: "assets")] - public List Assets { get; set; } + public List? Assets { get; set; } } public class FolderRules : Rule @@ -69,7 +69,7 @@ public class FolderRules : Rule public string Module { get; } = "folder"; [JsonProperty(propertyName: "folders")] - public List Folders { get; set; } + public List? Folders { get; set; } } public class EnvironmentRules : Rule @@ -78,16 +78,16 @@ public class EnvironmentRules : Rule public string Module { get; } = "environment"; [JsonProperty(propertyName: "environments")] - public List Environments { get; set; } + public List? Environments { get; set; } } public class TaxonomyContentType { [JsonProperty(propertyName: "uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonProperty(propertyName: "acl")] - public Dictionary ACL { get; } + public Dictionary? ACL { get; } } public class TaxonomyRules : Rule @@ -96,12 +96,12 @@ public class TaxonomyRules : Rule public string Module { get; } = "taxonomy"; [JsonProperty(propertyName: "taxonomies")] - public List Taxonomies { get; set; } + public List? Taxonomies { get; set; } [JsonProperty(propertyName: "terms")] - public List Terms { get; set; } + public List? Terms { get; set; } [JsonProperty(propertyName: "content_types")] - public List ContentTypes { get; set; } + public List? ContentTypes { get; set; } } } diff --git a/Contentstack.Management.Core/Models/Stack.cs b/Contentstack.Management.Core/Models/Stack.cs index 0142054..21ddf63 100644 --- a/Contentstack.Management.Core/Models/Stack.cs +++ b/Contentstack.Management.Core/Models/Stack.cs @@ -11,10 +11,10 @@ namespace Contentstack.Management.Core.Models { public class Stack { - internal ContentstackClient client; - public string APIKey { get; private set; } - public string ManagementToken { get; private set; } - public string BranchUid { get; private set; } + internal ContentstackClient client = null!; + public string? APIKey { get; private set; } + public string? ManagementToken { get; private set; } + public string? BranchUid { get; private set; } #region Constructor public Stack(ContentstackClient contentstackClient, string? apiKey = null, string? managementToken = null, string? branchUid = null) @@ -594,15 +594,13 @@ public Task UnShareAsync(string email) /// /// Locale code fot language /// The - /* - public Locale Locale(string code = null) + public Locale Locale(string? code = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); return new Locale(this, code); } - */ /// /// defines the structure or schema of a page or a section of your web or mobile property. @@ -637,7 +635,7 @@ public ContentType ContentType(string? uid = null) /// /// /// The - public Asset Asset(string uid = null) + public Asset Asset(string? uid = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); @@ -657,7 +655,7 @@ public Asset Asset(string uid = null) /// /// /// The - public GlobalField GlobalField(string uid = null, string apiVersion = null) + public GlobalField GlobalField(string? uid = null, string? apiVersion = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); @@ -740,7 +738,7 @@ public Taxonomy Taxonomy(string uid = null) /// /// /// The - public Environment Environment(string uid = null) + public Environment Environment(string? uid = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); @@ -936,7 +934,7 @@ public AuditLog AuditLog(string uid = null) /// /// /// The - public VariantGroup VariantGroup(string uid = null) + public VariantGroup VariantGroup(string? uid = null) { ThrowIfNotLoggedIn(); ThrowIfAPIKeyEmpty(); diff --git a/Contentstack.Management.Core/Models/StackSettings.cs b/Contentstack.Management.Core/Models/StackSettings.cs index fcbdd8e..b8619f4 100644 --- a/Contentstack.Management.Core/Models/StackSettings.cs +++ b/Contentstack.Management.Core/Models/StackSettings.cs @@ -9,13 +9,13 @@ public class StackSettings { [JsonPropertyName("stack_variables")] [JsonConverter(typeof(NativeDictionaryConverter))] - public Dictionary StackVariables { get; set; } + public Dictionary? StackVariables { get; set; } [JsonPropertyName("discrete_variables")] [JsonConverter(typeof(NativeDictionaryConverter))] - public Dictionary DiscreteVariables { get; set; } + public Dictionary? DiscreteVariables { get; set; } [JsonPropertyName("rte")] [JsonConverter(typeof(NativeDictionaryConverter))] - public Dictionary Rte { get; set; } + public Dictionary? Rte { get; set; } } /// @@ -24,7 +24,7 @@ public class StackSettings /// internal sealed class NativeDictionaryConverter : JsonConverter> { - public override Dictionary Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override Dictionary? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Null) return null; @@ -33,15 +33,16 @@ public override Dictionary Read(ref Utf8JsonReader reader, Type reader.Read(); // StartObject while (reader.TokenType != JsonTokenType.EndObject) { - string key = reader.GetString(); + string? key = reader.GetString(); reader.Read(); - dict[key] = ReadValue(ref reader); + if (key != null) + dict[key] = ReadValue(ref reader)!; reader.Read(); } return dict; } - private static object ReadValue(ref Utf8JsonReader reader) => reader.TokenType switch + private static object? ReadValue(ref Utf8JsonReader reader) => reader.TokenType switch { JsonTokenType.True => true, JsonTokenType.False => false, diff --git a/Contentstack.Management.Core/Models/TaxonomyModel.cs b/Contentstack.Management.Core/Models/TaxonomyModel.cs index d8ece88..1a33538 100644 --- a/Contentstack.Management.Core/Models/TaxonomyModel.cs +++ b/Contentstack.Management.Core/Models/TaxonomyModel.cs @@ -8,16 +8,16 @@ namespace Contentstack.Management.Core.Models public class TaxonomyModel { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string Description { get; set; } + public string? Description { get; set; } [JsonPropertyName("locale")] - public string Locale { get; set; } + public string? Locale { get; set; } [JsonPropertyName("terms_count")] public int? TermsCount { get; set; } @@ -32,12 +32,12 @@ public class TaxonomyModel public int? ReferencedContentTypeCount { get; set; } [JsonPropertyName("created_at")] - public string CreatedAt { get; set; } + public string? CreatedAt { get; set; } [JsonPropertyName("updated_at")] - public string UpdatedAt { get; set; } + public string? UpdatedAt { get; set; } [JsonPropertyName("uuid")] - public string Uuid { get; set; } + public string? Uuid { get; set; } } } diff --git a/Contentstack.Management.Core/Models/TermModel.cs b/Contentstack.Management.Core/Models/TermModel.cs index 4989976..d5938f1 100644 --- a/Contentstack.Management.Core/Models/TermModel.cs +++ b/Contentstack.Management.Core/Models/TermModel.cs @@ -9,16 +9,16 @@ namespace Contentstack.Management.Core.Models public class TermModel { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonPropertyName("taxonomy_uid")] - public string TaxonomyUid { get; set; } + public string? TaxonomyUid { get; set; } [JsonPropertyName("parent_uid")] - public string ParentUid { get; set; } + public string? ParentUid { get; set; } [JsonPropertyName("depth")] public int? Depth { get; set; } @@ -30,16 +30,16 @@ public class TermModel public int? ReferencedEntriesCount { get; set; } [JsonPropertyName("ancestors")] - public List Ancestors { get; set; } + public List? Ancestors { get; set; } [JsonPropertyName("descendants")] - public List Descendants { get; set; } + public List? Descendants { get; set; } [JsonPropertyName("created_at")] - public string CreatedAt { get; set; } + public string? CreatedAt { get; set; } [JsonPropertyName("updated_at")] - public string UpdatedAt { get; set; } + public string? UpdatedAt { get; set; } } /// @@ -48,13 +48,13 @@ public class TermModel public class TermAncestorDescendant { [JsonPropertyName("uid")] - public string Uid { get; set; } + public string? Uid { get; set; } [JsonPropertyName("name")] - public string Name { get; set; } + public string? Name { get; set; } [JsonPropertyName("parent_uid")] - public string ParentUid { get; set; } + public string? ParentUid { get; set; } [JsonPropertyName("depth")] public int? Depth { get; set; } @@ -72,7 +72,7 @@ public class TermAncestorDescendant public class TermMoveModel { [JsonPropertyName("parent_uid")] - public string ParentUid { get; set; } + public string? ParentUid { get; set; } [JsonPropertyName("order")] public int? Order { get; set; } diff --git a/Contentstack.Management.Core/Models/TextNode.cs b/Contentstack.Management.Core/Models/TextNode.cs index 1d4e9dc..384d6e5 100644 --- a/Contentstack.Management.Core/Models/TextNode.cs +++ b/Contentstack.Management.Core/Models/TextNode.cs @@ -13,6 +13,6 @@ public class TextNode: Node public bool subscript { get; set; } public bool superscript { get; set; } public bool @break { get; set; } - public string text { get; set; } + public string? text { get; set; } } } diff --git a/Contentstack.Management.Core/Models/UserInvitation.cs b/Contentstack.Management.Core/Models/UserInvitation.cs index 876262e..2c5aae7 100644 --- a/Contentstack.Management.Core/Models/UserInvitation.cs +++ b/Contentstack.Management.Core/Models/UserInvitation.cs @@ -8,16 +8,16 @@ public class UserInvitation /// /// User email-id for invitation /// - public string Email { get; set; } + public string? Email { get; set; } /// /// User uid for invitation /// - public string Uid { get; set; } + public string? Uid { get; set; } /// /// List of roles Uid to be assigned to the user. /// - public List Roles { get; set; } + public List? Roles { get; set; } } } diff --git a/Contentstack.Management.Core/Models/VariantGroup.cs b/Contentstack.Management.Core/Models/VariantGroup.cs index 2f2c02c..ea2ba65 100644 --- a/Contentstack.Management.Core/Models/VariantGroup.cs +++ b/Contentstack.Management.Core/Models/VariantGroup.cs @@ -12,16 +12,16 @@ namespace Contentstack.Management.Core.Models /// public class VariantGroup { - internal Stack stack; - internal string resourcePath; + internal Stack stack = null!; + internal string resourcePath = null!; /// /// Gets the UID of the variant group. /// - public string Uid { get; private set; } + public string? Uid { get; private set; } #region Constructor - internal VariantGroup(Stack stack, string uid = null) + internal VariantGroup(Stack stack, string? uid = null) { if (stack == null) { @@ -49,7 +49,7 @@ internal VariantGroup(Stack stack, string uid = null) /// /// /// The . - public ContentstackResponse Find(ParameterCollection collection = null) + public ContentstackResponse Find(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidNotEmpty(); @@ -73,7 +73,7 @@ public ContentstackResponse Find(ParameterCollection collection = null) /// /// /// The Task. - public Task FindAsync(ParameterCollection collection = null) + public Task FindAsync(ParameterCollection? collection = null) { stack.ThrowIfNotLoggedIn(); ThrowIfUidNotEmpty(); @@ -101,7 +101,7 @@ public Task FindAsync(ParameterCollection collection = nul /// The . public ContentstackResponse LinkContentTypes( List contentTypeUids, - ParameterCollection collection = null + ParameterCollection? collection = null ) { stack.ThrowIfNotLoggedIn(); @@ -135,7 +135,7 @@ public ContentstackResponse LinkContentTypes( /// The Task. public Task LinkContentTypesAsync( List contentTypeUids, - ParameterCollection collection = null + ParameterCollection? collection = null ) { stack.ThrowIfNotLoggedIn(); @@ -171,7 +171,7 @@ public Task LinkContentTypesAsync( /// The . public ContentstackResponse UnlinkContentTypes( List contentTypeUids, - ParameterCollection collection = null + ParameterCollection? collection = null ) { stack.ThrowIfNotLoggedIn(); @@ -205,7 +205,7 @@ public ContentstackResponse UnlinkContentTypes( /// The Task. public Task UnlinkContentTypesAsync( List contentTypeUids, - ParameterCollection collection = null + ParameterCollection? collection = null ) { stack.ThrowIfNotLoggedIn(); diff --git a/Contentstack.Management.Core/Models/Version.cs b/Contentstack.Management.Core/Models/Version.cs index a270658..8caad55 100644 --- a/Contentstack.Management.Core/Models/Version.cs +++ b/Contentstack.Management.Core/Models/Version.cs @@ -8,9 +8,9 @@ namespace Contentstack.Management.Core.Models { public class Version { - internal Stack stack; - internal string resourcePath; - internal string fieldName; + internal Stack stack = null!; + internal string resourcePath = null!; + internal string fieldName = null!; public int? Number { get; set; } @@ -22,7 +22,7 @@ public Version(Stack stack, string resourcePath, string fieldName, int? number) this.fieldName = fieldName; } - public virtual ContentstackResponse GetAll(ParameterCollection collection = null) + public virtual ContentstackResponse GetAll(ParameterCollection? collection = null) { ThrowIfVersionNumberNotEmpty(); @@ -30,7 +30,7 @@ public virtual ContentstackResponse GetAll(ParameterCollection collection = null return stack.client.InvokeSync(service); } - public virtual Task GetAllAsync(ParameterCollection collection = null) + public virtual Task GetAllAsync(ParameterCollection? collection = null) { ThrowIfVersionNumberNotEmpty(); @@ -38,7 +38,7 @@ public virtual Task GetAllAsync(ParameterCollection collec return stack.client.InvokeAsync(service); } - public virtual ContentstackResponse Delete(string locale = null) + public virtual ContentstackResponse Delete(string? locale = null) { ThrowIfVersionNumberEmpty(); @@ -46,7 +46,7 @@ public virtual ContentstackResponse Delete(string locale = null) return stack.client.InvokeSync(service); } - public virtual Task DeleteAsync(string locale = null) + public virtual Task DeleteAsync(string? locale = null) { ThrowIfVersionNumberEmpty(); @@ -54,7 +54,7 @@ public virtual Task DeleteAsync(string locale = null) return stack.client.InvokeAsync(service); } - public virtual ContentstackResponse SetName(string name, string locale = null, bool force = false) + public virtual ContentstackResponse SetName(string name, string? locale = null, bool force = false) { ThrowIfVersionNumberEmpty(); @@ -66,7 +66,7 @@ public virtual ContentstackResponse SetName(string name, string locale = null, b return stack.client.InvokeSync(service); } - public virtual Task SetNameAsync(string name, string locale = null, bool force = false) + public virtual Task SetNameAsync(string name, string? locale = null, bool force = false) { ThrowIfVersionNumberEmpty(); diff --git a/Contentstack.Management.Core/Queryable/Query.cs b/Contentstack.Management.Core/Queryable/Query.cs index 32cc3ed..d0cfd19 100644 --- a/Contentstack.Management.Core/Queryable/Query.cs +++ b/Contentstack.Management.Core/Queryable/Query.cs @@ -11,7 +11,7 @@ public class Query private readonly Stack _stack; private readonly string _resourcePath; private readonly ParameterCollection _collection = new ParameterCollection(); - private readonly string _apiVersion; + private readonly string? _apiVersion; internal Query(Stack stack, string resourcePath, string? apiVersion = null) { @@ -83,7 +83,7 @@ public Query IncludeCount() /// The Find all object call fetches the list of all objects owned by a particular user account. /// /// The - public ContentstackResponse Find(ParameterCollection collection = null) + public ContentstackResponse Find(ParameterCollection? collection = null) { _stack.ThrowIfNotLoggedIn(); this.ThrowIfAPIKeyEmpty(); @@ -103,7 +103,7 @@ public ContentstackResponse Find(ParameterCollection collection = null) /// The Find all object call fetches the list of all objects owned by a particular user account. /// /// The Task - public Task FindAsync(ParameterCollection collection = null) + public Task FindAsync(ParameterCollection? collection = null) { _stack.ThrowIfNotLoggedIn(); this.ThrowIfAPIKeyEmpty(); diff --git a/Contentstack.Management.Core/Runtime/Contexts/IRequestContext.cs b/Contentstack.Management.Core/Runtime/Contexts/IRequestContext.cs index eb2827e..2e4af89 100644 --- a/Contentstack.Management.Core/Runtime/Contexts/IRequestContext.cs +++ b/Contentstack.Management.Core/Runtime/Contexts/IRequestContext.cs @@ -6,8 +6,8 @@ namespace Contentstack.Management.Core.Runtime.Contexts { public interface IRequestContext { - IContentstackService service { get; set; } - ContentstackClientOptions config { get; set; } + IContentstackService? service { get; set; } + ContentstackClientOptions? config { get; set; } int Retries { get; set; } /// diff --git a/Contentstack.Management.Core/Runtime/Contexts/IResponseContext.cs b/Contentstack.Management.Core/Runtime/Contexts/IResponseContext.cs index 64982e3..d44755f 100644 --- a/Contentstack.Management.Core/Runtime/Contexts/IResponseContext.cs +++ b/Contentstack.Management.Core/Runtime/Contexts/IResponseContext.cs @@ -5,6 +5,6 @@ namespace Contentstack.Management.Core.Runtime.Contexts { public interface IResponseContext { - IResponse httpResponse { get; set; } + IResponse? httpResponse { get; set; } } } diff --git a/Contentstack.Management.Core/Runtime/Contexts/RequestContext.cs b/Contentstack.Management.Core/Runtime/Contexts/RequestContext.cs index 9ce0b1a..eef6eb7 100644 --- a/Contentstack.Management.Core/Runtime/Contexts/RequestContext.cs +++ b/Contentstack.Management.Core/Runtime/Contexts/RequestContext.cs @@ -6,9 +6,9 @@ namespace Contentstack.Management.Core.Runtime.Contexts { internal class RequestContext : IRequestContext { - public IContentstackService service { get; set; } + public IContentstackService? service { get; set; } - public ContentstackClientOptions config { get; set; } + public ContentstackClientOptions? config { get; set; } public int Retries { get; set; } /// diff --git a/Contentstack.Management.Core/Runtime/Contexts/ResponseContext.cs b/Contentstack.Management.Core/Runtime/Contexts/ResponseContext.cs index f0cb4ac..e0a4b72 100644 --- a/Contentstack.Management.Core/Runtime/Contexts/ResponseContext.cs +++ b/Contentstack.Management.Core/Runtime/Contexts/ResponseContext.cs @@ -5,6 +5,6 @@ namespace Contentstack.Management.Core.Runtime.Contexts { internal class ResponseContext : IResponseContext { - public IResponse httpResponse { get; set; } + public IResponse? httpResponse { get; set; } } } diff --git a/Contentstack.Management.Core/Runtime/Pipeline/ContentstackRuntimePipeline.cs b/Contentstack.Management.Core/Runtime/Pipeline/ContentstackRuntimePipeline.cs index 17337b1..b4dc45a 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/ContentstackRuntimePipeline.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/ContentstackRuntimePipeline.cs @@ -15,7 +15,7 @@ public partial class ContentstackRuntimePipeline : IDisposable readonly ILogManager _logManager; // The top-most handler in the pipeline. - IPipelineHandler _handler; + IPipelineHandler _handler = null!; /// /// The top-most handler in the pipeline. @@ -83,14 +83,14 @@ public void AddHanlder(IPipelineHandler handler) _handler = currentHanler; } - public System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { ThrowIfDisposed(); return _handler.InvokeAsync(executionContext, addAcceptMediaHeader, apiVersion); } - public IResponseContext InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public IResponseContext InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { ThrowIfDisposed(); diff --git a/Contentstack.Management.Core/Runtime/Pipeline/HttpHandler/HttpHandler.cs b/Contentstack.Management.Core/Runtime/Pipeline/HttpHandler/HttpHandler.cs index 82544e7..5066a57 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/HttpHandler/HttpHandler.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/HttpHandler/HttpHandler.cs @@ -20,25 +20,25 @@ internal HttpHandler(HttpClient httpClient) #endregion #region Public - public ILogManager LogManager { get; set; } - public IPipelineHandler InnerHandler { get; set; } + public ILogManager LogManager { get; set; } = null!; + public IPipelineHandler InnerHandler { get; set; } = null!; - public async System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public async System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { - IHttpRequest httpRequest = null; + IHttpRequest? httpRequest = null; try { var requestContext = executionContext.RequestContext; - httpRequest = requestContext.service.CreateHttpRequest(_httpClient, requestContext.config, addAcceptMediaHeader, apiVersion); + httpRequest = requestContext.service!.CreateHttpRequest(_httpClient, requestContext.config!, addAcceptMediaHeader, apiVersion); if (requestContext.service.HasRequestBody() && requestContext.service.Content != null) { - httpRequest.WriteToRequestBody(requestContext.service.Content, requestContext.service.Headers); + httpRequest!.WriteToRequestBody(requestContext.service.Content, requestContext.service.Headers); } - executionContext.ResponseContext.httpResponse = await httpRequest.GetResponseAsync().ConfigureAwait(false); - executionContext.RequestContext.service.OnResponse(executionContext.ResponseContext.httpResponse, requestContext.config); + executionContext.ResponseContext.httpResponse = await httpRequest!.GetResponseAsync().ConfigureAwait(false); + executionContext.RequestContext.service!.OnResponse(executionContext.ResponseContext.httpResponse, requestContext.config!); return await System.Threading.Tasks.Task.FromResult((T)executionContext.ResponseContext.httpResponse); } @@ -57,23 +57,23 @@ public async System.Threading.Tasks.Task InvokeAsync(IExecutionContext exe } } - public void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { - IHttpRequest httpRequest = null; + IHttpRequest? httpRequest = null; try { var requestContext = executionContext.RequestContext; - httpRequest = requestContext.service.CreateHttpRequest(_httpClient, requestContext.config, addAcceptMediaHeader, apiVersion: apiVersion); + httpRequest = requestContext.service!.CreateHttpRequest(_httpClient, requestContext.config!, addAcceptMediaHeader, apiVersion: apiVersion); if (requestContext.service.HasRequestBody() && requestContext.service.Content != null) { - httpRequest.WriteToRequestBody(requestContext.service.Content, requestContext.service.Headers); + httpRequest!.WriteToRequestBody(requestContext.service.Content, requestContext.service.Headers); } - executionContext.ResponseContext.httpResponse = httpRequest.GetResponse(); + executionContext.ResponseContext.httpResponse = httpRequest!.GetResponse(); - executionContext.RequestContext.service.OnResponse(executionContext.ResponseContext.httpResponse, requestContext.config); + executionContext.RequestContext.service!.OnResponse(executionContext.ResponseContext.httpResponse, requestContext.config!); } catch (Exception e) { diff --git a/Contentstack.Management.Core/Runtime/Pipeline/IPipelineHandler.cs b/Contentstack.Management.Core/Runtime/Pipeline/IPipelineHandler.cs index 7c6460e..d9efa8b 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/IPipelineHandler.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/IPipelineHandler.cs @@ -25,13 +25,13 @@ public interface IPipelineHandler /// /// - void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null); + void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null); /// /// /// /// /// - System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null); + System.Threading.Tasks.Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null); } } diff --git a/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs b/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs index e802586..444db96 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/PipelineHandler.cs @@ -8,11 +8,11 @@ namespace Contentstack.Management.Core.Runtime.Pipeline { public class PipelineHandler : IPipelineHandler { - public ILogManager LogManager { get; set; } + public ILogManager LogManager { get; set; } = null!; - public IPipelineHandler InnerHandler { get; set; } + public IPipelineHandler InnerHandler { get; set; } = null!; - public virtual Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public virtual Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { if (InnerHandler != null) { @@ -21,7 +21,7 @@ public virtual Task InvokeAsync(IExecutionContext executionContext, bool a throw new InvalidOperationException(CSConstants.InnerHandlerNotSet); } - public virtual void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public virtual void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { if (this.InnerHandler != null) { diff --git a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/DefaultRetryPolicy.cs b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/DefaultRetryPolicy.cs index 6cfeefa..fb691bb 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/DefaultRetryPolicy.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/DefaultRetryPolicy.cs @@ -11,9 +11,9 @@ namespace Contentstack.Management.Core.Runtime.Pipeline.RetryHandler public partial class DefaultRetryPolicy : RetryPolicy { protected TimeSpan retryDelay { get; set; } - protected RetryConfiguration retryConfiguration; - protected NetworkErrorDetector networkErrorDetector; - protected RetryDelayCalculator delayCalculator; + protected RetryConfiguration retryConfiguration = null!; + protected NetworkErrorDetector networkErrorDetector = null!; + protected RetryDelayCalculator delayCalculator = null!; protected ICollection statusCodesToRetryOn = new HashSet { @@ -187,7 +187,7 @@ public bool ShouldRetryHttpStatusCode(HttpStatusCode statusCode, IRequestContext /// /// Gets the retry delay for an HTTP error. /// - public TimeSpan GetHttpRetryDelay(IRequestContext requestContext, Exception exception, HttpResponseHeaders? responseHeaders = null) + public TimeSpan GetHttpRetryDelay(IRequestContext requestContext, Exception? exception, HttpResponseHeaders? responseHeaders = null) { if (retryConfiguration == null) { diff --git a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryHandler.cs b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryHandler.cs index 5a8a204..086d78e 100644 --- a/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryHandler.cs +++ b/Contentstack.Management.Core/Runtime/Pipeline/RetryHandler/RetryHandler.cs @@ -17,12 +17,12 @@ public RetryHandler(RetryPolicy retryPolicy) this.networkErrorDetector = new NetworkErrorDetector(); } - public override async Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public override async Task InvokeAsync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { var requestContext = executionContext.RequestContext; var responseContext = executionContext.ResponseContext; bool shouldRetry = false; - Exception lastException = null; + Exception? lastException = null; do { @@ -98,11 +98,11 @@ public override async Task InvokeAsync(IExecutionContext executionContext, throw new ContentstackException("No response was return nor exception was thrown"); } - public override void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string apiVersion = null) + public override void InvokeSync(IExecutionContext executionContext, bool addAcceptMediaHeader = false, string? apiVersion = null) { var requestContext = executionContext.RequestContext; bool shouldRetry = false; - Exception lastException = null; + Exception? lastException = null; do { @@ -180,11 +180,11 @@ public override void InvokeSync(IExecutionContext executionContext, bool addAcce private void LogForError(IRequestContext requestContext, Exception exception) { var totalAttempts = requestContext.NetworkRetryCount + requestContext.HttpRetryCount + requestContext.Retries + 1; - LogManager.InfoFormat( + LogManager!.InfoFormat( "[RequestId: {0}] {1} making request {2}. Final attempt {3} failed. Network retries: {4}, HTTP retries: {5}.", requestContext.RequestId, exception.GetType().Name, - requestContext.service.ResourcePath, + requestContext.service!.ResourcePath, totalAttempts, requestContext.NetworkRetryCount, requestContext.HttpRetryCount); @@ -193,11 +193,11 @@ private void LogForError(IRequestContext requestContext, Exception exception) private void LogForRetry(IRequestContext requestContext, Exception exception) { var totalAttempts = requestContext.NetworkRetryCount + requestContext.HttpRetryCount + requestContext.Retries; - LogManager.InfoFormat( + LogManager!.InfoFormat( "[RequestId: {0}] {1} making request {2}. Retrying (attempt {3}). Network retries: {4}, HTTP retries: {5}.", requestContext.RequestId, exception.GetType().Name, - requestContext.service.ResourcePath, + requestContext.service!.ResourcePath, totalAttempts, requestContext.NetworkRetryCount, requestContext.HttpRetryCount); @@ -206,11 +206,11 @@ private void LogForRetry(IRequestContext requestContext, Exception exception) private void LogForNetworkRetry(IRequestContext requestContext, Exception exception, NetworkErrorInfo errorInfo) { var totalAttempts = requestContext.NetworkRetryCount + requestContext.HttpRetryCount + requestContext.Retries; - LogManager.InfoFormat( + LogManager!.InfoFormat( "[RequestId: {0}] Network error ({1}) making request {2}. Retrying (attempt {3}, network retry {4}).", requestContext.RequestId, errorInfo.ErrorType, - requestContext.service.ResourcePath, + requestContext.service!.ResourcePath, totalAttempts, requestContext.NetworkRetryCount); } @@ -218,11 +218,11 @@ private void LogForNetworkRetry(IRequestContext requestContext, Exception except private void LogForHttpRetry(IRequestContext requestContext, System.Net.HttpStatusCode statusCode) { var totalAttempts = requestContext.NetworkRetryCount + requestContext.HttpRetryCount + requestContext.Retries; - LogManager.InfoFormat( + LogManager!.InfoFormat( "[RequestId: {0}] HTTP error ({1}) making request {2}. Retrying (attempt {3}, HTTP retry {4}).", requestContext.RequestId, statusCode, - requestContext.service.ResourcePath, + requestContext.service!.ResourcePath, totalAttempts, requestContext.HttpRetryCount); } diff --git a/Contentstack.Management.Core/Services/ContentstackService.cs b/Contentstack.Management.Core/Services/ContentstackService.cs index f9b5d0b..6dc10d1 100644 --- a/Contentstack.Management.Core/Services/ContentstackService.cs +++ b/Contentstack.Management.Core/Services/ContentstackService.cs @@ -29,7 +29,7 @@ internal class ContentstackService : IContentstackService #endregion #region Constructor - internal ContentstackService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack = null, ParameterCollection collection = null) + internal ContentstackService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack? stack = null, ParameterCollection? collection = null) { if (serializerOptions == null) { @@ -115,11 +115,11 @@ public IDictionary PathResources } } - public string ResourcePath { get; set; } - public byte[] ByteContent { get; set; } - public HttpContent Content { get; set; } + public string ResourcePath { get; set; } = null!; + public byte[]? ByteContent { get; set; } + public HttpContent? Content { get; set; } public string HttpMethod { get; set; } = "GET"; - public string ManagementToken { get; set; } + public string? ManagementToken { get; set; } public void AddQueryResource(string queryResource, string value) { @@ -138,7 +138,7 @@ public string GetHeaderValue(string headerName) { ThrowIfDisposed(); - string headerValue; + string? headerValue; if (headers.TryGetValue(headerName, out headerValue)) return headerValue; @@ -163,7 +163,7 @@ protected virtual bool ShouldSetContentType() return true; } - public virtual IHttpRequest CreateHttpRequest(HttpClient httpClient, ContentstackClientOptions config, bool addAcceptMediaHeader = false, string apiVersion = null) + public virtual IHttpRequest CreateHttpRequest(HttpClient httpClient, ContentstackClientOptions config, bool addAcceptMediaHeader = false, string? apiVersion = null) { ThrowIfDisposed(); diff --git a/Contentstack.Management.Core/Services/IContentstackService.cs b/Contentstack.Management.Core/Services/IContentstackService.cs index 954e4a4..acf6190 100644 --- a/Contentstack.Management.Core/Services/IContentstackService.cs +++ b/Contentstack.Management.Core/Services/IContentstackService.cs @@ -21,7 +21,7 @@ public interface IContentstackService : IDisposable /// /// Management Tokens are tokens that provide you with read-write access to the content of your stack. /// - string ManagementToken { get; set; } + string? ManagementToken { get; set; } /// /// Returns a dictionary of the parameters included in this request. @@ -86,7 +86,7 @@ IDictionary PathResources /// /// Gets and Sets the content for this request. /// - HttpContent Content + HttpContent? Content { get; set; @@ -97,7 +97,7 @@ HttpContent Content /// string GetHeaderValue(string headerName); - IHttpRequest CreateHttpRequest(HttpClient httpClient, ContentstackClientOptions config, bool addAcceptMediaHeader = false, string apiVersion = null); + IHttpRequest CreateHttpRequest(HttpClient httpClient, ContentstackClientOptions config, bool addAcceptMediaHeader = false, string? apiVersion = null); void OnResponse(IResponse httpResponse, ContentstackClientOptions config); bool HasRequestBody(); } diff --git a/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs b/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs index e75aa17..b116d04 100644 --- a/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs +++ b/Contentstack.Management.Core/Services/Models/CreateUpdateFolderService.cs @@ -9,18 +9,18 @@ namespace Contentstack.Management.Core.Services.Models internal class CreateUpdateFolderService : ContentstackService { private readonly string _name; - private readonly string _parentUId; + private readonly string? _parentUId; #region Internal internal CreateUpdateFolderService( Core.Models.Stack stack, string name, - string folderUid = null, - string parentUId = null, - JsonSerializerOptions stjOptions = null) + string? folderUid = null, + string? parentUId = null, + JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs b/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs index ac1a7ac..8c7796b 100644 --- a/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs +++ b/Contentstack.Management.Core/Services/Models/CreateUpdateService.cs @@ -12,10 +12,10 @@ internal class CreateUpdateService : ContentstackService private readonly string fieldName; #region Internal - internal CreateUpdateService(Core.Models.Stack stack, string resourcePath, T dataModel, string fieldName, string httpMethod = "POST", ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal CreateUpdateService(Core.Models.Stack stack, string resourcePath, T dataModel, string fieldName, string httpMethod = "POST", ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection: collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } @@ -44,7 +44,7 @@ internal CreateUpdateService(Core.Models.Stack stack, string resourcePath, T dat public override void ContentBody() { - var requestData = new Dictionary + var requestData = new Dictionary { { fieldName, _typedModel } }; diff --git a/Contentstack.Management.Core/Services/Models/DeleteService.cs b/Contentstack.Management.Core/Services/Models/DeleteService.cs index 715139b..db8f6d5 100644 --- a/Contentstack.Management.Core/Services/Models/DeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/DeleteService.cs @@ -11,10 +11,10 @@ internal class DeleteService: ContentstackService internal string fieldName; internal T model; - internal DeleteService(Core.Models.Stack stack, string resourcePath, string fieldName, T model, ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal DeleteService(Core.Models.Stack stack, string resourcePath, string fieldName, T model, ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection: collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } @@ -39,7 +39,7 @@ internal DeleteService(Core.Models.Stack stack, string resourcePath, string fiel public override void ContentBody() { - var requestData = new Dictionary + var requestData = new Dictionary { { fieldName, model } }; diff --git a/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs b/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs index 6ed5953..052e730 100644 --- a/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/FetchDeleteService.cs @@ -9,10 +9,10 @@ internal class FetchDeleteService: ContentstackService { #region Internal - internal FetchDeleteService(Core.Models.Stack stack, string resourcePath, string httpMethod = "GET", ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal FetchDeleteService(Core.Models.Stack stack, string resourcePath, string httpMethod = "GET", ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection: collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs b/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs index 170ada6..982ae8b 100644 --- a/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs +++ b/Contentstack.Management.Core/Services/Models/FetchReferencesService.cs @@ -7,10 +7,10 @@ namespace Contentstack.Management.Core.Services.Models { internal class FetchReferencesService : ContentstackService { - internal FetchReferencesService(Core.Models.Stack stack, string resourcePath = null, ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal FetchReferencesService(Core.Models.Stack stack, string? resourcePath = null, ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs b/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs index 8720875..534497b 100644 --- a/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs +++ b/Contentstack.Management.Core/Services/Models/GlobalFieldFetchDeleteService.cs @@ -10,15 +10,15 @@ namespace Contentstack.Management.Core.Services.Models /// internal class GlobalFieldFetchDeleteService : ContentstackService { - private readonly string _apiVersion; + private readonly string? _apiVersion; /// /// Initializes a new instance of the class. /// - internal GlobalFieldFetchDeleteService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, string apiVersion, string httpMethod = "GET", ParameterCollection collection = null) + internal GlobalFieldFetchDeleteService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, string? apiVersion, string httpMethod = "GET", ParameterCollection? collection = null) : base(serializerOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs b/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs index 6d2b45d..8ab929d 100644 --- a/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs +++ b/Contentstack.Management.Core/Services/Models/GlobalFieldService.cs @@ -14,15 +14,15 @@ internal class GlobalFieldService : ContentstackService { private readonly ContentModelling _typedModel; private readonly string fieldName; - private readonly string _apiVersion; + private readonly string? _apiVersion; /// /// Initializes a new instance of the class. /// - internal GlobalFieldService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, ContentModelling dataModel, string fieldName, string apiVersion, string httpMethod = "POST", ParameterCollection collection = null) + internal GlobalFieldService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, ContentModelling dataModel, string fieldName, string? apiVersion, string httpMethod = "POST", ParameterCollection? collection = null) : base(serializerOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } @@ -59,7 +59,7 @@ internal GlobalFieldService(JsonSerializerOptions serializerOptions, Core.Models public override void ContentBody() { - var requestData = new Dictionary + var requestData = new Dictionary { { fieldName, _typedModel } }; diff --git a/Contentstack.Management.Core/Services/Models/ImportExportService.cs b/Contentstack.Management.Core/Services/Models/ImportExportService.cs index 0b6c574..bbfc682 100644 --- a/Contentstack.Management.Core/Services/Models/ImportExportService.cs +++ b/Contentstack.Management.Core/Services/Models/ImportExportService.cs @@ -7,7 +7,7 @@ namespace Contentstack.Management.Core.Services.Models { internal class ImportExportService : ContentstackService { - internal ImportExportService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, bool isImport = false, string httpMethod = "GET", ParameterCollection collection = null) + internal ImportExportService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, bool isImport = false, string httpMethod = "GET", ParameterCollection? collection = null) : base(serializerOptions, stack: stack, collection: collection) { if (stack.APIKey == null) diff --git a/Contentstack.Management.Core/Services/Models/LocaleService.cs b/Contentstack.Management.Core/Services/Models/LocaleService.cs index 0e0a373..6a9b6ce 100644 --- a/Contentstack.Management.Core/Services/Models/LocaleService.cs +++ b/Contentstack.Management.Core/Services/Models/LocaleService.cs @@ -6,10 +6,10 @@ namespace Contentstack.Management.Core.Services.Models { internal class LocaleService: ContentstackService { - internal LocaleService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath = null) + internal LocaleService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string? resourcePath = null) : base(serializerOptions, stack: stack) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/LocalizationService.cs b/Contentstack.Management.Core/Services/Models/LocalizationService.cs index 06e852f..d2e9cac 100644 --- a/Contentstack.Management.Core/Services/Models/LocalizationService.cs +++ b/Contentstack.Management.Core/Services/Models/LocalizationService.cs @@ -6,14 +6,14 @@ namespace Contentstack.Management.Core.Services.Models { - internal class LocalizationService : ContentstackService + internal class LocalizationService : ContentstackService where T : class { - private readonly T _typedModel; + private readonly T? _typedModel; private readonly string _fieldName; private readonly bool _shouldUnlocalize; #region Internal - internal LocalizationService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, T dataModel, string fieldName, ParameterCollection collection = null, bool shouldUnlocalize = false) + internal LocalizationService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string resourcePath, T? dataModel, string fieldName, ParameterCollection? collection = null, bool shouldUnlocalize = false) : base(serializerOptions, stack: stack, collection) { if (stack.APIKey == null) @@ -48,7 +48,7 @@ public override void ContentBody() { if (!_shouldUnlocalize) { - var wrapper = new Dictionary { { _fieldName, _typedModel } }; + var wrapper = new Dictionary { { _fieldName, _typedModel! } }; this.ByteContent = JsonSerializer.SerializeToUtf8Bytes(wrapper, SerializerOptions); } } diff --git a/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs b/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs index 9406200..694dbbc 100644 --- a/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs +++ b/Contentstack.Management.Core/Services/Models/PublishUnpublishService.cs @@ -9,13 +9,13 @@ namespace Contentstack.Management.Core.Services.Models { internal class PublishUnpublishService : ContentstackService { - internal string locale; - internal string fieldName; - internal PublishUnpublishDetails details; - internal PublishUnpublishService(Core.Models.Stack stack, PublishUnpublishDetails details, string resourcePath, string fieldName, string locale = null, JsonSerializerOptions stjOptions = null) + internal string? locale; + internal string fieldName = null!; + internal PublishUnpublishDetails details = null!; + internal PublishUnpublishService(Core.Models.Stack stack, PublishUnpublishDetails details, string resourcePath, string fieldName, string? locale = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Models/UploadService.cs b/Contentstack.Management.Core/Services/Models/UploadService.cs index 95987e9..c07ec5e 100644 --- a/Contentstack.Management.Core/Services/Models/UploadService.cs +++ b/Contentstack.Management.Core/Services/Models/UploadService.cs @@ -12,10 +12,10 @@ internal class UploadService: ContentstackService { private readonly IUploadInterface _uploadInterface; - internal UploadService(Core.Models.Stack stack, string resourcePath, IUploadInterface uploadInterface, string httpMethod = "POST", ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal UploadService(Core.Models.Stack stack, string resourcePath, IUploadInterface uploadInterface, string httpMethod = "POST", ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } @@ -41,7 +41,7 @@ public override void ContentBody() HttpContent content = _uploadInterface.GetHttpContent(); Headers.Remove("Content-Type"); - this.Headers.Add("Content-Type", content.Headers.ContentType.ToString()); + this.Headers.Add("Content-Type", content.Headers.ContentType!.ToString()); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(_uploadInterface.ContentType); this.Content = content; } diff --git a/Contentstack.Management.Core/Services/Models/VariantContentTypeLinkService.cs b/Contentstack.Management.Core/Services/Models/VariantContentTypeLinkService.cs index 7026882..b4ec635 100644 --- a/Contentstack.Management.Core/Services/Models/VariantContentTypeLinkService.cs +++ b/Contentstack.Management.Core/Services/Models/VariantContentTypeLinkService.cs @@ -9,7 +9,7 @@ namespace Contentstack.Management.Core.Services.Models internal class VariantContentTypeLinkService : ContentstackService { private readonly List _contentTypeUids; - private readonly string _variantGroupUid; + private readonly string? _variantGroupUid; private readonly bool _isLink; internal VariantContentTypeLinkService( @@ -17,9 +17,9 @@ internal VariantContentTypeLinkService( Core.Models.Stack stack, string resourcePath, List contentTypeUids, - string variantGroupUid, + string? variantGroupUid, bool isLink, - ParameterCollection collection = null + ParameterCollection? collection = null ) : base(serializerOptions, stack, collection) { diff --git a/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs b/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs index e6adaa0..94d4cef 100644 --- a/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs +++ b/Contentstack.Management.Core/Services/Models/Versioning/VersionService.cs @@ -10,16 +10,16 @@ namespace Contentstack.Management.Core.Services.Models.Versioning internal class VersionService : ContentstackService { #region Internal - internal string fieldName; + internal string fieldName = null!; - internal string name; - internal string locale; + internal string? name; + internal string? locale; internal bool force; - internal VersionService(Core.Models.Stack stack, string resourcePath, string httpMethod, string fieldName, ParameterCollection collection = null, JsonSerializerOptions stjOptions = null) + internal VersionService(Core.Models.Stack stack, string resourcePath, string httpMethod, string fieldName, ParameterCollection? collection = null, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? stack?.client?.SerializerOptions ?? new JsonSerializerOptions(), stack: stack, collection) { - if (stack.APIKey == null) + if (stack!.APIKey == null) { throw new ArgumentNullException("stack", CSConstants.MissingAPIKey); } diff --git a/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs b/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs index 859ca10..843bf89 100644 --- a/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs +++ b/Contentstack.Management.Core/Services/Organization/GetOrganizations.cs @@ -7,7 +7,7 @@ internal class GetOrganizations: ContentstackService { #region Internal - internal GetOrganizations(JsonSerializerOptions serializerOptions, ParameterCollection collection, string uid = null) : base(serializerOptions, collection: collection) + internal GetOrganizations(JsonSerializerOptions serializerOptions, ParameterCollection? collection, string? uid = null) : base(serializerOptions, collection: collection) { this.ResourcePath = "organizations"; diff --git a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs index c2f9fd2..74b800a 100644 --- a/Contentstack.Management.Core/Services/Organization/OrgRoles.cs +++ b/Contentstack.Management.Core/Services/Organization/OrgRoles.cs @@ -9,7 +9,7 @@ internal class OrganizationRolesService : ContentstackService { #region Internal - internal OrganizationRolesService(string uid, ParameterCollection collection, JsonSerializerOptions stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), collection: collection) + internal OrganizationRolesService(string? uid, ParameterCollection? collection, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), collection: collection) { if (string.IsNullOrEmpty(uid)) { diff --git a/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs b/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs index 8f32920..b8a0451 100644 --- a/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs +++ b/Contentstack.Management.Core/Services/Organization/OrganizationStackService.cs @@ -9,7 +9,7 @@ internal class OrganizationStackService : ContentstackService { #region Internal - internal OrganizationStackService(JsonSerializerOptions serializerOptions, string uid, ParameterCollection collection = null) : base(serializerOptions, collection: collection) + internal OrganizationStackService(JsonSerializerOptions serializerOptions, string? uid, ParameterCollection? collection = null) : base(serializerOptions, collection: collection) { if (string.IsNullOrEmpty(uid)) diff --git a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs index ccb3792..e17bf2c 100644 --- a/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/ResendInvitationService.cs @@ -8,7 +8,7 @@ internal class ResendInvitationService : ContentstackService { #region Internal - internal ResendInvitationService(JsonSerializerOptions serializerOptions, string uid, string shareUid) : base(serializerOptions) + internal ResendInvitationService(JsonSerializerOptions serializerOptions, string? uid, string shareUid) : base(serializerOptions) { if (string.IsNullOrEmpty(uid)) { diff --git a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs index 65cbe13..3d17a99 100644 --- a/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Organization/TransferOwnershipService.cs @@ -10,7 +10,7 @@ internal class TransferOwnershipService : ContentstackService private readonly string _email; #region Internal - internal TransferOwnershipService(JsonSerializerOptions serializerOptions, string uid, string email) : base(serializerOptions) + internal TransferOwnershipService(JsonSerializerOptions serializerOptions, string? uid, string email) : base(serializerOptions) { if (string.IsNullOrEmpty(uid)) { diff --git a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs index 03c1880..22a517c 100644 --- a/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs +++ b/Contentstack.Management.Core/Services/Organization/UserInvitationService.cs @@ -10,12 +10,12 @@ namespace Contentstack.Management.Core.Services.Organization { internal class UserInvitationService : ContentstackService { - private List _organizationInvite; - private Dictionary> _stackInvite; - private List _removeUsers; + private List? _organizationInvite; + private Dictionary>? _stackInvite; + private List? _removeUsers; #region Internal - internal UserInvitationService(JsonSerializerOptions serializerOptions, string uid, string httpMethod = "GET", ParameterCollection collection = null) : base(serializerOptions, collection: collection) + internal UserInvitationService(JsonSerializerOptions serializerOptions, string? uid, string httpMethod = "GET", ParameterCollection? collection = null) : base(serializerOptions, collection: collection) { if (string.IsNullOrEmpty(uid)) { @@ -100,9 +100,9 @@ private void WriteAddInvite(Stream stream) writer.WriteStartObject(); foreach (UserInvitation invitation in this._organizationInvite) { - writer.WritePropertyName(invitation.Email); + writer.WritePropertyName(invitation.Email!); writer.WriteStartArray(); - foreach (string role in invitation.Roles) + foreach (string role in invitation.Roles!) writer.WriteStringValue(role); writer.WriteEndArray(); } @@ -127,13 +127,13 @@ private void WriteAddInvite(Stream stream) private void WriteStackInvites(Utf8JsonWriter writer, string key) { - foreach (UserInvitation invitation in this._stackInvite[key]) + foreach (UserInvitation invitation in this._stackInvite![key]) { - writer.WritePropertyName(invitation.Email); + writer.WritePropertyName(invitation.Email!); writer.WriteStartObject(); writer.WritePropertyName(key); writer.WriteStartArray(); - foreach (string role in invitation.Roles) + foreach (string role in invitation.Roles!) writer.WriteStringValue(role); writer.WriteEndArray(); writer.WriteEndObject(); diff --git a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkAddItemsService.cs b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkAddItemsService.cs index 4f93420..a62e1b9 100644 --- a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkAddItemsService.cs +++ b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkAddItemsService.cs @@ -11,7 +11,7 @@ namespace Contentstack.Management.Core.Services.Stack.BulkOperation internal class BulkAddItemsService : ContentstackService { private readonly BulkAddItemsData _data; - private readonly string _bulkVersion; + private readonly string? _bulkVersion; /// /// Initializes a new instance of the class. @@ -20,7 +20,7 @@ internal class BulkAddItemsService : ContentstackService /// The stack instance. /// The add items data. /// The bulk version. - public BulkAddItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkAddItemsData data, string bulkVersion = null) + public BulkAddItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkAddItemsData data, string? bulkVersion = null) : base(serializerOptions, stack) { _data = data ?? throw new ArgumentNullException(nameof(data)); diff --git a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkJobStatusService.cs b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkJobStatusService.cs index e920075..bc53a0b 100644 --- a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkJobStatusService.cs +++ b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkJobStatusService.cs @@ -10,7 +10,7 @@ namespace Contentstack.Management.Core.Services.Stack.BulkOperation internal class BulkJobStatusService : ContentstackService { private readonly string _jobId; - private readonly string _bulkVersion; + private readonly string? _bulkVersion; /// /// Initializes a new instance of the class. @@ -19,7 +19,7 @@ internal class BulkJobStatusService : ContentstackService /// The stack instance. /// The job ID. /// The bulk version. - public BulkJobStatusService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, string jobId, string bulkVersion = null) + public BulkJobStatusService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, string jobId, string? bulkVersion = null) : base(serializerOptions, stack) { _jobId = jobId ?? throw new ArgumentNullException(nameof(jobId)); diff --git a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkReleaseItemsService.cs b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkReleaseItemsService.cs index 47f486b..3deb296 100644 --- a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkReleaseItemsService.cs +++ b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkReleaseItemsService.cs @@ -11,7 +11,7 @@ namespace Contentstack.Management.Core.Services.Stack.BulkOperation internal class BulkReleaseItemsService : ContentstackService { private readonly BulkReleaseItemsData _data; - private readonly string _bulkVersion; + private readonly string? _bulkVersion; /// /// Initializes a new instance of the class. @@ -20,7 +20,7 @@ internal class BulkReleaseItemsService : ContentstackService /// The stack instance. /// The release items data. /// The bulk version. - public BulkReleaseItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkReleaseItemsData data, string bulkVersion = null) + public BulkReleaseItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkReleaseItemsData data, string? bulkVersion = null) : base(serializerOptions, stack) { _data = data ?? throw new ArgumentNullException(nameof(data)); diff --git a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkUpdateItemsService.cs b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkUpdateItemsService.cs index eb2b339..566da47 100644 --- a/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkUpdateItemsService.cs +++ b/Contentstack.Management.Core/Services/Stack/BulkOperation/BulkUpdateItemsService.cs @@ -11,7 +11,7 @@ namespace Contentstack.Management.Core.Services.Stack.BulkOperation internal class BulkUpdateItemsService : ContentstackService { private readonly BulkAddItemsData _data; - private readonly string _bulkVersion; + private readonly string? _bulkVersion; /// /// Initializes a new instance of the class. @@ -20,7 +20,7 @@ internal class BulkUpdateItemsService : ContentstackService /// The stack instance. /// The update items data. /// The bulk version. - public BulkUpdateItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkAddItemsData data, string bulkVersion = null) + public BulkUpdateItemsService(JsonSerializerOptions serializerOptions, Contentstack.Management.Core.Models.Stack stack, BulkAddItemsData data, string? bulkVersion = null) : base(serializerOptions, stack) { _data = data ?? throw new ArgumentNullException(nameof(data)); diff --git a/Contentstack.Management.Core/Services/Stack/FetchStackService.cs b/Contentstack.Management.Core/Services/Stack/FetchStackService.cs index 0978cc4..c74ec74 100644 --- a/Contentstack.Management.Core/Services/Stack/FetchStackService.cs +++ b/Contentstack.Management.Core/Services/Stack/FetchStackService.cs @@ -8,7 +8,7 @@ internal class FetchStackService : ContentstackService { #region Internal - internal FetchStackService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, ParameterCollection collection = null) + internal FetchStackService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, ParameterCollection? collection = null) : base(serializerOptions, stack, collection) { this.ResourcePath = "stacks"; diff --git a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs index 78b8eaf..bce3219 100644 --- a/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackCreateUpdateService.cs @@ -8,17 +8,17 @@ namespace Contentstack.Management.Core.Services.Stack internal class StackCreateUpdateService : ContentstackService { private readonly string _name; - private readonly string _masterLocale; - private readonly string _description; + private readonly string? _masterLocale; + private readonly string? _description; #region Internal internal StackCreateUpdateService( JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string name, - string masterLocale = null, - string description = null, - string organizationUid = null) + string? masterLocale = null, + string? description = null, + string? organizationUid = null) : base(serializerOptions, stack) { this.ResourcePath = "/stacks"; diff --git a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs index 3f36e52..0b14be7 100644 --- a/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackOwnershipService.cs @@ -9,7 +9,7 @@ internal class StackOwnershipService : ContentstackService private readonly string _email; #region Internal - internal StackOwnershipService(Core.Models.Stack stack, string email, JsonSerializerOptions stjOptions = null) + internal StackOwnershipService(Core.Models.Stack stack, string email, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (string.IsNullOrEmpty(stack.APIKey)) diff --git a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs index ed97327..ca7ffb2 100644 --- a/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackSettingsService.cs @@ -11,9 +11,9 @@ internal class StackSettingsService: ContentstackService { #region Internal - private readonly StackSettings _settings; + private readonly StackSettings? _settings; - internal StackSettingsService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string method = "GET", StackSettings settings = null) : base(serializerOptions, stack) + internal StackSettingsService(JsonSerializerOptions serializerOptions, Core.Models.Stack stack, string method = "GET", StackSettings? settings = null) : base(serializerOptions, stack) { if (stack.APIKey == null) { diff --git a/Contentstack.Management.Core/Services/Stack/StackShareService.cs b/Contentstack.Management.Core/Services/Stack/StackShareService.cs index e9e2d49..93a6bc3 100644 --- a/Contentstack.Management.Core/Services/Stack/StackShareService.cs +++ b/Contentstack.Management.Core/Services/Stack/StackShareService.cs @@ -9,11 +9,11 @@ namespace Contentstack.Management.Core.Services.Stack { internal class StackShareService : ContentstackService { - private List _invitations; + private List? _invitations; - private string _removeUser; + private string? _removeUser; - internal StackShareService(Core.Models.Stack stack, JsonSerializerOptions stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), stack) + internal StackShareService(Core.Models.Stack stack, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (string.IsNullOrEmpty(stack.APIKey)) { @@ -44,8 +44,8 @@ public override void ContentBody() { emails = _invitations.Select(u => u.Email).ToArray(), roles = _invitations.ToDictionary( - invitation => invitation.Email, - invitation => invitation.Roles.ToArray() + invitation => invitation.Email!, + invitation => invitation.Roles!.ToArray() ) }; } diff --git a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs index b75ec15..866b9cd 100644 --- a/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs +++ b/Contentstack.Management.Core/Services/Stack/UpdateUserRoleService.cs @@ -13,7 +13,7 @@ internal class UpdateUserRoleService : ContentstackService #region Internal private readonly List _users; - internal UpdateUserRoleService(Core.Models.Stack stack, List userInvitation, JsonSerializerOptions stjOptions = null) + internal UpdateUserRoleService(Core.Models.Stack stack, List userInvitation, JsonSerializerOptions? stjOptions = null) : base(stjOptions ?? new JsonSerializerOptions(), stack) { if (userInvitation == null) @@ -35,8 +35,8 @@ public override void ContentBody() var requestData = new { users = _users.ToDictionary( - invitation => invitation.Uid, - invitation => invitation.Roles.ToArray() + invitation => invitation.Uid!, + invitation => invitation.Roles!.ToArray() ) }; diff --git a/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs b/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs index 79dd006..0432885 100644 --- a/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs +++ b/Contentstack.Management.Core/Services/User/GetLoggedInUserService.cs @@ -6,7 +6,7 @@ namespace Contentstack.Management.Core.Services.User { internal class GetLoggedInUserService: ContentstackService { - public GetLoggedInUserService(JsonSerializerOptions serializerOptions, ParameterCollection collection): base(serializerOptions, collection: collection) + public GetLoggedInUserService(JsonSerializerOptions serializerOptions, ParameterCollection? collection): base(serializerOptions, collection: collection) { this.ResourcePath = "user"; } diff --git a/Contentstack.Management.Core/Services/User/LoginService.cs b/Contentstack.Management.Core/Services/User/LoginService.cs index 450a671..e606d77 100644 --- a/Contentstack.Management.Core/Services/User/LoginService.cs +++ b/Contentstack.Management.Core/Services/User/LoginService.cs @@ -12,12 +12,12 @@ namespace Contentstack.Management.Core.Services.User internal class LoginService : ContentstackService { #region Private - private readonly ICredentials _credentials; - private readonly string _token; + private readonly ICredentials _credentials = null!; + private readonly string? _token; #endregion #region Constructor - internal LoginService(JsonSerializerOptions serializerOptions, ICredentials credentials, string token = null, string mfaSecret = null): base(serializerOptions) + internal LoginService(JsonSerializerOptions serializerOptions, ICredentials credentials, string? token = null, string? mfaSecret = null): base(serializerOptions) { this.HttpMethod = "POST"; this.ResourcePath = "user-session"; @@ -45,7 +45,7 @@ internal LoginService(JsonSerializerOptions serializerOptions, ICredentials cred public override void ContentBody() { - var credential = _credentials as NetworkCredential; + var credential = (_credentials as NetworkCredential)!; using var ms = new MemoryStream(); using (var writer = new Utf8JsonWriter(ms)) { diff --git a/Contentstack.Management.Core/Utils/FieldJsonConverter.cs b/Contentstack.Management.Core/Utils/FieldJsonConverter.cs index f92c15f..a7a8b59 100644 --- a/Contentstack.Management.Core/Utils/FieldJsonConverter.cs +++ b/Contentstack.Management.Core/Utils/FieldJsonConverter.cs @@ -10,7 +10,7 @@ namespace Contentstack.Management.Core.Utils /// public class FieldJsonConverter : JsonConverter { - public override Field Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) + public override Field? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType == JsonTokenType.Null) return null; @@ -19,7 +19,7 @@ public override Field Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe var root = doc.RootElement; var targetType = ResolveConcreteType(root); var innerOpts = options.WithoutConverter(); - return (Field)JsonSerializer.Deserialize(root.GetRawText(), targetType, innerOpts); + return (Field?)JsonSerializer.Deserialize(root.GetRawText(), targetType, innerOpts); } public override void Write(Utf8JsonWriter writer, Field value, JsonSerializerOptions options) diff --git a/Contentstack.Management.Core/contentstack.management.core.csproj b/Contentstack.Management.Core/contentstack.management.core.csproj index 8e04e7a..9959fa9 100644 --- a/Contentstack.Management.Core/contentstack.management.core.csproj +++ b/Contentstack.Management.Core/contentstack.management.core.csproj @@ -66,7 +66,6 @@ - @@ -86,7 +85,7 @@ - +