diff --git a/README.md b/README.md index 6a6d0364..d7abde1c 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ See the [list of all RIDs](https://docs.microsoft.com/en-us/dotnet/articles/core | `-p` | `--projectid` | True | `null` | A GUID that can be found in [Kentico Kontent](https://app.kontent.ai) -> API keys -> Project ID | | `-n` | `--namespace` | False | `KenticoKontentModels` | A name of the [C# namespace](https://msdn.microsoft.com/en-us/library/z2kcy19k.aspx) | | `-o` | `--outputdir` | False | `\.` | An output folder path | -| `-g` | `--generatepartials` | False | `false` | Generates partial classes for customization. Partial classes are the best practice for customization so the recommended value is `true`. | +| `-g` | `--generatepartials` | False | `true` | Generates partial classes for customization. Partial classes are the best practice for customization so the recommended value is `true`. | | `-t` | `--withtypeprovider` | False | `true` | Indicates whether the `CustomTypeProvider` class should be generated (see [Customizing the strong-type binding logic](https://github.com/Kentico/delivery-sdk-net/wiki/Working-with-Strongly-Typed-Models-(aka-Code-First-Approach)#customizing-the-strong-type-binding-logic) for more info) | | `-s` | `--structuredmodel` | False | `false` | Generates `IRichTextContent` instead of `string` for rich-text elements. This enables utilizing [structured rich-text rendering](https://github.com/Kentico/delivery-sdk-net/wiki/Structured-Rich-text-rendering) | | `-f` | `--filenamesuffix` | False | `null` | Adds a suffix to generated filenames (e.g., News.cs becomes News.Generated.cs) | diff --git a/src/Kentico.Kontent.ModelGenerator.Core/CodeGenerator.cs b/src/Kentico.Kontent.ModelGenerator.Core/CodeGenerator.cs index 6398757e..696e811c 100644 --- a/src/Kentico.Kontent.ModelGenerator.Core/CodeGenerator.cs +++ b/src/Kentico.Kontent.ModelGenerator.Core/CodeGenerator.cs @@ -19,11 +19,6 @@ public CodeGenerator(IOptions options, IDeliveryClient del _options = options.Value; _client = deliveryClient; _outputProvider = outputProvider; - - if (_options.GeneratePartials && string.IsNullOrEmpty(_options.FileNameSuffix)) - { - _options.FileNameSuffix = "Generated"; - } } public async Task RunAsync() diff --git a/src/Kentico.Kontent.ModelGenerator.Core/Configuration/CodeGeneratorOptions.cs b/src/Kentico.Kontent.ModelGenerator.Core/Configuration/CodeGeneratorOptions.cs index f9c22d5a..f49c4d0f 100644 --- a/src/Kentico.Kontent.ModelGenerator.Core/Configuration/CodeGeneratorOptions.cs +++ b/src/Kentico.Kontent.ModelGenerator.Core/Configuration/CodeGeneratorOptions.cs @@ -4,10 +4,11 @@ namespace Kentico.Kontent.ModelGenerator.Core.Configuration { public class CodeGeneratorOptions { - public static bool DefaultGeneratePartials = false; + public static bool DefaultGeneratePartials = true; public static bool DefaultWithTypeProvider = true; public static bool DefaultStructuredModel = false; public static bool DefaultContentManagementApi = false; + public static string DefaultFileNameSuffix = "Generated"; /// /// Delivery Client configuration. @@ -27,7 +28,7 @@ public class CodeGeneratorOptions /// /// Optionally add suffix to the generated files /// - public string FileNameSuffix { get; set; } + public string FileNameSuffix { get; set; } = DefaultFileNameSuffix; /// /// Optionally generate partial classes for user customization diff --git a/test/Kentico.Kontent.ModelGenerator.Tests/CodeGeneratorTests.cs b/test/Kentico.Kontent.ModelGenerator.Tests/CodeGeneratorTests.cs index 23e2b22b..31c66ea7 100644 --- a/test/Kentico.Kontent.ModelGenerator.Tests/CodeGeneratorTests.cs +++ b/test/Kentico.Kontent.ModelGenerator.Tests/CodeGeneratorTests.cs @@ -10,6 +10,7 @@ using Kentico.Kontent.ModelGenerator.Core; using Kentico.Kontent.ModelGenerator.Core.Configuration; using Xunit; +using System.Linq; namespace Kentico.Kontent.ModelGenerator.Tests { @@ -85,10 +86,9 @@ public async Task IntegrationTest(bool cmApi) Assert.True(Directory.GetFiles(Path.GetFullPath(TEMP_DIR)).Length > 10); - foreach (var filepath in Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR))) - { - Assert.DoesNotContain(".Generated.cs", Path.GetFileName(filepath)); - } + Assert.NotEmpty(Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR), "*.Generated.cs")); + Assert.NotEmpty(Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR)).Where(p=> !p.Contains("*.Generated.cs"))); + Assert.NotEmpty(Directory.EnumerateFiles(Path.GetFullPath(TEMP_DIR), "*TypeProvider.cs")); // Cleanup Directory.Delete(TEMP_DIR, true); @@ -104,7 +104,7 @@ public async Task IntegrationTestWithGeneratedSuffix(bool cmApi) .Respond("application/json", await File.ReadAllTextAsync(Path.Combine(AppContext.BaseDirectory, "Fixtures/types.json"))); var httpClient = mockHttp.ToHttpClient(); - const string transformFilename = "Generated"; + const string transformFilename = "CustomSuffix"; var mockOptions = new Mock>(); mockOptions.Setup(x => x.Value).Returns(new CodeGeneratorOptions @@ -112,6 +112,7 @@ public async Task IntegrationTestWithGeneratedSuffix(bool cmApi) DeliveryOptions = new DeliveryOptions { ProjectId = PROJECT_ID }, Namespace = "CustomNamespace", OutputDir = TEMP_DIR, + GeneratePartials = false, FileNameSuffix = transformFilename, ContentManagementApi = cmApi });