Skip to content

Commit d55abc7

Browse files
authored
Merge pull request #1274 from sbueringer/pr-drop-invalid-formats
🐛 Stop setting invalid formats int32/int64 for integer types
2 parents 257e3a0 + 02ea9af commit d55abc7

File tree

3 files changed

+8
-144
lines changed

3 files changed

+8
-144
lines changed

pkg/crd/schema.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
271271
typeInfo = aliasInfo.Rhs()
272272
}
273273
if basicInfo, isBasic := typeInfo.(*types.Basic); isBasic {
274-
typ, fmt, err := builtinToType(basicInfo, ctx.allowDangerousTypes)
274+
typ, err := builtinToType(basicInfo, ctx.allowDangerousTypes)
275275
if err != nil {
276276
ctx.pkg.AddError(loader.ErrFromNode(err, ident))
277277
}
@@ -284,14 +284,12 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
284284
ctx.requestSchema("", ident.Name)
285285
link := TypeRefLink("", ident.Name)
286286
return &apiext.JSONSchemaProps{
287-
Type: typ,
288-
Format: fmt,
289-
Ref: &link,
287+
Type: typ,
288+
Ref: &link,
290289
}
291290
}
292291
return &apiext.JSONSchemaProps{
293-
Type: typ,
294-
Format: fmt,
292+
Type: typ,
295293
}
296294
}
297295
// NB(directxman12): if there are dot imports, this might be an external reference,
@@ -554,7 +552,7 @@ func validateOneOfValues(fields ...string) error {
554552
// builtinToType converts builtin basic types to their equivalent JSON schema form.
555553
// It *only* handles types allowed by the kubernetes API standards. Floats are not
556554
// allowed unless allowDangerousTypes is true
557-
func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, format string, err error) {
555+
func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, err error) {
558556
// NB(directxman12): formats from OpenAPI v3 are slightly different than those defined
559557
// in JSONSchema. This'll use the OpenAPI v3 ones, since they're useful for bounding our
560558
// non-string types.
@@ -570,20 +568,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo
570568
if allowDangerousTypes {
571569
typ = "number"
572570
} else {
573-
return "", "", errors.New("found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true")
571+
return "", errors.New("found float, the usage of which is highly discouraged, as support for them varies across languages. Please consider serializing your float as string instead. If you are really sure you want to use them, re-run with crd:allowDangerousTypes=true")
574572
}
575573
default:
576-
return "", "", fmt.Errorf("unsupported type %q", basic.String())
574+
return "", fmt.Errorf("unsupported type %q", basic.String())
577575
}
578576

579-
switch basic.Kind() {
580-
case types.Int32, types.Uint32:
581-
format = "int32"
582-
case types.Int64, types.Uint64:
583-
format = "int64"
584-
}
585-
586-
return typ, format, nil
577+
return typ, nil
587578
}
588579

589580
// Open coded go/types representation of encoding/json.Marshaller

0 commit comments

Comments
 (0)