diff --git a/internal/schemas/generator/go.go b/internal/schemas/generator/go.go index c57784e8..f2f54ab8 100644 --- a/internal/schemas/generator/go.go +++ b/internal/schemas/generator/go.go @@ -214,6 +214,7 @@ import ( "time" "github.com/oapi-codegen/runtime" + openapi_types "github.com/oapi-codegen/runtime/types" {{- range .ExternalImports}} {{ . }} @@ -229,6 +230,7 @@ var ( _ json.RawMessage = nil _ = fmt.Errorf _ = runtime.JSONMerge + _ openapi_types.Email ) ` diff --git a/internal/schemas/generator/runtimeobject.go b/internal/schemas/generator/runtimeobject.go index 1acf5c6e..b993756a 100644 --- a/internal/schemas/generator/runtimeobject.go +++ b/internal/schemas/generator/runtimeobject.go @@ -35,6 +35,10 @@ const ( roRuntimeAlias = "k8sruntime" roRuntimeImport = "k8s.io/apimachinery/pkg/runtime" roSchemaImport = "k8s.io/apimachinery/pkg/runtime/schema" + + // roOpenAPITypesAlias is the alias oapi-codegen uses for its formatted + // string types (Email, Date, File, UUID). + roOpenAPITypesAlias = "openapi_types" ) // roScalarSelectorTypes are k8s types referenced via a package selector that are @@ -216,7 +220,11 @@ func classifyElem(e ast.Expr, structs map[string]bool) fieldKind { // pkg.Type — time.* and known alias types (Time, MicroTime, FieldsV1) // are scalars; every other referenced package type is a generated struct // with a DeepCopyInto method. - if pkg, ok := x.X.(*ast.Ident); ok && pkg.Name == "time" { + if pkg, ok := x.X.(*ast.Ident); ok && (pkg.Name == "time" || pkg.Name == roOpenAPITypesAlias) { + // oapi-codegen emits openapi_types.Email, Date, File and UUID for + // formatted strings. None of them has a DeepCopyInto method: + // Email is a string, UUID is an array, Date wraps a time.Time and + // File holds unexported fields. They copy by value. return fkScalar } if roScalarSelectorTypes[x.Sel.Name] { diff --git a/internal/schemas/generator/testdata/account_scaffold_definition.yaml b/internal/schemas/generator/testdata/account_scaffold_definition.yaml index 95495fdf..977321fd 100644 --- a/internal/schemas/generator/testdata/account_scaffold_definition.yaml +++ b/internal/schemas/generator/testdata/account_scaffold_definition.yaml @@ -35,6 +35,13 @@ spec: type: string description: | The name of the account to be scaffolded. + members: + type: array + description: | + Member principals for the account. + items: + type: string + format: email required: - name required: