✨Support XValidation on type aliases to map/slice/pointer types - #1463
Open
dongjiang1989 wants to merge 1 commit into
Open
✨Support XValidation on type aliases to map/slice/pointer types#1463dongjiang1989 wants to merge 1 commit into
dongjiang1989 wants to merge 1 commit into
Conversation
Contributor
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dongjiang1989 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
controller-gen did not generate x-kubernetes-validations for type aliases
to complex types (e.g. type X = map[string]string). The alias was unwrapped
to the underlying type, which hit the default case in localNamedToSchema
and produced an error ("unsupported type *types.Map for identifier X").
For user-defined aliases to non-basic, non-named types, emit a $ref to
the alias type so the flattener resolves it via infoToSchema, applying
markers on the alias declaration. Basic and named type aliases keep
their existing behavior.
Fixes: kubernetes-sigs#1462
Signed-off-by: dongjiang <[email protected]>
dongjiang1989
force-pushed
the
object-alias-XValidation
branch
from
August 5, 2026 09:22
43921d4 to
9f9967c
Compare
Member
Author
|
cc @sbueringer PTAL, thanks |
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.
What does this PR do, and why do we need it?
Fixes #1462
controller-gendid not generatex-kubernetes-validationsfor type aliases to complex types (e.g.type X = map[string]string). The alias was unwrapped to the underlying type inlocalNamedToSchema, which hit the default case and produced an error:Changes
For user-defined type aliases (
type X = Y) whose RHS is a non-basic, non-named type (map, slice, pointer, etc.), emit a$refto the alias type instead of unwrapping it. The flattener then resolves the$refviainfoToSchema, which correctly applies markers on the alias declaration (including+kubebuilder:validation:XValidation).Behavior for other alias types is preserved:
type X = string): unwrap, emit inline type/format +$ref(preserves field-level markers like MinLength/MaxLength)type X = SomeStruct): unwrap, emit$refto the underlying named type (preserves inline/embedded struct alias behavior and applyconfiguration generator compatibility)any): unwrap (no$ref, sinceanyis not a user-defined type)Example
Now correctly generates: