Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
521 changes: 521 additions & 0 deletions .devcontainer/openapi.yaml

Large diffs are not rendered by default.

2,021 changes: 2,021 additions & 0 deletions .devcontainer/test.json

Large diffs are not rendered by default.

Empty file added .devcontainer/test2.json
Empty file.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,5 @@ FodyWeavers.xsd
*.msix
*.msm
*.msp

.idea/
17 changes: 17 additions & 0 deletions DbApiBuilderEntityGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator.Core", "src\DbApiBuilderEntityGenerator.Core\DbApiBuilderEntityGenerator.Core.csproj", "{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{0AB3BF05-4346-4AA6-1389-037BE0695223}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DbApiBuilderEntityGenerator.Core.Tests", "tests\DbApiBuilderEntityGenerator.Core.Tests\DbApiBuilderEntityGenerator.Core.Tests.csproj", "{1E6A2D39-C87E-457D-9733-C95A43256055}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -43,12 +47,25 @@ Global
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x64.Build.0 = Release|Any CPU
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x86.ActiveCfg = Release|Any CPU
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E}.Release|x86.Build.0 = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x64.ActiveCfg = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x64.Build.0 = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x86.ActiveCfg = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Debug|x86.Build.0 = Debug|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|Any CPU.Build.0 = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x64.ActiveCfg = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x64.Build.0 = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x86.ActiveCfg = Release|Any CPU
{1E6A2D39-C87E-457D-9733-C95A43256055}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{033FBC15-D1D8-4ACB-9D7D-4D0C7803345C} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{DAC9B44B-0E75-4AD5-80CB-4C1E2063142E} = {827E0CD3-B72D-47B6-A68D-7590B98EB39B}
{1E6A2D39-C87E-457D-9733-C95A43256055} = {0AB3BF05-4346-4AA6-1389-037BE0695223}
EndGlobalSection
EndGlobal
6 changes: 0 additions & 6 deletions src/DbApiBuilderEntityGenerator.Core/Class1.cs

This file was deleted.

132 changes: 132 additions & 0 deletions src/DbApiBuilderEntityGenerator.Core/ConfigurationSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
using System;
using DbApiBuilderEntityGenerator.Core.Serialization;
using Microsoft.Extensions.Logging;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions;

namespace DbApiBuilderEntityGenerator.Core;

/// <summary>
/// Serialization and Deserialization for the <see cref="Generator"/> class
/// </summary>
public class ConfigurationSerializer : IConfigurationSerializer
{
private readonly ILogger<ConfigurationSerializer> _logger;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationSerializer"/> class.
/// </summary>
/// <param name="logger">The logger.</param>
public ConfigurationSerializer(ILogger<ConfigurationSerializer> logger)
{
_logger = logger;
}

/// <summary>
/// The options file name. Default 'generation.yml'
/// </summary>
public const string OptionsFileName = "generation.yml";

/// <summary>
/// Loads the options file using the specified <paramref name="directory"/> and <paramref name="file"/>.
/// </summary>
/// <param name="directory">The directory where the file is located.</param>
/// <param name="file">The name of the options file.</param>
/// <returns>An instance of <see cref="Generator"/> if the file exists; otherwise <c>null</c>.</returns>
public GeneratorModel? Load(string? directory = null, string file = OptionsFileName)
{
var path = GetPath(directory, file);
if (!File.Exists(path))
{
_logger.LogWarning("Option file not found: {file}", file);
return null;
}

_logger.LogInformation("Loading options file: {file}", file);
using var reader = File.OpenText(path);

return Load(reader);
}

/// <summary>
/// Loads the options using the specified <paramref name="reader" />
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>
/// An instance of <see cref="Generator" />.
/// </returns>
public GeneratorModel? Load(TextReader reader)
{
if (reader == null)
return null;

var deserializer = new DeserializerBuilder()
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

// use Serialization model for better yaml support
return deserializer.Deserialize<GeneratorModel>(reader);
}

/// <summary>
/// Saves the generator options to the specified <paramref name="directory"/> and <paramref name="file"/>.
/// </summary>
/// <param name="generatorOptions">The generator options to save.</param>
/// <param name="directory">The directory where the file is located.</param>
/// <param name="file">The name of the options file.</param>
/// <returns>The full path of the options file.</returns>
public string Save(GeneratorModel generatorOptions, string? directory = null, string file = OptionsFileName)
{
if (string.IsNullOrWhiteSpace(directory))
directory = Environment.CurrentDirectory;

if (string.IsNullOrWhiteSpace(file))
file = OptionsFileName;

if (!Directory.Exists(directory))
{
_logger.LogTrace($"Creating Directory: {directory}");
Directory.CreateDirectory(directory);
}

_logger.LogInformation($"Saving options file: {file}");

var path = Path.Combine(directory, file);

var serializer = new SerializerBuilder()
.ConfigureDefaultValuesHandling(DefaultValuesHandling.OmitDefaults)
.WithNamingConvention(CamelCaseNamingConvention.Instance)
.Build();

using (var streamWriter = File.CreateText(path))
serializer.Serialize(streamWriter, generatorOptions);

return path;
}

/// <summary>
/// Determines if the specified options file exists.
/// </summary>
/// <param name="directory">The directory where the file is located.</param>
/// <param name="file">The name of the options file.</param>
/// <returns><c>true</c> if options file exits; otherwise <c>false</c>.</returns>
public bool Exists(string? directory = null, string file = OptionsFileName)
{
var path = GetPath(directory, file);
return File.Exists(path);
}


private static string GetPath(string? directory, string? file)
{
if (string.IsNullOrWhiteSpace(directory))
directory = Environment.CurrentDirectory;

if (string.IsNullOrWhiteSpace(file))
file = OptionsFileName;

var path = Path.Combine(directory, file);
return path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql.NetTopologySuite" Version="9.0.0-preview.3.efcore.9.0.0" />
<PackageReference Include="YamlDotNet" Version="16.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Serialization\" />
</ItemGroup>
</Project>
Loading