Skip to content

Commit

Permalink
[IDPHD-35] Add Do not edit comment on spec (#99)
Browse files Browse the repository at this point in the history
* [IDPHD-35] Add Do not edit comment on spec

* Extract into own method
  • Loading branch information
heqianwang authored Jan 8, 2025
1 parent b618f6d commit 98460ce
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Workleap.OpenApi.MSBuild/SwaggerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Workleap.OpenApi.MSBuild;
internal sealed class SwaggerManager : ISwaggerManager
{
private const string SwaggerVersion = "6.5.0";
private const string DoNotEditComment = "# DO NOT EDIT. This is a generated file\n";
private const int MaxRetryCount = 3;
private readonly IProcessWrapper _processWrapper;
private readonly ILoggerWrapper _loggerWrapper;
Expand Down Expand Up @@ -100,6 +101,22 @@ public async Task<string> GenerateOpenApiSpecAsync(string swaggerExePath, string
break;
}

this.PrependComment(outputOpenApiSpecPath, DoNotEditComment);

return outputOpenApiSpecPath;
}

private void PrependComment(string outputOpenApiSpecPath, string comment)
{
try
{
// Add the comment at the top of the generated YAML file
var yamlContent = File.ReadAllText(outputOpenApiSpecPath);
File.WriteAllText(outputOpenApiSpecPath, comment + yamlContent);
}
catch (Exception)
{
this._loggerWrapper.LogWarning($"Failed to add comment to generated spec for {outputOpenApiSpecPath}.");
}
}
}

0 comments on commit 98460ce

Please sign in to comment.