mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #85162 from apelisse/strip-nullable
Strip nullable for Server-side apply
This commit is contained in:
commit
567b13487f
@ -1245,7 +1245,7 @@ func buildOpenAPIModelsForApply(staticOpenAPISpec *spec.Swagger, crd *apiextensi
|
|||||||
|
|
||||||
specs := []*spec.Swagger{}
|
specs := []*spec.Swagger{}
|
||||||
for _, v := range crd.Spec.Versions {
|
for _, v := range crd.Spec.Versions {
|
||||||
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, AllowNonStructural: true})
|
s, err := builder.BuildSwagger(crd, v.Name, builder.Options{V2: false, StripDefaults: true, StripValueValidation: true, StripNullable: true, AllowNonStructural: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -49,3 +49,17 @@ func (s *Structural) StripValueValidations() *Structural {
|
|||||||
v.Visit(s)
|
v.Visit(s)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// StripNullable returns a copy without nullable.
|
||||||
|
func (s *Structural) StripNullable() *Structural {
|
||||||
|
s = s.DeepCopy()
|
||||||
|
v := Visitor{
|
||||||
|
Structural: func(s *Structural) bool {
|
||||||
|
changed := s.Nullable
|
||||||
|
s.Nullable = false
|
||||||
|
return changed
|
||||||
|
},
|
||||||
|
}
|
||||||
|
v.Visit(s)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
@ -76,6 +76,9 @@ type Options struct {
|
|||||||
// Strip value validation.
|
// Strip value validation.
|
||||||
StripValueValidation bool
|
StripValueValidation bool
|
||||||
|
|
||||||
|
// Strip nullable.
|
||||||
|
StripNullable bool
|
||||||
|
|
||||||
// AllowNonStructural indicates swagger should be built for a schema that fits into the structural type but does not meet all structural invariants
|
// AllowNonStructural indicates swagger should be built for a schema that fits into the structural type but does not meet all structural invariants
|
||||||
AllowNonStructural bool
|
AllowNonStructural bool
|
||||||
}
|
}
|
||||||
@ -101,6 +104,9 @@ func BuildSwagger(crd *apiextensions.CustomResourceDefinition, version string, o
|
|||||||
if opts.StripValueValidation {
|
if opts.StripValueValidation {
|
||||||
schema = schema.StripValueValidations()
|
schema = schema.StripValueValidations()
|
||||||
}
|
}
|
||||||
|
if opts.StripNullable {
|
||||||
|
schema = schema.StripNullable()
|
||||||
|
}
|
||||||
|
|
||||||
schema = schema.Unfold()
|
schema = schema.Unfold()
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,8 @@ func TestApplyCRDStructuralSchema(t *testing.T) {
|
|||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
"protocol": {
|
"protocol": {
|
||||||
"type": "string"
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
Loading…
Reference in New Issue
Block a user