-
Notifications
You must be signed in to change notification settings - Fork 0
Various Fixes #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various Fixes #41
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using Microsoft.OpenApi; | ||
| using OpenAPIDyalog.Constants; | ||
|
|
||
| namespace OpenAPIDyalog.Models; | ||
|
|
||
|
|
@@ -117,15 +118,24 @@ public IEnumerable<string> GetAllTags() | |
| { | ||
| if (Paths == null) return Enumerable.Empty<string>(); | ||
|
|
||
| return Paths.Values | ||
| var operations = Paths.Values | ||
| .Where(path => path.Operations != null) | ||
| .SelectMany(path => path.Operations!.Values) | ||
| .Where(op => op.Tags != null) | ||
| .ToList(); | ||
|
|
||
| var explicitTags = operations | ||
| .Where(op => op.Tags is { Count: > 0 }) | ||
| .SelectMany(op => op.Tags!) | ||
| .Select(tag => tag.Name) | ||
| .Where(name => name != null) | ||
| .Cast<string>() | ||
| .Distinct(); | ||
|
|
||
| var hasTaglessOperations = operations.Any(op => op.Tags == null || op.Tags.Count == 0); | ||
| if (hasTaglessOperations) | ||
| return explicitTags.Append(GeneratorConstants.DefaultTagName).Distinct(); | ||
|
|
||
|
Comment on lines
+134
to
+137
|
||
| return explicitTags; | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,22 +51,36 @@ public async Task GenerateVersionAsync(OpenApiDocument document, string outputDi | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Copies the embedded HttpCommand.aplc binary resource to the output directory. | ||
| /// Copies the embedded HttpCommand.aplc binary resource to the output directory, | ||
| /// skipping the write if the existing file is already identical. | ||
| /// </summary> | ||
| public async Task CopyHttpCommandAsync(string outputDirectory) | ||
| { | ||
| var destPath = Path.Combine(outputDirectory, GeneratorConstants.AplSourceDir, "HttpCommand.aplc"); | ||
| Directory.CreateDirectory(Path.GetDirectoryName(destPath)!); | ||
|
|
||
| using var srcStream = _templateService.GetEmbeddedResourceStream(GeneratorConstants.HttpCommandResource); | ||
| using var destStream = File.Create(destPath); | ||
| await srcStream.CopyToAsync(destStream); | ||
| using var srcStream = _templateService.GetEmbeddedResourceStream(GeneratorConstants.HttpCommandResource); | ||
| using var memStream = new MemoryStream(); | ||
| await srcStream.CopyToAsync(memStream); | ||
| var srcBytes = memStream.ToArray(); | ||
|
|
||
| if (File.Exists(destPath)) | ||
| { | ||
| var destBytes = await File.ReadAllBytesAsync(destPath); | ||
| if (srcBytes.SequenceEqual(destBytes)) | ||
| { | ||
| _logger.LogInformation("Unchanged: {AplSourceDir}/HttpCommand.aplc", GeneratorConstants.AplSourceDir); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| await File.WriteAllBytesAsync(destPath, srcBytes); | ||
| _logger.LogInformation("Copied: {AplSourceDir}/HttpCommand.aplc", GeneratorConstants.AplSourceDir); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Copies the OpenAPI specification file to the output directory. | ||
| /// Copies the OpenAPI specification file to the output directory, | ||
| /// skipping the write if the existing file is already identical. | ||
| /// </summary> | ||
| /// <exception cref="IOException">Re-thrown after logging if the copy fails.</exception> | ||
| public async Task CopySpecificationAsync(string sourcePath, string outputDirectory) | ||
|
|
@@ -76,9 +90,20 @@ public async Task CopySpecificationAsync(string sourcePath, string outputDirecto | |
|
|
||
| try | ||
| { | ||
| File.Copy(sourcePath, destPath, overwrite: true); | ||
| var srcBytes = await File.ReadAllBytesAsync(sourcePath); | ||
|
|
||
| if (File.Exists(destPath)) | ||
| { | ||
| var destBytes = await File.ReadAllBytesAsync(destPath); | ||
| if (srcBytes.SequenceEqual(destBytes)) | ||
| { | ||
|
Comment on lines
+93
to
+99
|
||
| _logger.LogInformation("Unchanged: {FileName}", fileName); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| await File.WriteAllBytesAsync(destPath, srcBytes); | ||
| _logger.LogInformation("Copied: {FileName}", fileName); | ||
| await Task.CompletedTask; // async for consistent caller pattern | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,7 +71,7 @@ public string Render(Template template, object context) | |
| try | ||
| { | ||
| var scriptObject = BuildScriptObject(context); | ||
| var templateContext = new TemplateContext(); | ||
| var templateContext = new TemplateContext { LoopLimit = int.MaxValue }; | ||
| templateContext.PushGlobal(scriptObject); | ||
| return template.Render(templateContext); | ||
|
Comment on lines
73
to
76
|
||
| } | ||
|
|
@@ -89,7 +89,7 @@ public async Task<string> RenderAsync(Template template, object context) | |
| try | ||
| { | ||
| var scriptObject = BuildScriptObject(context); | ||
| var templateContext = new TemplateContext(); | ||
| var templateContext = new TemplateContext { LoopLimit = int.MaxValue }; | ||
| templateContext.PushGlobal(scriptObject); | ||
| return await template.RenderAsync(templateContext); | ||
|
Comment on lines
91
to
94
|
||
| } | ||
|
|
@@ -109,7 +109,7 @@ public async Task<string> LoadAndRenderAsync(string templateName, object context | |
| } | ||
|
|
||
| /// <summary> | ||
| /// Saves rendered output to a file. | ||
| /// Saves rendered output to a file, skipping the write if the existing content is identical. | ||
| /// </summary> | ||
| public async Task SaveOutputAsync(string output, string outputPath) | ||
| { | ||
|
|
@@ -119,6 +119,9 @@ public async Task SaveOutputAsync(string output, string outputPath) | |
| Directory.CreateDirectory(directory); | ||
| } | ||
|
|
||
| if (File.Exists(outputPath) && await File.ReadAllTextAsync(outputPath) == output) | ||
| return; | ||
|
|
||
| await File.WriteAllTextAsync(outputPath, output); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| :Namespace utils | ||
| ⍝ Generated on {{ generated_at | date.to_string "%Y-%m-%d %H:%M:%S" }} UTC | ||
| ⍝ {{ title }} - Version {{ version }} | ||
| ⍝ Utility functions for HTTP requests and parameter validation | ||
|
|
||
|
|
@@ -98,12 +97,12 @@ | |
|
|
||
| ∇ | ||
|
|
||
| isValidPathParam←{ | ||
| isValidPathParam←{ | ||
| ⍝ True if argument is a character vector or a scalar number | ||
| isChar←(0=10|⎕DR)⍵ | ||
| isChar←(1=≢⍴1∘/⍵)∧(0=10|⎕DR)⍵ | ||
| isScalarNum←(0=≢⍴⍵)∧2|⎕DR ⍵ | ||
| isChar ∨ isScalarNum | ||
| } | ||
| isChar∨isScalarNum | ||
| } | ||
|
Comment on lines
+100
to
+105
|
||
|
|
||
| base64←{⎕IO ⎕ML←0 1 ⍝ Base64 encoding and decoding as used in MIME. | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s trailing whitespace at the end of this line (after “respective”). It’s best to remove it to avoid noisy diffs and keep the notices file clean.