Skip to content

Commit

Permalink
Merge pull request #5770 from microsoft/5635-php---doc-comments-with-…
Browse files Browse the repository at this point in the history
…-lead-to-invalid-code

Fixes invalid code in Php caused by `/*/*`` in property description
  • Loading branch information
timayabi2020 authored Nov 14, 2024
2 parents 0618d19 + c6e86b5 commit 7dedd9a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed python generation in scenarios with opening/closing tags for code comments. [#5636](https://github.com/microsoft/kiota/issues/5636)
- 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

Expand Down
10 changes: 5 additions & 5 deletions it/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"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"
},
{
"Language": "php",
"Rationale": "https://github.com/microsoft/kiota/issues/5779"
}
],
"ExcludePatterns": [
Expand Down Expand Up @@ -259,4 +259,4 @@
"Suppressions": [],
"IdempotencySuppressions": []
}
}
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Php/CodeEnumWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Php/PhpConventionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("*/", string.Empty, StringComparison.OrdinalIgnoreCase);
public override bool WriteShortDescription(IDocumentedElement element, LanguageWriter writer, string prefix = "", string suffix = "")
{
ArgumentNullException.ThrowIfNull(writer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Kiota.Builder.Tests/Writers/Php/CodePropertyWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,26 @@ public async Task WriteRequestOptionAsync()
Assert.Contains("@var array<RequestOption>|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);
}
}

0 comments on commit 7dedd9a

Please sign in to comment.