Skip to content

Commit

Permalink
Merge pull request #4932 from ajtribick/path-normalization
Browse files Browse the repository at this point in the history
Normalize local DescriptionLocation to use / as directory separator
  • Loading branch information
baywet authored Jul 4, 2024
2 parents 8b2ca84 + 71619b8 commit 285db9f
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Emit `[GeneratedCode]` attribute for C# types. [#4907](https://github.com/microsoft/kiota/issues/4907)
- Fixes error property disambiguation when the property has the same name as class [#4893](https://github.com/microsoft/kiota/issues/)
- Fixes missing imports for `UntypedNode` for method parameter and return value scenarios. [#4925](https://github.com/microsoft/kiota/issues/4925)
- Normalize path separators in lock and workspace files to use `/` as the path separator. [#4228](https://github.com/microsoft/kiota/issues/4228)

## [1.15.0] - 2024-06-06

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Configuration/GenerationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private string NormalizeDescriptionLocation(string targetDirectory)
!OpenAPIFilePath.StartsWith("http", StringComparison.OrdinalIgnoreCase) &&
Path.IsPathRooted(OpenAPIFilePath) &&
Path.GetFullPath(OpenAPIFilePath).StartsWith(Path.GetFullPath(targetDirectory), StringComparison.Ordinal))
return "./" + Path.GetRelativePath(targetDirectory, OpenAPIFilePath);
return "./" + Path.GetRelativePath(targetDirectory, OpenAPIFilePath).NormalizePathSeparators();
return OpenAPIFilePath;
}
public bool IsPluginConfiguration => PluginTypes.Count != 0;
Expand Down
6 changes: 6 additions & 0 deletions src/Kiota.Builder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,10 @@ public static string GetFileExtension(this string path)
if (string.IsNullOrEmpty(path)) return string.Empty;
return Path.GetExtension(path).TrimStart('.');
}
public static string NormalizePathSeparators(this string path)
{
if (string.IsNullOrEmpty(path)) return string.Empty;
if (Path.DirectorySeparatorChar != '/') return path.Replace(Path.DirectorySeparatorChar, '/');
return path;
}
}
3 changes: 2 additions & 1 deletion src/Kiota.Builder/Lock/LockManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Kiota.Builder.Extensions;

namespace Kiota.Builder.Lock;

Expand Down Expand Up @@ -83,7 +84,7 @@ private static string GetRelativeDescriptionPath(string descriptionPath, string
{
if (IsDescriptionLocal(descriptionPath) &&
Path.GetDirectoryName(lockFilePath) is string lockFileDirectoryPath)
return Path.GetRelativePath(lockFileDirectoryPath, descriptionPath);
return Path.GetRelativePath(lockFileDirectoryPath, descriptionPath).NormalizePathSeparators();
return descriptionPath;
}
/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using Kiota.Builder.Configuration;
using Kiota.Builder.Extensions;
using Microsoft.OpenApi.ApiManifest;

namespace Kiota.Builder.WorkspaceManagement;
Expand Down Expand Up @@ -41,12 +42,12 @@ private protected BaseApiConsumerConfiguration(GenerationConfiguration config)
public void NormalizeOutputPath(string targetDirectory)
{
if (Path.IsPathRooted(OutputPath))
OutputPath = "./" + Path.GetRelativePath(targetDirectory, OutputPath);
OutputPath = "./" + Path.GetRelativePath(targetDirectory, OutputPath).NormalizePathSeparators();
}
public void NormalizeDescriptionLocation(string targetDirectory)
{
if (Path.IsPathRooted(DescriptionLocation) && Path.GetFullPath(DescriptionLocation).StartsWith(Path.GetFullPath(targetDirectory), StringComparison.Ordinal) && !DescriptionLocation.StartsWith("http", StringComparison.OrdinalIgnoreCase))
DescriptionLocation = "./" + Path.GetRelativePath(targetDirectory, DescriptionLocation);
DescriptionLocation = "./" + Path.GetRelativePath(targetDirectory, DescriptionLocation).NormalizePathSeparators();
}
protected void CloneBase(BaseApiConsumerConfiguration target)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public async Task<IEnumerable<string>> MigrateFromLockFileAsync(string clientNam
}
var generationConfiguration = new GenerationConfiguration();
lockInfo.UpdateGenerationConfigurationFromLock(generationConfiguration);
generationConfiguration.OutputPath = "./" + Path.GetRelativePath(WorkingDirectory, lockFileDirectory);
generationConfiguration.OutputPath = "./" + Path.GetRelativePath(WorkingDirectory, lockFileDirectory).NormalizePathSeparators();
if (!string.IsNullOrEmpty(clientName))
{
generationConfiguration.ClientClassName = clientName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public async Task UsesRelativePaths()
var outputDirectory = Path.Combine(tmpPath, "output");
Directory.CreateDirectory(outputDirectory);
await lockManagementService.WriteLockFileAsync(outputDirectory, lockFile);
Assert.Equal($"..{Path.DirectorySeparatorChar}information{Path.DirectorySeparatorChar}description.yml", lockFile.DescriptionLocation, StringComparer.OrdinalIgnoreCase);
Assert.Equal("../information/description.yml", lockFile.DescriptionLocation, StringComparer.OrdinalIgnoreCase);
}
[Fact]
public async Task DeletesALock()
Expand Down

0 comments on commit 285db9f

Please sign in to comment.