🐛 fix +listType marker not working on type alias fields#1359
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sivchari 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 |
06bfcda to
a39b281
Compare
a39b281 to
639035d
Compare
639035d to
4d23c3a
Compare
|
Code change looks good but we do need to fix the commit message please |
4d23c3a to
98002b0
Compare
|
Sorry, fixed. |
|
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
| // For type aliases to slice/map types, include the underlying type information | ||
| // so that markers like +listType can be applied at the field level. |
There was a problem hiding this comment.
| // For type aliases to slice/map types, include the underlying type information | |
| // so that markers like +listType can be applied at the field level. | |
| ▎ // Set the type for slice and map aliases so field-level markers like +listType | |
| ▎ // and +mapType can work. Structs are skipped — they use a $ref only. |
I think we sould need to shape it here.
| // For type aliases to slice/map types, include the underlying type information | ||
| // so that markers like +listType can be applied at the field level. | ||
| props := &apiextensionsv1.JSONSchemaProps{ |
There was a problem hiding this comment.
| // For type aliases to slice/map types, include the underlying type information | |
| // so that markers like +listType can be applied at the field level. | |
| props := &apiextensionsv1.JSONSchemaProps{ | |
| ▎ // Set the type for slice and map aliases so field-level markers like +listType | |
| ▎ // and +mapType can work. Structs are skipped — they use a $ref only. | |
| props := &apiextensionsv1.JSONSchemaProps{ |
here too?
| @@ -312,26 +315,31 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiextensionsv1.J | |||
| ctx.requestSchema(pkgPath, typeNameInfo.Name()) | |||
| link := TypeRefLink(pkgPath, typeNameInfo.Name()) | |||
|
|
|||
There was a problem hiding this comment.
| resolvedType := typeInfoRaw | |
| if aliasInfo, isAlias := typeInfoRaw.(*types.Alias); isAlias { | |
| resolvedType = aliasInfo.Rhs() | |
| } |
I think we need to handle the case where Go 1.23+ represents type aliases as *types.Alias instead of *types.Named. Right now if someone has type Foo = []T in an external package, isNamed is false, typ stays empty and +listType still fails — same as before this fix. Could you add the alias unwrap before the switch? That seems like a blocker for merging this one.
There was a problem hiding this comment.
Yes, addressed with types.Unalias() so slice/map aliases resolve correctly and +listType/+mapType apply
| @@ -207,6 +207,12 @@ type CronJobSpec struct { | |||
| // This tests that associative lists work via a nested type. | |||
There was a problem hiding this comment.
The PR adds props.Type = "object" for map aliases to make +mapType work at the field level, but there's no test covering that path. Could you add a field with a map alias type and +mapType on it? Without it a regression there would go unnoticed. Could you please add ?
|
|
||
| // +kubebuilder:validation:MinLength=4 | ||
| // This tests that markers that are allowed on both fields and types are applied to types | ||
| type LongerString string |
There was a problem hiding this comment.
Hey, I was looking at flattenAllOfInto and noticed XListType and XListMapKeys don't have their own case there. If both the type and the field have +listType set, they'll hit default: and the annotation gets wiped from the top level of the CRD.
Could it not be a silent failure? XMapType has its own case already so it handles this fine, could we do the same for these two?
camilamacedo86
left a comment
There was a problem hiding this comment.
Thank you so much for looking on this one 🎉
I just try to do a full review. Could you please check it out?
Can you please rebase with main and address those ones?
Then, I would be happy to LGTM this one.
Thank you 🚀
|
/remove-lifecycle stale |
98002b0 to
9284ccd
Compare
|
I addressed these comments. Thnaks. |
|
Hi @sivchari Could you please ensure that pass in the lint check and the tests? |
bb50795 to
d7f3da5
Compare
Include underlying type info (array/object) in schema for slice/map type aliases, allowing field-level markers like +listType to work. Signed-off-by: sivchari <shibuuuu5@gmail.com>
d7f3da5 to
1d22cac
Compare
|
CI green now. |
Include underlying type info (array/object) in schema for slice/map type aliases, allowing field-level markers like +listType to work.
Fixes #988