Skip to content

Commit a7ed777

Browse files
committed
pkg/crd: fix alias type parsing
Using Underlying() was working for basic types but was resolving "too far" for more complex type, as for the structure. I.e. instead of retrieving the new type for aliased, it actually retrieved the underyling (who could have guessed) actual type. For example, for a string alias, we have: - Alias type info: testdata.kubebuilder.io/cronjob.StringAlias - Rhs from the alias def: string - Underlying from the alias: string But for a struct alias, we have: - Alias type info: testdata.kubebuilder.io/cronjob.InlineAlias - Rhs from the alias def: testdata.kubebuilder.io/cronjob.EmbeddedStruct - Underlying from the alias: struct{FromEmbedded string "json:\"fromEmbedded,omitempty\""} I also imagine that we don't handle nested alias, but this is for another patch. Signed-off-by: Mahe Tardy <[email protected]>
1 parent 7a92e7b commit a7ed777

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/crd/schema.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
268268
// This reproduces the behavior we had pre gotypesalias=1 (needed if this
269269
// project is compiled with default settings and Go >= 1.23).
270270
if aliasInfo, isAlias := typeInfo.(*types.Alias); isAlias {
271-
typeInfo = aliasInfo.Underlying()
271+
typeInfo = aliasInfo.Rhs()
272272
}
273273
if basicInfo, isBasic := typeInfo.(*types.Basic); isBasic {
274274
typ, fmt, err := builtinToType(basicInfo, ctx.allowDangerousTypes)

0 commit comments

Comments
 (0)