75 lines
2.6 KiB
C#
75 lines
2.6 KiB
C#
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;
|
|
}
|
|
|
|
} |