Skip to content

Commit 9d71ea3

Browse files
committed
Corrected paths
1 parent 08b5dcc commit 9d71ea3

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

tools/OpenApiInfoGenerator/OpenApiInfoGenerator/FileHandler.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ namespace openapiinfo;
22

33
public static class FileHandler
44
{
5-
private const string OpenApiFolderName = "docs";
5+
private const string OpenApiFolderName = "OpenApiDocs";
6+
private const string DocFolderName = "docs";
67
private static string? AssemblyLocation = Path.GetDirectoryName(typeof(FileHandler).Assembly.Location);
78

8-
public static string? GetDocsFolder()
9+
public static string? GetOpenApiFolder()
910
{
1011
if (AssemblyLocation is null)
1112
{
@@ -14,4 +15,13 @@ public static class FileHandler
1415

1516
return Path.Combine(AssemblyLocation, $"../../../../../../{OpenApiFolderName}");
1617
}
18+
public static string? GetDocFolder()
19+
{
20+
if (AssemblyLocation is null)
21+
{
22+
throw new InvalidOperationException("Assembly location is null.");
23+
}
24+
25+
return Path.Combine(AssemblyLocation, $"../../../../../../{DocFolderName}");
26+
}
1727
}

tools/OpenApiInfoGenerator/OpenApiInfoGenerator/Program.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@ private static void CompareOpenApiInfo(string version, IList<Model> openApiInfoM
3030
var openApiErrors = new HashSet<string>();
3131
newPathsAdded.Add("Module,Path,Method");
3232
openApiErrors.Add("Module,ApiPath,Method,From,To");
33-
var filePath = FileHandler.GetDocsFolder();
34-
Console.WriteLine(filePath);
35-
var combinedPath = filePath != null ? Path.Combine(filePath, "openApiInfo") : null;
36-
var openAPiInfoPath = combinedPath != null ? Path.Combine(combinedPath, version) : null;
37-
var combinedErrorPath = openAPiInfoPath != null ? Path.Combine(openAPiInfoPath, openApiFileError) : null;
38-
if (combinedErrorPath != null && File.Exists(combinedErrorPath))
33+
var openApiFilePath = FileHandler.GetOpenApiFolder();
34+
var docPath = FileHandler.GetDocFolder();
35+
var openApiPath = openApiFilePath != null ? Path.Combine(openApiFilePath, version) : null;
36+
37+
var combinedDocPath = docPath != null ? Path.Combine(docPath, "OpenAPiInfo") : null;
38+
var openApiInfoPath = combinedDocPath != null ? Path.Combine(combinedDocPath, version) : null;
39+
40+
var errorPath = openApiInfoPath != null ? Path.Combine(openApiInfoPath, openApiFileError) : null;
41+
if (errorPath != null && File.Exists(errorPath))
3942
{
40-
File.WriteAllText(combinedErrorPath, string.Empty);
43+
File.WriteAllText(errorPath, string.Empty);
4144
}
42-
if(combinedPath!=null)
45+
if(openApiPath!=null)
4346
{
4447
//Go through list of openapi files
45-
foreach (var file in Directory.GetFiles(combinedPath))
48+
foreach (var file in Directory.GetFiles(openApiPath))
4649
{
4750
using (var sr = new StreamReader(file))
4851
{
@@ -112,17 +115,17 @@ private static void CompareOpenApiInfo(string version, IList<Model> openApiInfoM
112115
var options = new JsonSerializerOptions { WriteIndented = true };
113116
var json = JsonSerializer.Serialize(models, options);
114117
//Clear file first
115-
File.WriteAllText($"{openAPiInfoPath}\\{openApiInfoFile}", string.Empty);
118+
File.WriteAllText($"{openApiInfoPath}\\{openApiInfoFile}", string.Empty);
116119
//then write to it with new content.
117-
File.WriteAllText($"{openAPiInfoPath}\\{openApiInfoFile}", json);
120+
File.WriteAllText($"{openApiInfoPath}\\{openApiInfoFile}", json);
118121
}
119122
if (openApiErrors.Count > 1)
120123
{
121124
foreach (var error in openApiErrors)
122125
{
123126
var errList = error.Split(",");
124127
var report = $"{errList[0]},{errList[1]},{errList[2]},{errList[3]},{errList[4]}";
125-
File.AppendAllText($"{openAPiInfoPath}\\{openApiFileError}", report + Environment.NewLine);
128+
File.AppendAllText($"{openApiInfoPath}\\{openApiFileError}", report + Environment.NewLine);
126129
}
127130
}
128131

0 commit comments

Comments
 (0)