Skip to content

Commit 98460ce

Browse files
authored
[IDPHD-35] Add Do not edit comment on spec (#99)
* [IDPHD-35] Add Do not edit comment on spec * Extract into own method
1 parent b618f6d commit 98460ce

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/Workleap.OpenApi.MSBuild/SwaggerManager.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace Workleap.OpenApi.MSBuild;
66
internal sealed class SwaggerManager : ISwaggerManager
77
{
88
private const string SwaggerVersion = "6.5.0";
9+
private const string DoNotEditComment = "# DO NOT EDIT. This is a generated file\n";
910
private const int MaxRetryCount = 3;
1011
private readonly IProcessWrapper _processWrapper;
1112
private readonly ILoggerWrapper _loggerWrapper;
@@ -100,6 +101,22 @@ public async Task<string> GenerateOpenApiSpecAsync(string swaggerExePath, string
100101
break;
101102
}
102103

104+
this.PrependComment(outputOpenApiSpecPath, DoNotEditComment);
105+
103106
return outputOpenApiSpecPath;
104107
}
108+
109+
private void PrependComment(string outputOpenApiSpecPath, string comment)
110+
{
111+
try
112+
{
113+
// Add the comment at the top of the generated YAML file
114+
var yamlContent = File.ReadAllText(outputOpenApiSpecPath);
115+
File.WriteAllText(outputOpenApiSpecPath, comment + yamlContent);
116+
}
117+
catch (Exception)
118+
{
119+
this._loggerWrapper.LogWarning($"Failed to add comment to generated spec for {outputOpenApiSpecPath}.");
120+
}
121+
}
105122
}

0 commit comments

Comments
 (0)