Skip to content

Commit

Permalink
pkg/crd: fix alias type parsing
Browse files Browse the repository at this point in the history
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 guess) 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 <mahe.tardy@gmail.com>
  • Loading branch information
mtardy committed Jan 6, 2025
1 parent 7a92e7b commit a1c5e9e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
// This reproduces the behavior we had pre gotypesalias=1 (needed if this
// project is compiled with default settings and Go >= 1.23).
if aliasInfo, isAlias := typeInfo.(*types.Alias); isAlias {
typeInfo = aliasInfo.Underlying()
typeInfo = aliasInfo.Rhs()
}
if basicInfo, isBasic := typeInfo.(*types.Basic); isBasic {
typ, fmt, err := builtinToType(basicInfo, ctx.allowDangerousTypes)
Expand Down

0 comments on commit a1c5e9e

Please sign in to comment.