mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-10-21 22:49:31 +00:00
pin openapi
This commit is contained in:
52
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
generated
vendored
52
vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
generated
vendored
@@ -594,11 +594,43 @@ func defaultFromComments(comments []string, commentPath string, t *types.Type) (
|
||||
return i, nil, nil
|
||||
}
|
||||
|
||||
func mustEnforceDefault(t *types.Type, omitEmpty bool) (interface{}, error) {
|
||||
func implementsCustomUnmarshalling(t *types.Type) bool {
|
||||
switch t.Kind {
|
||||
case types.Pointer:
|
||||
unmarshaller, isUnmarshaller := t.Elem.Methods["UnmarshalJSON"]
|
||||
return isUnmarshaller && unmarshaller.Signature.Receiver.Kind == types.Pointer
|
||||
case types.Struct:
|
||||
_, isUnmarshaller := t.Methods["UnmarshalJSON"]
|
||||
return isUnmarshaller
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func mustEnforceDefault(t *types.Type, omitEmpty bool) (interface{}, error) {
|
||||
// Treat types with custom unmarshalling as a value
|
||||
// (Can be alias, struct, or pointer)
|
||||
if implementsCustomUnmarshalling(t) {
|
||||
// Since Go JSON deserializer always feeds `null` when present
|
||||
// to structs with custom UnmarshalJSON, the zero value for
|
||||
// these structs is also null.
|
||||
//
|
||||
// In general, Kubernetes API types with custom marshalling should
|
||||
// marshal their empty values to `null`.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
switch t.Kind {
|
||||
case types.Alias:
|
||||
return mustEnforceDefault(t.Underlying, omitEmpty)
|
||||
case types.Pointer, types.Map, types.Slice, types.Array, types.Interface:
|
||||
return nil, nil
|
||||
case types.Struct:
|
||||
if len(t.Members) == 1 && t.Members[0].Embedded {
|
||||
// Treat a struct with a single embedded member the same as an alias
|
||||
return mustEnforceDefault(t.Members[0].Type, omitEmpty)
|
||||
}
|
||||
|
||||
return map[string]interface{}{}, nil
|
||||
case types.Builtin:
|
||||
if !omitEmpty {
|
||||
@@ -619,7 +651,7 @@ func (g openAPITypeWriter) generateDefault(comments []string, t *types.Type, omi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if enforced, err := mustEnforceDefault(resolveAliasAndEmbeddedType(t), omitEmpty); err != nil {
|
||||
if enforced, err := mustEnforceDefault(t, omitEmpty); err != nil {
|
||||
return err
|
||||
} else if enforced != nil {
|
||||
if def == nil {
|
||||
@@ -751,22 +783,6 @@ func (g openAPITypeWriter) generateReferenceProperty(t *types.Type) {
|
||||
g.Do("Ref: ref(\"$.$\"),\n", t.Name.String())
|
||||
}
|
||||
|
||||
func resolveAliasAndEmbeddedType(t *types.Type) *types.Type {
|
||||
var prev *types.Type
|
||||
for prev != t {
|
||||
prev = t
|
||||
if t.Kind == types.Alias {
|
||||
t = t.Underlying
|
||||
}
|
||||
if t.Kind == types.Struct {
|
||||
if len(t.Members) == 1 && t.Members[0].Embedded {
|
||||
t = t.Members[0].Type
|
||||
}
|
||||
}
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func resolveAliasAndPtrType(t *types.Type) *types.Type {
|
||||
var prev *types.Type
|
||||
for prev != t {
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@@ -2140,7 +2140,7 @@ k8s.io/kube-aggregator/pkg/registry/apiservice/rest
|
||||
# k8s.io/kube-controller-manager v0.0.0 => ./staging/src/k8s.io/kube-controller-manager
|
||||
## explicit; go 1.20
|
||||
k8s.io/kube-controller-manager/config/v1alpha1
|
||||
# k8s.io/kube-openapi v0.0.0-20231009201959-f62364c3c354
|
||||
# k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00
|
||||
## explicit; go 1.19
|
||||
k8s.io/kube-openapi/cmd/openapi-gen
|
||||
k8s.io/kube-openapi/cmd/openapi-gen/args
|
||||
|
Reference in New Issue
Block a user