chore(controlplane): adopt go fix's rewrites in schema.go
task fmt is not a formatter: it runs go fix to a fixpoint and then
golangci-lint's formatters, so a package can be gofmt-clean and still
go-fix-dirty. The merge train's full gate on 0c25a1fc caught exactly that and
rewrote this file -- reflect.TypeFor[T]() in place of reflect.TypeOf(T(0)), the
t.Fields() iterator, and maps.Copy over a manual key-by-key copy.
Adopted verbatim; formatter output is law here. The remaining stages of that
gate ran against this content, so it arrives verified rather than merely
formatted. The author's scoped gate could not have caught it: gofumpt and
golangci-lint fmt agree with the original text, and only go fix disagrees.
This commit is contained in:
1 parent
0c25a1fc6e
commit
0d8c4383a0
1 file changed
+6
-8
@@ -2,6 +2,7 @@ package controlplane
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"maps"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -16,9 +17,9 @@ import (
|
||||
const bareObjectSchema = `{"type":"object"}`
|
||||
|
||||
var (
|
||||
configDurationType = reflect.TypeOf(config.Duration(0))
|
||||
channelDurationType = reflect.TypeOf(channelDuration(0))
|
||||
timeType = reflect.TypeOf(time.Time{})
|
||||
configDurationType = reflect.TypeFor[config.Duration]()
|
||||
channelDurationType = reflect.TypeFor[channelDuration]()
|
||||
timeType = reflect.TypeFor[time.Time]()
|
||||
)
|
||||
|
||||
// schemaJSON renders the JSON Schema a resource descriptor advertises, derived
|
||||
@@ -90,8 +91,7 @@ func schemaOf(t reflect.Type) map[string]any {
|
||||
|
||||
func objectSchemaOf(t reflect.Type) map[string]any {
|
||||
properties := map[string]any{}
|
||||
for i := range t.NumField() {
|
||||
field := t.Field(i)
|
||||
for field := range t.Fields() {
|
||||
if field.Anonymous {
|
||||
// encoding/json promotes an embedded struct's fields into the
|
||||
// enclosing object, so the schema lists them there too. Dropping
|
||||
@@ -100,9 +100,7 @@ func objectSchemaOf(t reflect.Type) map[string]any {
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for name, property := range embedded {
|
||||
properties[name] = property
|
||||
}
|
||||
maps.Copy(properties, embedded)
|
||||
continue
|
||||
}
|
||||
if field.PkgPath != "" {
|
||||
|
||||
Reference in new issue
Block a user