Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums should not be escaped in Go #4136

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading