Repository navigation
fix: skip null entries when mapping enums to OneOf validators - #15
Merged
hanneshayashi merged 1 commit intoOct 26, 2026
Merged
hanneshayashi merged 1 commit into
hanneshayashi merged 1 commit into
Conversation
A nullable enum lists null (OpenAPI 3.0 requires it for null to be valid), but decoding a YAML null into a Go string, int64 or float64 returns no error and leaves the zero value, so the generated OneOf validator accepted "" or 0. Skip null nodes before decoding; an enum that only lists null now produces no validator.
There was a problem hiding this comment.
🟢 Approval recommended
The focused fix consistently handles all three validator paths, includes unit and integration regression coverage, and has no identified blocking issues.
No open issues 🎉
What changed in this PR
Fixes #14 by preventing null enum entries from becoming unintended empty-string or zero values in generated Terraform OneOf validators.
Changes:
- Filters null nodes before decoding string, integer, and float enums.
- Adds unit and golden regression coverage for mixed and null-only enums, plus quoted
"null"strings. - Documents that null-only enums produce no validator.
| File | Description |
|---|---|
internal/mapper/oas/string.go |
Skips null entries in string enums. |
internal/mapper/oas/string_test.go |
Covers mixed, null-only, and quoted-null string enums. |
internal/mapper/oas/number.go |
Skips null entries in float enums. |
internal/mapper/oas/number_test.go |
Covers mixed and null-only float enums. |
internal/mapper/oas/integer.go |
Skips null entries in integer enums. |
internal/mapper/oas/integer_test.go |
Covers mixed and null-only integer enums. |
internal/cmd/testdata/edgecase/provider_code_spec.json |
Records expected validators without null-derived values. |
internal/cmd/testdata/edgecase/openapi_spec.yml |
Adds nullable enum integration fixtures. |
internal/cmd/testdata/edgecase/generator_config.yml |
Enables generation for the nullable enum fixture. |
DESIGN.md |
Documents null enum mapping behavior. |
Review effort: Balanced
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.
Closes #14
Problem
OpenAPI 3.0 only accepts
nullfor anullable: trueenum ifnullis listed in the enum, so specs (and vacuum'snullable-enum-contains-nullrule) list it:GetStringValidators,GetIntegerValidatorsandGetFloatValidatorsdecode each enum node into a Go value and only skip it whenDecodereturns an error. Decoding a YAMLnullreturns no error and leaves the zero value, so the generated validator wasstringvalidator.OneOf("editor", "viewer", "")(or0for integer/number enums). The downstream framework generator also appends the values to the description, which producedPossible values: `editor`, `viewer`,``.Solution
ShortTag()is!!nullbefore decoding, in the string, int64 and float64 paths. A quoted"null"or""is still a string and stays an allowed value.nullnow produces no validator, since the*ValidatorOneOfhelpers already returnnilfor an empty slice.DESIGN.md.Tests
TestGetStringValidators,TestGetIntegerValidators,TestGetFloatValidators:enum-with-nullandenum-only-nullcases. The string test also hasenum-with-quoted-null-string. All of these fail without the fix.nullable_enumresource (OAS 3.1type: [<t>, "null"]) with string, integer, double and null-only enums. It covers the real libopenapi parse path. Without the fix,TestGenerate_WithConfig/EdgeCase_APIfails with""/0in all four validators. No other golden file changes.make generateinterraform-provider-doitwith the spec from doiteng/omni#69368 (via a localreplace).doit_sharing.publicis back toOneOf("editor", "viewer")in the IR,sharing_resource_gen.goanddocs/resources/sharing.md, and the rest of the generated output is unchanged. Providermake testandmake lintpass.