Import from internal git

This commit is contained in:
2025-10-11 13:08:09 +02:00
commit 97aaa715dc
175 changed files with 7014 additions and 0 deletions

75
Core/Yaml/OpenApiYaml.cs Normal file
View File

@@ -0,0 +1,75 @@
using Core.SpecConfig;
using MoreLinq;
namespace Core.Yaml;
public class OpenApiYaml : ISpecFile
{
public Location Location { get; }
public string Name => Location.GetFileName();
public string Folder => Location.GetFolder();
public string? Openapi { get; set; }
public IDictionary<string, object>? Info { get; set; }
public IList<object>? Tags { get; set; }
public YamlConfig Config;
public ISet<string> Models;
public ISet<string> IgnoredModels;
public ISet<OpenApiYaml> ReferencedSchemas;
public ISet<string> ScopedRefs { get; set; }
public ISet<string> OutScopedRefs { get; set; }
public IEnumerable<string> Refs => ScopedRefs.Union(OutScopedRefs);
public SpecType SpecType => Config.Type;
public string NugetPackage => Config.NugetPackage;
public string MavenGroup => Config.JavaGroup;
public string NpmPackage => Config.NpmPackage;
public string Version => (string)Info["version"];
public int Priority => Config.Priority;
public OpenApiYaml(string loc)
{
Location = new Location(loc);
Info = new Dictionary<string, object>();
Tags = new List<object>();
Config = new YamlConfig();
IgnoredModels = new HashSet<string>();
ScopedRefs = new HashSet<string>();
OutScopedRefs = new HashSet<string>();
ReferencedSchemas = new HashSet<OpenApiYaml>();
Models = new HashSet<string>();
}
public Queue<ISpecFile> GetTasksBy(Language language, GenerationType type)
{
var tasks = new Queue<ISpecFile>();
var toGenerate = new List<ISpecFile>();
var packageTypes = Config.PackageTypes;
var specs = GetSpecsInSameFolder().ToList();
if (packageTypes.Has(language, type))
toGenerate.AddRange(type switch
{
GenerationType.Server => specs.Where(s => s.SpecType == SpecType.Api),
GenerationType.Client => specs.Where(s => s.SpecType == SpecType.Api),
GenerationType.Common => specs.Where(s => s.SpecType == SpecType.Model),
_ => throw new ArgumentOutOfRangeException(nameof(type), type, null)
});
toGenerate.Sort((s1, s2) => s2.Priority - s1.Priority);
toGenerate.ForEach(s => tasks.Enqueue(s));
return tasks;
}
private IEnumerable<ISpecFile> GetSpecsInSameFolder()
{
var result = new List<ISpecFile>{ this };
ReferencedSchemas.ForEach(oay =>
{
if (oay.Location.IsInSameFolder(this.Location)) result.Add(oay);
});
return result;
}
}

16
Core/Yaml/YamlConfig.cs Normal file
View File

@@ -0,0 +1,16 @@
using Core.SpecConfig;
namespace Core.Yaml;
public class YamlConfig
{
public PackageTypes PackageTypes;
public int Priority { get; set; }
public SpecType Type { get; set; }
public string NugetPackage { get; set; } = "";
public string NpmPackage { get; set; } = "";
public string JavaGroup { get; set; } = "";
public string ModelSuffix { get; set; } = "";
public bool KeepModels { get; set; } = false;
}