From be2495011f1c0def18413be1ac1195221886fff6 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Tue, 25 Nov 2025 15:03:16 +0530 Subject: [PATCH 1/3] Refactor console messages in ModelGenerator and Program for improved readability and maintainability. Replace hardcoded strings with message constants. --- contentstack.model.generator/Messages.cs | 49 ++++++++++++++++ .../ModelGenerator.cs | 56 +++++++++---------- contentstack.model.generator/Program.cs | 17 +++--- 3 files changed, 86 insertions(+), 36 deletions(-) create mode 100644 contentstack.model.generator/Messages.cs diff --git a/contentstack.model.generator/Messages.cs b/contentstack.model.generator/Messages.cs new file mode 100644 index 0000000..d3ce213 --- /dev/null +++ b/contentstack.model.generator/Messages.cs @@ -0,0 +1,49 @@ +namespace contentstack.model.generator +{ + /// + /// Centralized console messages for the Contentstack Model Generator + /// + public static class Messages + { + // Error Messages + public const string UnexpectedError = "Unexpected error occurred. See logs for details."; + public const string OperationFailed = "Operation failed. See error details in logs."; + public const string ApiCommunicationError = "API communication error. Check your network or configuration and try again."; + public const string AuthenticationFailed = "Authentication failed. Verify your API key and auth token and try again."; + + // Path Messages + public static string NoPathSpecified(string path) => $"No path specified. Generating files in the current working directory: {path}."; + public static string OutputPathSpecified(string path) => $"Output path specified. Generating files at: {path}."; + public static string OutputPathNotFound(string path) => $"Output path not found. Creating: {path}."; + public static string OpeningOutputDirectory(string directory) => $"Opening output directory: {directory}."; + + // Content Types Messages + public const string FetchingStackDetails = "Fetching stack details for the provided API key."; + public static string FetchingContentTypes(string stackName) => $"Fetching content types from {stackName} stack."; + public static string FoundContentTypes(int count) => $"Found {count} content types."; + public static string FetchedContentTypes(int count) => $"Fetched {count} content types."; + public static string TotalContentTypesFetched(int count) => $"Total content types fetched: {count}."; + + // Global Fields Messages + public static string FetchingGlobalFields(string stackName) => $"Fetching global fields from stack: {stackName}."; + public static string FoundGlobalFields(int count) => $"Found {count} global fields."; + public static string FetchedGlobalFields(int count) => $"Fetched {count} global fields."; + public static string TotalGlobalFieldsFetched(int count) => $"Total global fields fetched: {count}."; + + // File Generation Messages + public const string GeneratingFiles = "Generating files from content types."; + public const string FilesCreatedSuccessfully = "Files created successfully."; + public static string SkippingFile(string fileName) => $"Skipping {fileName} file."; + public static string AddingFile(string fileName, string directory) => $"Adding {fileName} file to {directory}"; + + // Field Messages + public static string FieldDataType(string dataType) => $"Field data type: {dataType}."; + + // Modular Blocks and Groups Messages + public static string ExtractingModularBlocksInContentType(string contentTypeName) => $"Extracting modular blocks in {contentTypeName} Content Type"; + public static string ExtractingGroupsInContentType(string contentTypeName) => $"Extracting groups in {contentTypeName} Content Type"; + public static string ExtractingModularBlocksInGroup(string groupName) => $"Extracting modular blocks in {groupName} group."; + public static string ExtractingGroupsInGroup(string groupName) => $"Extracting groups in {groupName} group."; + } +} + diff --git a/contentstack.model.generator/ModelGenerator.cs b/contentstack.model.generator/ModelGenerator.cs index 9c2890b..518762a 100644 --- a/contentstack.model.generator/ModelGenerator.cs +++ b/contentstack.model.generator/ModelGenerator.cs @@ -150,15 +150,15 @@ public async Task OnExecute(CommandLineApplication app, IConsole console) try { - Console.WriteLine($"Fetching Stack details for API Key {ApiKey}"); + Console.WriteLine(Messages.FetchingStackDetails); stack = await client.GetStack(); } catch (Exception e) { Console.WriteLine(e); Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine("There was an error communicating with the Contentstack API: " + e.Message); - Console.Error.WriteLine("Please verify that your api key and authtoken are correct"); + Console.Error.WriteLine(Messages.ApiCommunicationError); + Console.Error.WriteLine(Messages.AuthenticationFailed); return Program.ERROR; } @@ -166,11 +166,11 @@ public async Task OnExecute(CommandLineApplication app, IConsole console) if (string.IsNullOrEmpty(Path)) { path = Directory.GetCurrentDirectory(); - Console.WriteLine($"No path specified, creating files in current working directory {path}"); + Console.WriteLine(Messages.NoPathSpecified(path)); } else { - Console.WriteLine($"Path specified. Files will be created at {Path}"); + Console.WriteLine(Messages.OutputPathSpecified(Path)); path = Path; } path = $"{path}/Models"; @@ -178,45 +178,45 @@ public async Task OnExecute(CommandLineApplication app, IConsole console) try { - Console.WriteLine($"Fetching Content Types from {stack.Name}"); + Console.WriteLine(Messages.FetchingContentTypes(stack.Name)); var totalCount = await getContentTypes(client, 0); var skip = 100; - Console.WriteLine($"Found {totalCount} Content Types ."); + Console.WriteLine(Messages.FoundContentTypes(totalCount)); while (totalCount > skip) { - Console.WriteLine($"{skip} Content Types Fetched."); + Console.WriteLine(Messages.FetchedContentTypes(skip)); totalCount = await getContentTypes(client, skip); skip += 100; } - Console.WriteLine($"Total {totalCount} Content Types fetched."); + Console.WriteLine(Messages.TotalContentTypesFetched(totalCount)); CreateEmbeddedObjectClass(Namespace, dir); - Console.WriteLine($"Fetching Global Fields from {stack.Name}"); + Console.WriteLine(Messages.FetchingGlobalFields(stack.Name)); totalCount = await getGlobalFields(client, 0); skip = 100; - Console.WriteLine($"Found {totalCount} Global Fields."); + Console.WriteLine(Messages.FoundGlobalFields(totalCount)); while (totalCount > skip) { - Console.WriteLine($"{skip} Global Fields Fetched."); + Console.WriteLine(Messages.FetchedGlobalFields(skip)); totalCount = await getGlobalFields(client, skip); skip += 100; } - Console.WriteLine($"Total {totalCount} Global Fields fetched."); + Console.WriteLine(Messages.TotalGlobalFieldsFetched(totalCount)); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine("There was an error communicating with the Contentstack API: " + e.Message); - Console.Error.WriteLine("Please verify that your api key and authtoken are correct"); + Console.Error.WriteLine(Messages.ApiCommunicationError); + Console.Error.WriteLine(Messages.AuthenticationFailed); return Program.ERROR; } Console.ResetColor(); Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"Generating files from content type"); + Console.WriteLine(Messages.GeneratingFiles); Console.ResetColor(); Console.ForegroundColor = ConsoleColor.DarkYellow; @@ -231,9 +231,9 @@ public async Task OnExecute(CommandLineApplication app, IConsole console) } Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine($"Files successfully created!"); + Console.WriteLine(Messages.FilesCreatedSuccessfully); Console.ResetColor(); - Console.WriteLine($"Opening {dir.FullName}"); + Console.WriteLine(Messages.OpeningOutputDirectory(dir.FullName)); OpenFolderatPath(dir.FullName); // Logout from OAuth if OAuth was used @@ -306,7 +306,7 @@ private string GetDatatype(Field field, string contentTypeName) case "group": return GetDataTypeForGroup(field, contentTypeName); default: - Console.WriteLine(field.DataType); + Console.WriteLine(Messages.FieldDataType(field.DataType)); break; } return "object"; @@ -625,7 +625,7 @@ private void CreateGlobalFieldModular(string contentTypeName, string nameSpace, private void CreateModularFile(string contentTypeName, string nameSpace, Contenttype contentType, DirectoryInfo directoryInfo, string extendsClass = null) { - Console.WriteLine($"Extracting Modular Blocks in {contentTypeName}."); + Console.WriteLine(Messages.ExtractingModularBlocksInContentType(contentTypeName)); // Get modular Block within ContentType var usingDirectiveList = new List(); @@ -635,7 +635,7 @@ private void CreateModularFile(string contentTypeName, string nameSpace, Content usingDirectiveList.Add(modularUsingDirective); } - Console.WriteLine($"Extracting Groups in {contentTypeName}."); + Console.WriteLine(Messages.ExtractingGroupsInContentType(contentTypeName)); string groupUsingDirective = CreateGroup(nameSpace, contentTypeName, contentType.Schema, directoryInfo); usingDirectiveList.Add(groupUsingDirective); @@ -699,7 +699,7 @@ private Boolean findRTEReference(List Schema) private void CreateFile(string contentTypeName, string nameSpace, Contenttype contentType, DirectoryInfo directoryInfo) { - Console.WriteLine($"Extracting Modular Blocks in {contentTypeName}."); + Console.WriteLine(Messages.ExtractingModularBlocksInContentType(contentTypeName)); var fields = findRTEReference(contentType.Schema); @@ -711,7 +711,7 @@ private void CreateFile(string contentTypeName, string nameSpace, Contenttype co usingDirectiveList.Add(modularUsingDirective); } - Console.WriteLine($"Extracting Groups in {contentTypeName}."); + Console.WriteLine(Messages.ExtractingGroupsInContentType(contentTypeName)); string groupUsingDirective = CreateGroup(nameSpace, contentTypeName, contentType.Schema, directoryInfo); usingDirectiveList.Add(groupUsingDirective); @@ -775,12 +775,12 @@ private FileInfo shouldCreateFile(string fileName, DirectoryInfo directoryInfo) if (!prompt) { Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine($"Skipping {file.Name}"); + Console.WriteLine(Messages.SkippingFile(file.Name)); Console.ResetColor(); return null; } } - Console.WriteLine($"Adding File {fileName} to {directoryInfo.FullName}."); + Console.WriteLine(Messages.AddingFile(fileName, directoryInfo.FullName)); return file; } @@ -789,7 +789,7 @@ private DirectoryInfo CreateDirectory(string path) var dir = new DirectoryInfo(path); if (!dir.Exists) { - Console.WriteLine($"Path {path} does not exist and will be created."); + Console.WriteLine(Messages.OutputPathNotFound(path)); dir.Create(); } return dir; @@ -947,7 +947,7 @@ private void AddEnum(string enumName, in StringBuilder sb) private void CreateGroupClass(string groupName, string nameSpace, Field field, DirectoryInfo directoryInfo) { - Console.WriteLine($"Extracting Modular Blocks in {groupName}."); + Console.WriteLine(Messages.ExtractingModularBlocksInGroup(groupName)); // Get modular Block within Group var usingDirectiveList = new List(); @@ -957,7 +957,7 @@ private void CreateGroupClass(string groupName, string nameSpace, Field field, D usingDirectiveList.Add(modularUsingDirective); } - Console.WriteLine($"Extracting Groups in {groupName}."); + Console.WriteLine(Messages.ExtractingGroupsInGroup(groupName)); // Get Group within Group string grpupUsingDirective = CreateGroup(nameSpace, groupName, field.Schema, directoryInfo); usingDirectiveList.Add(grpupUsingDirective); diff --git a/contentstack.model.generator/Program.cs b/contentstack.model.generator/Program.cs index 0a3f5ee..0070bb5 100644 --- a/contentstack.model.generator/Program.cs +++ b/contentstack.model.generator/Program.cs @@ -1,9 +1,9 @@ -using System; -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using McMaster.Extensions.CommandLineUtils; - -namespace contentstack.model.generator -{ + +namespace contentstack.model.generator +{ class Program { public const int EXCEPTION = 2; @@ -23,10 +23,11 @@ static async Task Main(string[] args) catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; - Console.Error.WriteLine("Unexpected error: " + ex.ToString()); + Console.Error.WriteLine(Messages.UnexpectedError); + Console.Error.WriteLine(ex.ToString()); Console.ResetColor(); return EXCEPTION; } } - } -} + } +} From aabbf03a110efe40cbcc85f3a49c17cfd822ec1d Mon Sep 17 00:00:00 2001 From: raj pandey Date: Fri, 2 Jan 2026 14:40:03 +0530 Subject: [PATCH 2/3] chore: license update --- LICENSE | 2 +- README.md | 2 +- contentstack.model.generator/LICENSE.txt | 2 +- .../contentstack.model.generator.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index 501f936..4382a0d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright © 2012-2025 Contentstack. All Rights Reserved +Copyright © 2012-2026 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 99ca2b3..19aaaf5 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ OAuth logout successful! ### MIT License -Copyright (c) 2012-2025 Contentstack +Copyright (c) 2012-2026 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/contentstack.model.generator/LICENSE.txt b/contentstack.model.generator/LICENSE.txt index 501f936..4382a0d 100644 --- a/contentstack.model.generator/LICENSE.txt +++ b/contentstack.model.generator/LICENSE.txt @@ -1,6 +1,6 @@ MIT License -Copyright © 2012-2025 Contentstack. All Rights Reserved +Copyright © 2012-2026 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/contentstack.model.generator/contentstack.model.generator.csproj b/contentstack.model.generator/contentstack.model.generator.csproj index 16f8f6d..41769a1 100644 --- a/contentstack.model.generator/contentstack.model.generator.csproj +++ b/contentstack.model.generator/contentstack.model.generator.csproj @@ -4,7 +4,7 @@ Exe net7.0 contentstack.model.generator - Copyright © 2012-2025 Contentstack. All Rights Reserved + Copyright © 2012-2026 Contentstack. All Rights Reserved en-US https://github.com/contentstack/contentstack-model-generator/blob/master/LICENSE README.md From 3c2cc6b5563624048abd2f94ca9ab470f7c787b6 Mon Sep 17 00:00:00 2001 From: reeshika-h Date: Fri, 9 Jan 2026 11:43:15 +0530 Subject: [PATCH 3/3] version bump --- CHANGELOG.md | 5 +++++ LICENSE | 2 +- README.md | 2 +- contentstack.model.generator/ModelGenerator.cs | 2 +- .../contentstack.model.generator.csproj | 8 ++++---- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dc19b3..c7d402e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +### Version: 0.5.1 +#### Date: Jan-12-2026 + +- Improved Error messages + ### Version: 0.5.0 #### Date: Oct-05-2025 diff --git a/LICENSE b/LICENSE index 501f936..4382a0d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright © 2012-2025 Contentstack. All Rights Reserved +Copyright © 2012-2026 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 99ca2b3..19aaaf5 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ OAuth logout successful! ### MIT License -Copyright (c) 2012-2025 Contentstack +Copyright (c) 2012-2026 Contentstack Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/contentstack.model.generator/ModelGenerator.cs b/contentstack.model.generator/ModelGenerator.cs index 518762a..3550594 100644 --- a/contentstack.model.generator/ModelGenerator.cs +++ b/contentstack.model.generator/ModelGenerator.cs @@ -68,7 +68,7 @@ public class ModelGenerator [Option(CommandOptionType.NoValue, ShortName = "N", LongName = "is-nullable", Description = "The features that protect against throwing a System.NullReferenceException can be disruptive when turned on.")] public bool IsNullable { get; } - [VersionOption("0.5.0")] + [VersionOption("0.5.1")] public bool Version { get; } private readonly string _templateStart = @"using System; diff --git a/contentstack.model.generator/contentstack.model.generator.csproj b/contentstack.model.generator/contentstack.model.generator.csproj index 16f8f6d..acdcdb3 100644 --- a/contentstack.model.generator/contentstack.model.generator.csproj +++ b/contentstack.model.generator/contentstack.model.generator.csproj @@ -13,15 +13,15 @@ true ./nupkg true - 0.5.0 + 0.5.1 Contentstack - 0.5.0 + 0.5.1 Contentstack.Model.Generator LICENSE.txt - Modular block with Global field issue resolved + Improved Error messages true true - v0.5.0 + v0.5.1 Release;Debug