Skip to content

Commit d944deb

Browse files
committed
Support type aliasing to basic types
Previously, validation schema generation was skipped on a type alias: ``` type A = B ``` Whereas, a new type was fine: ``` type A B ``` This commit implements support for generating validation schemas for type aliases to basic types, i.e. string, int, etc. Signed-off-by: Chris Tarazi <[email protected]>
1 parent 7bb5dee commit d944deb

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/crd/schema.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,21 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
208208
if err != nil {
209209
ctx.pkg.AddError(loader.ErrFromNode(err, ident))
210210
}
211+
212+
// Check for type aliasing. If the type is not an alias, then handle it
213+
// as a basic type.
214+
if basicInfo.Name() == ident.Name {
215+
return &apiext.JSONSchemaProps{
216+
Type: typ,
217+
Format: fmt,
218+
}
219+
}
220+
221+
// Type alias to a basic type.
222+
ctx.requestSchema("", ident.Name)
223+
link := TypeRefLink("", ident.Name)
211224
return &apiext.JSONSchemaProps{
212-
Type: typ,
213-
Format: fmt,
225+
Ref: &link,
214226
}
215227
}
216228
// NB(directxman12): if there are dot imports, this might be an external reference,

0 commit comments

Comments
 (0)