From 2b23581f0860a05b433b5115bff340124523ddf4 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 13 Nov 2024 17:04:51 +0300 Subject: [PATCH 1/6] Fixed invalid code in Php caused by "*/*/" in property description --- CHANGELOG.md | 2 +- .../Writers/Php/PhpConventionService.cs | 2 +- .../Writers/Php/CodePropertyWriterTests.cs | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b6590f54..71e6a1821e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,9 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed - - Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) - Fix anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353) +- Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) ## [1.20.0] - 2024-11-07 diff --git a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs index 67cee78295..2f74723278 100644 --- a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs +++ b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs @@ -135,7 +135,7 @@ private string GetCollectionDocString(CodeParameter codeParameter) return codeParameter.Optional ? $"{doc}|null" : doc; } - internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase); + internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("*/", "", StringComparison.OrdinalIgnoreCase); public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "") { ArgumentNullException.ThrowIfNull(writer); diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs index a00225e813..4b96585405 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs @@ -246,4 +246,26 @@ public async Task WriteRequestOptionAsync() Assert.Contains("@var array|null $options", result); Assert.Contains("public ?array $options = null;", result); } + + [Fact] + public void WritePropertyWithDescription() + { + CodeProperty property = new CodeProperty + { + Name = "name", + Documentation = new() + { + DescriptionTemplate = "The name pattern that branches must match in order to deploy to the environment.Wildcard characters will not match `/`. For example, to match branches that begin with `release/` and contain an additional single slash, use `release/*/*`.For more information about pattern matching syntax, see the [Ruby File.fnmatch documentation](https://ruby-doc.org/core-2.5.1/File.html#method-c-fnmatch).", + }, + Type = new CodeType + { + Name = "string" + }, + Access = AccessModifier.Private + }; + parentClass.AddProperty(property); + propertyWriter.WriteCodeElement(property, languageWriter); + var result = stringWriter.ToString(); + Assert.DoesNotContain("/*/*", result); + } } From 2a5095195c7e918fe3f2a5582ebe1fdb67c46aa2 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 13 Nov 2024 17:22:19 +0300 Subject: [PATCH 2/6] Retained extra space at the top --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e6a1821e..1e849b57b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Changed + - Fixed Python error when a class inherits from a base class and implements an interface. [5637](https://github.com/microsoft/kiota/issues/5637) - Fix anyOf/oneOf generation in TypeScript. [5353](https://github.com/microsoft/kiota/issues/5353) - Fixed invalid code in Php caused by "*/*/" in property description. [5635](https://github.com/microsoft/kiota/issues/5635) From b8069c0ff209337bf9a3494e1255e45fe19dd1ea Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 13 Nov 2024 10:06:53 -0500 Subject: [PATCH 3/6] chore: removes suppression in integration test --- it/config.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/it/config.json b/it/config.json index 78f4d857ab..d06d269e52 100644 --- a/it/config.json +++ b/it/config.json @@ -33,10 +33,6 @@ "Language": "typescript", "Rationale": "https://github.com/microsoft/kiota/issues/5634" }, - { - "Language": "php", - "Rationale": "https://github.com/microsoft/kiota/issues/5635" - }, { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" @@ -267,4 +263,4 @@ "Suppressions": [], "IdempotencySuppressions": [] } -} \ No newline at end of file +} From 2292e43b0c54222e55bda4082296f505aadcc6d2 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Wed, 13 Nov 2024 10:07:12 -0500 Subject: [PATCH 4/6] chore: applies review suggestions --- src/Kiota.Builder/Writers/Php/PhpConventionService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs index 2f74723278..230fa1b527 100644 --- a/src/Kiota.Builder/Writers/Php/PhpConventionService.cs +++ b/src/Kiota.Builder/Writers/Php/PhpConventionService.cs @@ -135,7 +135,7 @@ private string GetCollectionDocString(CodeParameter codeParameter) return codeParameter.Optional ? $"{doc}|null" : doc; } - internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("*/", "", StringComparison.OrdinalIgnoreCase); + internal static string RemoveInvalidDescriptionCharacters(string originalDescription) => originalDescription.Replace("\\", "/", StringComparison.OrdinalIgnoreCase).Replace("*/", string.Empty, StringComparison.OrdinalIgnoreCase); public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "") { ArgumentNullException.ThrowIfNull(writer); From d472aeb2ef9a1d737944aaf4f77381d5e423cffb Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Wed, 13 Nov 2024 23:09:55 +0300 Subject: [PATCH 5/6] Replaced the enclosing of enum values from single to double quotes. This accomodates values with apostrophe --- src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs | 2 +- tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs b/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs index b85e876273..cd6789a8fa 100644 --- a/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs +++ b/src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs @@ -47,7 +47,7 @@ public override void WriteCodeElement(CodeEnum codeElement, LanguageWriter write writer.IncreaseIndent(); foreach (var enumProperty in enumProperties) { - writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = '{enumProperty.WireName}';"); + writer.WriteLine($"public const {GetEnumValueName(enumProperty.Name)} = \"{enumProperty.WireName}\";"); } } [GeneratedRegex(@"([A-Z]{1})", RegexOptions.Singleline, 500)] diff --git a/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs b/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs index 62ce1a24ec..609434152f 100644 --- a/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs +++ b/tests/Kiota.Builder.Tests/Writers/Php/CodeEnumWriterTests.cs @@ -52,7 +52,7 @@ public async Task WritesEnumAsync() Assert.Contains("use Microsoft\\Kiota\\Abstractions\\Enum", result); Assert.Contains("class", result); Assert.Contains("extends Enum", result); - Assert.Contains($"public const {optionName.ToUpperInvariant()} = '{optionName}'", result); + Assert.Contains($"public const {optionName.ToUpperInvariant()} = \"{optionName}\"", result); AssertExtensions.CurlyBracesAreClosed(result, 1); Assert.Contains(optionName, result); } From c6e86b5ac85abb0fdb68541cce8de124e6524103 Mon Sep 17 00:00:00 2001 From: Microsoft Graph DevX Tooling Date: Thu, 14 Nov 2024 15:12:13 +0300 Subject: [PATCH 6/6] Added suppression and tied it to a known issue which will be fixed later --- it/config.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/it/config.json b/it/config.json index e8c8f66441..dab857bc52 100644 --- a/it/config.json +++ b/it/config.json @@ -36,6 +36,10 @@ { "Language": "ruby", "Rationale": "https://github.com/microsoft/kiota/issues/1816" + }, + { + "Language": "php", + "Rationale": "https://github.com/microsoft/kiota/issues/5779" } ], "ExcludePatterns": [