Import from internal git
This commit is contained in:
60
Generator/Infrastructure/Export/Exporter.cs
Normal file
60
Generator/Infrastructure/Export/Exporter.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Core;
|
||||
using Core.Actions;
|
||||
using Core.Helpers;
|
||||
using Core.Templates;
|
||||
using Core.Yaml;
|
||||
using Generator.Infrastructure.TemplateFiller;
|
||||
|
||||
namespace Generator.Infrastructure.Export;
|
||||
|
||||
/// <summary>
|
||||
/// Provides multiple methods to specification references
|
||||
/// </summary>
|
||||
public class Exporter
|
||||
{
|
||||
private readonly ITemplateFactory _templateFactory;
|
||||
|
||||
public Exporter(ITemplateFactory factory)
|
||||
{
|
||||
_templateFactory = factory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Export file references as plant uml diagram
|
||||
/// </summary>
|
||||
/// <param name="export">plantuml data needed for exportation</param>
|
||||
/// <param name="file">File to export</param>
|
||||
public void PlantUml(PlantUmlExport export, ISpecFile file)
|
||||
{
|
||||
var yaml = TypeHelper.SafeCast<ISpecFile, OpenApiYaml>(file);
|
||||
var input = export.LocalRoot.ConcatenateWith(export.Template);
|
||||
var output = export.LocalRoot.ConcatenateWith(export.Output);
|
||||
|
||||
var references = new List<(string Package, string Reference)>();
|
||||
var schemas = yaml.ReferencedSchemas.ToList();
|
||||
|
||||
for (var i = -1; i < schemas.Count; i++)
|
||||
{
|
||||
var baseFile = i == -1 ? yaml : schemas[i];
|
||||
if(!baseFile.Location.IsInSameFolder(yaml.Location)) continue;
|
||||
|
||||
foreach (var reference in baseFile.ReferencedSchemas)
|
||||
{
|
||||
references.Add((baseFile.NugetPackage, reference.NugetPackage));
|
||||
}
|
||||
}
|
||||
|
||||
var data = new Dictionary<string, object>()
|
||||
{
|
||||
{"specName", file.Folder},
|
||||
{"packages", references.Select(t => t.Package).ToHashSet()},
|
||||
{"references", references}
|
||||
};
|
||||
|
||||
var template = _templateFactory.GetTemplate(input.ToString(), data);
|
||||
var f = new MustacheFiller(template);
|
||||
f.Fill();
|
||||
f.Write(output.ToString());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user