Import from internal git
This commit is contained in:
45
Generator/Repo/ApiAnalyzer.cs
Normal file
45
Generator/Repo/ApiAnalyzer.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Core;
|
||||
using Core.Helpers;
|
||||
using Generator.Daos;
|
||||
using Generator.DataSource.Yaml;
|
||||
|
||||
namespace Generator.Repo;
|
||||
|
||||
public class ApiAnalyzer
|
||||
{
|
||||
|
||||
private readonly EnvironmentDao _envDao;
|
||||
private readonly OpenApiDao _openApiDao;
|
||||
|
||||
public ApiAnalyzer(OpenApiDao openApiDao, EnvironmentDao envDao)
|
||||
{
|
||||
_envDao = envDao;
|
||||
_openApiDao = openApiDao;
|
||||
}
|
||||
|
||||
public IEnumerable<Location> ListSpecifications()
|
||||
{
|
||||
var res = new List<string>();
|
||||
var directories = Directory.GetDirectories(_envDao.ApiFolder().ToString());
|
||||
|
||||
foreach (var d in directories) res.AddRange(Directory.EnumerateFiles(d));
|
||||
|
||||
return res
|
||||
.Select(s => new Location(s))
|
||||
.Where(s => s.HasExtension("yaml"));
|
||||
}
|
||||
|
||||
public bool CanBeGenerated(string folder, string spec)
|
||||
{
|
||||
var extractor = new OpenApiYamlExtractor();
|
||||
var path = _openApiDao.ConfigOf($"{folder}/{folder}");
|
||||
var configs = extractor.LoadConfigs(path.ToString());
|
||||
return configs.ContainsKey(spec);
|
||||
}
|
||||
|
||||
public string GetText(string folder, string spec)
|
||||
{
|
||||
var path = _envDao.ApiFolder().ConcatenateWith([folder, $"{spec}.yaml"]);
|
||||
return PathHelper.TextFrom(path.ToString());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user