diff --git a/CHANGELOG.md b/CHANGELOG.md index e62774ff34..235d347d51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Switched to lazy loading module imports in Python. [#2007](https://github.com/microsoft/kiota/issues/2007) - Caters for type names being used from System namespace in CSharp generation [#2021](https://github.com/microsoft/kiota/issues/2021) - Fixed wrong send request method name for collections in Python. [#2057](https://github.com/microsoft/kiota/issues/2057) +- Implemented request builders with no parameters as properties in Python. [#2024](https://github.com/microsoft/kiota/issues/2024) ## [0.8.3] - 2022-12-01 diff --git a/src/Kiota.Builder/Writers/Python/CodePropertyWriter.cs b/src/Kiota.Builder/Writers/Python/CodePropertyWriter.cs index 661546136a..fc5a31bc26 100644 --- a/src/Kiota.Builder/Writers/Python/CodePropertyWriter.cs +++ b/src/Kiota.Builder/Writers/Python/CodePropertyWriter.cs @@ -15,6 +15,7 @@ public override void WriteCodeElement(CodeProperty codeElement, LanguageWriter w */ switch(codeElement.Kind) { case CodePropertyKind.RequestBuilder: + writer.WriteLine("@property"); writer.WriteLine($"def {codeElement.Name.ToSnakeCase()}(self) -> {returnType}:"); writer.IncreaseIndent(); conventions.WriteShortDescription(codeElement.Documentation.Description, writer); diff --git a/tests/Kiota.Builder.Tests/Writers/Python/CodePropertyWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Python/CodePropertyWriterTests.cs index 6f52765eb2..95c3dadae0 100644 --- a/tests/Kiota.Builder.Tests/Writers/Python/CodePropertyWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Python/CodePropertyWriterTests.cs @@ -49,6 +49,7 @@ public void WritesRequestBuilder() { property.Documentation.Description = "This is a request builder"; writer.Write(property); var result = tw.ToString(); + Assert.Contains("@property", result); Assert.Contains("def property_name(", result); Assert.Contains("This is a request builder", result); Assert.Contains($"return {TypeName.ToLower()}.{TypeName}(", result); @@ -60,6 +61,7 @@ public void WritesQueryParameters() { property.Kind = CodePropertyKind.QueryParameters; writer.Write(property); var result = tw.ToString(); + Assert.DoesNotContain("@property", result); Assert.Contains($"property_name: Optional[{TypeName.ToLower()}.{TypeName}]", result); } [Fact]