Skip to content

Commit

Permalink
Merge branch 'main' into fix/update-php-promise-doc-include-generic-type
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Oct 27, 2023
2 parents f90a550 + 9cb04ed commit af26dc0
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 64 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed

- Include the type which a promise resolves to in PHPDocs for PHP. [#3542](https://github.com/microsoft/kiota/issues/3542)
- Added null check for null content type instances when getting deprecation information [#3588](https://github.com/microsoft/kiota/issues/3588)
- Aligns header management in Python with other languages. [#3430](https://github.com/microsoft/kiota/issues/3430)
- Fixed parameters that are in camelcase to snakecase in Python. [#3525](https://github.com/microsoft/kiota/issues/3525)
- Fixed missing imports for method parameters that are query parameters.
- Replaces the use of "new" by "override" and "virtual" in CSharp models.
- Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354)
- The lock file now contains the relative path to the description in case of local path. [#3151](https://github.com/microsoft/kiota/issues/3151)
- Fixed bug where base64url and decimal types would not be generated properly in Java.
- Fixed bug where symbol name cleanup would not work on forward single quotes characters [#3426](https://github.com/microsoft/kiota/issues/3426).
- Fixed a bug where a "models" API path segment in the description would derail generation. [#3400](https://github.com/microsoft/kiota/issues/3400)
Expand Down
6 changes: 3 additions & 3 deletions it/python/requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ attrs==23.1.0 ; python_version >= '3.7'

azure-core==1.29.5 ; python_version >= '3.7'

azure-identity==1.14.1
azure-identity==1.15.0

cffi==1.16.0

cryptography==41.0.4 ; python_version >= '3.7'
cryptography==41.0.5 ; python_version >= '3.7'

frozenlist==1.4.0 ; python_version >= '3.7'

Expand All @@ -98,7 +98,7 @@ httpx[http2]==0.25.0

hyperframe==6.0.1 ; python_full_version >= '3.6.1'

microsoft-kiota-abstractions==0.9.0
microsoft-kiota-abstractions==0.9.1

microsoft-kiota-authentication-azure==0.3.2

Expand Down
66 changes: 33 additions & 33 deletions it/typescript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions it/typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"prettier": "./.prettierrc.json",
"devDependencies": {
"@es-exec/esbuild-plugin-start": "^0.0.5",
"@types/node": "^20.8.8",
"@types/node": "^20.8.9",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"esbuild": "^0.19.5",
Expand All @@ -32,12 +32,12 @@
"dependencies": {
"@azure/identity": "^3.3.2",
"@microsoft/kiota-abstractions": "^1.0.0-preview.29",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.23",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.27",
"@microsoft/kiota-authentication-azure": "^1.0.0-preview.24",
"@microsoft/kiota-http-fetchlibrary": "^1.0.0-preview.28",
"@microsoft/kiota-serialization-form": "^1.0.0-preview.18",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.28",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.7",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.25",
"@microsoft/kiota-serialization-json": "^1.0.0-preview.29",
"@microsoft/kiota-serialization-multipart": "^1.0.0-preview.8",
"@microsoft/kiota-serialization-text": "^1.0.0-preview.26",
"express": "^4.18.2",
"node-fetch": "^2.7.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ internal static DeprecationInformation GetDeprecationInformation(this OpenApiOpe
return deprecatedValue.ToDeprecationInformation();
else if (operation.Responses.Values
.SelectMany(static x => x.Content.Values)
.Select(static x => x.Schema)
.Where(static x => x != null && !x.IsReferencedSchema())
.Select(static x => x?.Schema)
.OfType<OpenApiSchema>()
.Where(static x => !x.IsReferencedSchema())
.Select(static x => x.GetDeprecationInformation())
.FirstOrDefault(static x => x.IsDeprecated) is DeprecationInformation responseDeprecationInformation)
return responseDeprecationInformation;
else if (operation.RequestBody?.Content.Values
.Select(static x => x.Schema)
.Where(static x => x != null && !x.IsReferencedSchema())
.Select(static x => x?.Schema)
.OfType<OpenApiSchema>()
.Where(static x => !x.IsReferencedSchema())
.Select(static x => x.GetDeprecationInformation())
.FirstOrDefault(static x => x.IsDeprecated) is DeprecationInformation requestDeprecationInformation)
return requestDeprecationInformation;
Expand Down
22 changes: 18 additions & 4 deletions src/Kiota.Builder/Lock/LockManagementService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ public IEnumerable<string> GetDirectoriesContainingLockFile(string searchDirecto
}
private static async Task<KiotaLock?> GetLockFromDirectoryInternalAsync(string directoryPath, CancellationToken cancellationToken)
{
var lockFile = Path.Combine(directoryPath, LockFileName);
if (File.Exists(lockFile))
var lockFilePath = Path.Combine(directoryPath, LockFileName);
if (File.Exists(lockFilePath))
{
#pragma warning disable CA2007
await using var fileStream = File.OpenRead(lockFile);
await using var fileStream = File.OpenRead(lockFilePath);
#pragma warning restore CA2007
return await GetLockFromStreamInternalAsync(fileStream, cancellationToken).ConfigureAwait(false);
var result = await GetLockFromStreamInternalAsync(fileStream, cancellationToken).ConfigureAwait(false);
if (result is not null && IsDescriptionLocal(result.DescriptionLocation) && !Path.IsPathRooted(result.DescriptionLocation))
{
result.DescriptionLocation = Path.GetFullPath(Path.Combine(directoryPath, result.DescriptionLocation));
}
return result;
}
return null;
}
Expand Down Expand Up @@ -70,8 +75,17 @@ private static async Task WriteLockFileInternalAsync(string directoryPath, Kiota
#pragma warning disable CA2007
await using var fileStream = File.Open(lockFilePath, FileMode.Create);
#pragma warning restore CA2007
lockInfo.DescriptionLocation = GetRelativeDescriptionPath(lockInfo.DescriptionLocation, lockFilePath);
await JsonSerializer.SerializeAsync(fileStream, lockInfo, context.KiotaLock, cancellationToken).ConfigureAwait(false);
}
private static bool IsDescriptionLocal(string descriptionPath) => !descriptionPath.StartsWith("http", StringComparison.OrdinalIgnoreCase);
private static string GetRelativeDescriptionPath(string descriptionPath, string lockFilePath)
{
if (IsDescriptionLocal(descriptionPath) &&
Path.GetDirectoryName(lockFilePath) is string lockFileDirectoryPath)
return Path.GetRelativePath(lockFileDirectoryPath, descriptionPath);
return descriptionPath;
}
/// <inheritdoc/>
public Task BackupLockFileAsync(string directoryPath, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,31 @@ public void GetsNoDeprecationOnNonDeprecatedOperation()
Assert.Null(deprecationInformation.Description);
}
[Fact]
public void GetsDeprecationOnOperationWithNullResponseContentTypeInstance()
{
var operation = new OpenApiOperation
{
Deprecated = false,
Responses = new OpenApiResponses
{
{
"200", new OpenApiResponse
{
Content = new Dictionary<string, OpenApiMediaType>()
{
{ "application/json", null
}
}
}
}
}
};
var deprecationInformation = operation.GetDeprecationInformation();
Assert.NotNull(deprecationInformation);
Assert.False(deprecationInformation.IsDeprecated);
Assert.Null(deprecationInformation.Description);
}
[Fact]
public void GetsDeprecationOnOperationWithDeprecatedInlineResponseSchema()
{
var operation = new OpenApiOperation
Expand Down Expand Up @@ -245,6 +270,26 @@ public void GetsDeprecationOnOperationWithDeprecatedInlineRequestSchema()
Assert.Equal("description", deprecationInformation.Description);
}
[Fact]
public void GetsDeprecationOnOperationWithNullRequestBodyContentTypeInstance()
{
var operation = new OpenApiOperation
{
Deprecated = false,
RequestBody = new OpenApiRequestBody
{
Content = new Dictionary<string, OpenApiMediaType>()
{
{ "application/json", null
}
}
}
};
var deprecationInformation = operation.GetDeprecationInformation();
Assert.NotNull(deprecationInformation);
Assert.False(deprecationInformation.IsDeprecated);
Assert.Null(deprecationInformation.Description);
}
[Fact]
public void GetsNoDeprecationOnOperationWithDeprecatedReferenceRequestSchema()
{
var operation = new OpenApiOperation
Expand Down
25 changes: 23 additions & 2 deletions tests/Kiota.Builder.Tests/Lock/LockManagementServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Kiota.Builder.Tests.Lock;
public class LockManagementServiceTests
{
[Fact]
public async Task DefensivePrograming()
public async Task DefensiveProgramming()
{
var lockManagementService = new LockManagementService();
Assert.Throws<ArgumentNullException>(() => lockManagementService.GetDirectoriesContainingLockFile(null));
Expand All @@ -22,13 +22,34 @@ public async Task DefensivePrograming()
public async Task Identity()
{
var lockManagementService = new LockManagementService();
var descriptionPath = Path.Combine(Path.GetTempPath(), "description.yml");
var lockFile = new KiotaLock
{
DescriptionLocation = "description",
ClientClassName = "foo",
ClientNamespaceName = "bar",
DescriptionLocation = descriptionPath,
};
var path = Path.GetTempPath();
await lockManagementService.WriteLockFileAsync(path, lockFile);
lockFile.DescriptionLocation = Path.GetFullPath(descriptionPath); // expected since we write the relative path but read to the full path
var result = await lockManagementService.GetLockFromDirectoryAsync(path);
Assert.Equal(lockFile, result, new KiotaLockComparer());
}
[Fact]
public async Task UsesRelativePaths()
{
var tmpPath = Path.Combine(Path.GetTempPath(), "tests", "kiota");
var lockManagementService = new LockManagementService();
var descriptionPath = Path.Combine(tmpPath, "information", "description.yml");
var descriptionDirectory = Path.GetDirectoryName(descriptionPath);
Directory.CreateDirectory(descriptionDirectory);
var lockFile = new KiotaLock
{
DescriptionLocation = descriptionPath,
};
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);
}
}
Loading

0 comments on commit af26dc0

Please sign in to comment.