From 7e7f2e9449f544e9a4011373bc00c65a863499b9 Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Sat, 18 Sep 2021 15:55:56 -0400 Subject: [PATCH] :bug: Be more helpful with floats when allowDangerousTypes=false Currently, we fall through and just emit an error telling that floats are not supported which lead to ppl creating prs to add support. We actually do support them although that is discouraged. This change makes us emit a more helpful error. --- pkg/crd/schema.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/crd/schema.go b/pkg/crd/schema.go index d2112db35..be6103a09 100644 --- a/pkg/crd/schema.go +++ b/pkg/crd/schema.go @@ -17,6 +17,7 @@ limitations under the License. package crd import ( + "errors" "fmt" "go/ast" "go/token" @@ -427,10 +428,13 @@ func builtinToType(basic *types.Basic, allowDangerousTypes bool) (typ string, fo typ = "string" case basicInfo&types.IsInteger != 0: typ = "integer" - case basicInfo&types.IsFloat != 0 && allowDangerousTypes: - typ = "number" + case basicInfo&types.IsFloat != 0: + if allowDangerousTypes { + typ = "number" + } else { + 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") + } default: - // NB(directxman12): floats are *NOT* allowed in kubernetes APIs return "", "", fmt.Errorf("unsupported type %q", basic.String()) }