Preserve empty string enum values during generation#7990
Open
AayushP123 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
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
CodeEnumOptioninstances 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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