Skip to content
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

Normalize local DescriptionLocation to use / as directory separator #4932

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading