Skip to content

Preserve empty string enum values during generation#7990

Open
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:codex/fix-go-empty-enum
Open

Preserve empty string enum values during generation#7990
AayushP123 wants to merge 1 commit into
microsoft:mainfrom
AayushP123:codex/fix-go-empty-enum

Conversation

@AayushP123

Copy link
Copy Markdown
Contributor

Summary

Retains empty string values when building enum CodeDOM options. Distinguishes an explicitly empty serialization name from an unset one, and verifies the Go writer emits and parses the empty wire value.

This allows schemas with values such as M, F, X, and "" to generate a valid constant and parser case for the empty value.

Validation

dotnet test tests/Kiota.Builder.Tests/Kiota.Builder.Tests.csproj --no-restore --nologo --filter 'FullyQualifiedName~CodeDOM.CodeEnumTests|FullyQualifiedName~Writers.Go.CodeEnumWriterTests|Name=ParsesEnumDescriptionsAsync' (14 passed)

Fixes #4329

@AayushP123
AayushP123 requested a review from a team as a code owner July 26, 2026 07:17
Copilot AI review requested due to automatic review settings July 26, 2026 07:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates Kiota’s enum CodeDOM construction to preserve explicitly empty-string enum wire values (instead of dropping them), and adds regression tests to ensure the Go writer emits and parses the empty wire value correctly—addressing #4329.

Changes:

  • Preserve empty-string enum values when building CodeEnumOption instances from OpenAPI schemas.
  • Distinguish “explicitly set (possibly empty) serialization name” from “unset serialization name” in CodeEnumOption.
  • Add tests covering empty-string enum option parsing/building and Go writer emission.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Kiota.Builder/KiotaBuilder.cs Stops filtering out empty enum values and assigns a stable option name for the empty wire value.
src/Kiota.Builder/CodeDOM/CodeEnumOption.cs Tracks whether SerializationName was explicitly set (even if empty) to preserve empty wire names.
tests/Kiota.Builder.Tests/CodeDOM/CodeEnumTests.cs Verifies explicit empty serialization name behavior in CodeEnumOption.
tests/Kiota.Builder.Tests/KiotaBuilderTests.cs Ensures enum parsing retains an empty option and keeps its wire/serialization name empty.
tests/Kiota.Builder.Tests/Writers/Go/CodeEnumWriterTests.cs Validates Go enum writer emits/handles the empty string wire value in String() and parser switch.

Comment on lines 2201 to 2205
var optionDescription = extensionInformation?.ValuesDescriptions.Find(y => y.Value.Equals(x, StringComparison.OrdinalIgnoreCase));
var optionName = optionDescription?.Name is string name && !string.IsNullOrEmpty(name) ?
name :
string.IsNullOrEmpty(x) ? "Empty" : x;
return new CodeEnumOption
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generator does not handle empty strings in enum fields (Go)

2 participants