Strip nullable for Server-side apply

This commit is contained in:
Antoine Pelisse 2019-11-12 16:33:20 -08:00
parent eedfb6bc7a
commit 5038f80b45
4 changed files with 23 additions and 2 deletions

View File

@ -1245,7 +1245,7 @@ func buildOpenAPIModelsForApply(staticOpenAPISpec *spec.Swagger, crd *apiextensi
specs := []*spec.Swagger{}
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 {
return nil, err
}

View File

@ -49,3 +49,17 @@ func (s *Structural) StripValueValidations() *Structural {
v.Visit(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
}

View File

@ -76,6 +76,9 @@ type Options struct {
// Strip value validation.
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 bool
}
@ -101,6 +104,9 @@ func BuildSwagger(crd *apiextensions.CustomResourceDefinition, version string, o
if opts.StripValueValidation {
schema = schema.StripValueValidations()
}
if opts.StripNullable {
schema = schema.StripNullable()
}
schema = schema.Unfold()
}

View File

@ -190,7 +190,8 @@ func TestApplyCRDStructuralSchema(t *testing.T) {
"type": "string"
},
"protocol": {
"type": "string"
"type": "string",
"nullable": true
}
},
"required": [