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? Info { get; set; } public IList? Tags { get; set; } public YamlConfig Config; public ISet Models; public ISet IgnoredModels; public ISet ReferencedSchemas; public ISet ScopedRefs { get; set; } public ISet OutScopedRefs { get; set; } public IEnumerable 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(); Tags = new List(); Config = new YamlConfig(); IgnoredModels = new HashSet(); ScopedRefs = new HashSet(); OutScopedRefs = new HashSet(); ReferencedSchemas = new HashSet(); Models = new HashSet(); } public Queue GetTasksBy(Language language, GenerationType type) { var tasks = new Queue(); var toGenerate = new List(); 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 GetSpecsInSameFolder() { var result = new List{ this }; ReferencedSchemas.ForEach(oay => { if (oay.Location.IsInSameFolder(this.Location)) result.Add(oay); }); return result; } }