...

Source file src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/unfold.go

Documentation: k8s.io/apiextensions-apiserver/pkg/apiserver/schema

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package schema
    18  
    19  // Unfold expands vendor extensions of a structural schema.
    20  // It mutates the receiver.
    21  func (s *Structural) Unfold() *Structural {
    22  	if s == nil {
    23  		return nil
    24  	}
    25  
    26  	mapper := Visitor{
    27  		Structural: func(s *Structural) bool {
    28  			if !s.XIntOrString {
    29  				return false
    30  			}
    31  
    32  			skipAnyOf := isIntOrStringAnyOfPattern(s)
    33  			skipFirstAllOfAnyOf := isIntOrStringAllOfPattern(s)
    34  			if skipAnyOf || skipFirstAllOfAnyOf {
    35  				return false
    36  			}
    37  
    38  			if s.ValueValidation == nil {
    39  				s.ValueValidation = &ValueValidation{}
    40  			}
    41  			if s.ValueValidation.AnyOf == nil {
    42  				s.ValueValidation.AnyOf = []NestedValueValidation{
    43  					{ForbiddenGenerics: Generic{Type: "integer"}},
    44  					{ForbiddenGenerics: Generic{Type: "string"}},
    45  				}
    46  			} else {
    47  				s.ValueValidation.AllOf = append([]NestedValueValidation{
    48  					{
    49  						ValueValidation: ValueValidation{
    50  							AnyOf: []NestedValueValidation{
    51  								{ForbiddenGenerics: Generic{Type: "integer"}},
    52  								{ForbiddenGenerics: Generic{Type: "string"}},
    53  							},
    54  						},
    55  					},
    56  				}, s.ValueValidation.AllOf...)
    57  			}
    58  
    59  			return true
    60  		},
    61  		NestedValueValidation: nil, // x-kubernetes-int-or-string cannot be set in nested value validation
    62  	}
    63  	mapper.Visit(s)
    64  
    65  	return s
    66  }
    67  

View as plain text