Skip to content

Commit

Permalink
Normalize directory separators in WorkspaceManagement
Browse files Browse the repository at this point in the history
  • Loading branch information
ajtribick committed Jul 3, 2024
1 parent c87c7cc commit 71619b8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 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;
}
}
8 changes: 2 additions & 6 deletions 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,12 +84,7 @@ private static string GetRelativeDescriptionPath(string descriptionPath, string
{
if (IsDescriptionLocal(descriptionPath) &&
Path.GetDirectoryName(lockFilePath) is string lockFileDirectoryPath)
{
var relativePath = Path.GetRelativePath(lockFileDirectoryPath, descriptionPath);
if (Path.DirectorySeparatorChar != '/')
relativePath = relativePath.Replace(Path.DirectorySeparatorChar, '/');
return relativePath;
}
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

0 comments on commit 71619b8

Please sign in to comment.