Skip to content

Commit

Permalink
Enums should not be escaped in Go
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Feb 5, 2024
1 parent 6077e9f commit 5e60a60
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed
- Fixed mantis for bitwise enums in Go. [#3936](https://github.com/microsoft/kiota/issues/3936)
- Keyword in enum names for go should not be escaped. [#2877](https://github.com/microsoft/kiota/issues/2877)

## [1.11.1] - 2024-02-05

Expand Down
5 changes: 3 additions & 2 deletions src/Kiota.Builder/Refiners/GoRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
generatedCode,
new GoReservedNamesProvider(),
x => $"{x}Escaped",
shouldReplaceCallback: x => x is not CodeProperty currentProp ||
shouldReplaceCallback: x => (x is not CodeEnumOption && x is not CodeEnum) && // enums and enum options start with uppercase
(x is not CodeProperty currentProp ||
!(currentProp.Parent is CodeClass parentClass &&
parentClass.IsOfKind(CodeClassKind.QueryParameters, CodeClassKind.ParameterSet) &&
currentProp.Access == AccessModifier.Public)); // Go reserved keywords are all lowercase and public properties are uppercased when we don't provide accessors (models)
currentProp.Access == AccessModifier.Public))); // Go reserved keywords are all lowercase and public properties are uppercased when we don't provide accessors (models)
ReplaceReservedExceptionPropertyNames(generatedCode, new GoExceptionsReservedNamesProvider(), x => $"{x}Escaped");
cancellationToken.ThrowIfCancellationRequested();
AddPropertiesAndMethodTypesImports(
Expand Down
4 changes: 3 additions & 1 deletion tests/Kiota.Builder.Tests/Refiners/GoLanguageRefinerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public async Task AddsInnerClasses()
await ILanguageRefiner.Refine(new GenerationConfiguration { Language = GenerationLanguage.Go }, root);
Assert.Equal(2, requestBuilder.GetChildElements(true).Count());
}
[Theory(Skip = "Fixing this test is a breaking change - https://github.com/microsoft/kiota/issues/2877")]


[Theory]
[InlineData("break")]
[InlineData("case")]
public async Task EnumWithReservedName_IsNotRenamed(string input)
Expand Down

0 comments on commit 5e60a60

Please sign in to comment.