@@ -23,7 +23,7 @@ import (
2323 "strings"
2424 "sync"
2525
26- apiext "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
26+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727 "sigs.k8s.io/controller-tools/pkg/loader"
2828)
2929
@@ -49,7 +49,7 @@ func isOrNil(val reflect.Value, valInt any, zeroInt any) bool {
4949
5050// flattenAllOfInto copies properties from src to dst, then copies the properties
5151// of each item in src's allOf to dst's properties as well.
52- func flattenAllOfInto (dst * apiext .JSONSchemaProps , src apiext .JSONSchemaProps , errRec ErrorRecorder ) {
52+ func flattenAllOfInto (dst * apiextensionsv1 .JSONSchemaProps , src apiextensionsv1 .JSONSchemaProps , errRec ErrorRecorder ) {
5353 if len (src .AllOf ) > 0 {
5454 for _ , embedded := range src .AllOf {
5555 flattenAllOfInto (dst , embedded , errRec )
@@ -60,9 +60,9 @@ func flattenAllOfInto(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps, e
6060 srcVal := reflect .ValueOf (src )
6161 typ := dstVal .Type ()
6262
63- srcRemainder := apiext .JSONSchemaProps {}
63+ srcRemainder := apiextensionsv1 .JSONSchemaProps {}
6464 srcRemVal := reflect .Indirect (reflect .ValueOf (& srcRemainder ))
65- dstRemainder := apiext .JSONSchemaProps {}
65+ dstRemainder := apiextensionsv1 .JSONSchemaProps {}
6666 dstRemVal := reflect .Indirect (reflect .ValueOf (& dstRemainder ))
6767 hoisted := false
6868
@@ -104,8 +104,8 @@ func flattenAllOfInto(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps, e
104104 switch fieldName {
105105 case "Properties" :
106106 // merge if possible, use all of otherwise
107- srcMap := srcInt .(map [string ]apiext .JSONSchemaProps )
108- dstMap := dstInt .(map [string ]apiext .JSONSchemaProps )
107+ srcMap := srcInt .(map [string ]apiextensionsv1 .JSONSchemaProps )
108+ dstMap := dstInt .(map [string ]apiextensionsv1 .JSONSchemaProps )
109109
110110 for k , v := range srcMap {
111111 dstProp , exists := dstMap [k ]
@@ -132,14 +132,14 @@ func flattenAllOfInto(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps, e
132132 // - Definitions: common named validation sets that can be references (merge, bail if duplicate)
133133 case "AdditionalProperties" :
134134 // as of the time of writing, `allows: false` is not allowed, so we don't have to handle it
135- srcProps := srcInt .(* apiext .JSONSchemaPropsOrBool )
135+ srcProps := srcInt .(* apiextensionsv1 .JSONSchemaPropsOrBool )
136136 if srcProps .Schema == nil {
137137 // nothing to merge
138138 continue
139139 }
140- dstProps := dstInt .(* apiext .JSONSchemaPropsOrBool )
140+ dstProps := dstInt .(* apiextensionsv1 .JSONSchemaPropsOrBool )
141141 if dstProps .Schema == nil {
142- dstProps .Schema = & apiext .JSONSchemaProps {}
142+ dstProps .Schema = & apiextensionsv1 .JSONSchemaProps {}
143143 }
144144 flattenAllOfInto (dstProps .Schema , * srcProps .Schema , errRec )
145145 case "XPreserveUnknownFields" :
@@ -188,7 +188,7 @@ type allOfVisitor struct {
188188 errRec ErrorRecorder
189189}
190190
191- func (v * allOfVisitor ) Visit (schema * apiext .JSONSchemaProps ) SchemaVisitor {
191+ func (v * allOfVisitor ) Visit (schema * apiextensionsv1 .JSONSchemaProps ) SchemaVisitor {
192192 if schema == nil {
193193 return v
194194 }
@@ -210,7 +210,7 @@ func (v *allOfVisitor) Visit(schema *apiext.JSONSchemaProps) SchemaVisitor {
210210// FlattenEmbedded flattens embedded fields (represented via AllOf) which have
211211// already had their references resolved into simple properties in the containing
212212// schema.
213- func FlattenEmbedded (schema * apiext .JSONSchemaProps , errRec ErrorRecorder ) * apiext .JSONSchemaProps {
213+ func FlattenEmbedded (schema * apiextensionsv1 .JSONSchemaProps , errRec ErrorRecorder ) * apiextensionsv1 .JSONSchemaProps {
214214 outSchema := schema .DeepCopy ()
215215 EditSchema (outSchema , & allOfVisitor {errRec : errRec })
216216 return outSchema
@@ -226,27 +226,27 @@ type Flattener struct {
226226 LookupReference func (ref string , contextPkg * loader.Package ) (TypeIdent , error )
227227
228228 // flattenedTypes hold the flattened version of each seen type for later reuse.
229- flattenedTypes map [TypeIdent ]apiext .JSONSchemaProps
229+ flattenedTypes map [TypeIdent ]apiextensionsv1 .JSONSchemaProps
230230 initOnce sync.Once
231231}
232232
233233func (f * Flattener ) init () {
234234 f .initOnce .Do (func () {
235- f .flattenedTypes = make (map [TypeIdent ]apiext .JSONSchemaProps )
235+ f .flattenedTypes = make (map [TypeIdent ]apiextensionsv1 .JSONSchemaProps )
236236 if f .LookupReference == nil {
237237 f .LookupReference = identFromRef
238238 }
239239 })
240240}
241241
242242// cacheType saves the flattened version of the given type for later reuse
243- func (f * Flattener ) cacheType (typ TypeIdent , schema apiext .JSONSchemaProps ) {
243+ func (f * Flattener ) cacheType (typ TypeIdent , schema apiextensionsv1 .JSONSchemaProps ) {
244244 f .init ()
245245 f .flattenedTypes [typ ] = schema
246246}
247247
248248// loadUnflattenedSchema fetches a fresh, unflattened schema from the parser.
249- func (f * Flattener ) loadUnflattenedSchema (typ TypeIdent ) (* apiext .JSONSchemaProps , error ) {
249+ func (f * Flattener ) loadUnflattenedSchema (typ TypeIdent ) (* apiextensionsv1 .JSONSchemaProps , error ) {
250250 f .Parser .NeedSchemaFor (typ )
251251
252252 baseSchema , found := f .Parser .Schemata [typ ]
@@ -258,7 +258,7 @@ func (f *Flattener) loadUnflattenedSchema(typ TypeIdent) (*apiext.JSONSchemaProp
258258
259259// FlattenType flattens the given pre-loaded type, removing any references from it.
260260// It deep-copies the schema first, so it won't affect the parser's version of the schema.
261- func (f * Flattener ) FlattenType (typ TypeIdent ) * apiext .JSONSchemaProps {
261+ func (f * Flattener ) FlattenType (typ TypeIdent ) * apiextensionsv1 .JSONSchemaProps {
262262 f .init ()
263263 if cachedSchema , isCached := f .flattenedTypes [typ ]; isCached {
264264 return & cachedSchema
@@ -275,7 +275,7 @@ func (f *Flattener) FlattenType(typ TypeIdent) *apiext.JSONSchemaProps {
275275
276276// FlattenSchema flattens the given schema, removing any references.
277277// It deep-copies the schema first, so the input schema won't be affected.
278- func (f * Flattener ) FlattenSchema (baseSchema apiext .JSONSchemaProps , currentPackage * loader.Package ) * apiext .JSONSchemaProps {
278+ func (f * Flattener ) FlattenSchema (baseSchema apiextensionsv1 .JSONSchemaProps , currentPackage * loader.Package ) * apiextensionsv1 .JSONSchemaProps {
279279 resSchema := baseSchema .DeepCopy ()
280280 EditSchema (resSchema , & flattenVisitor {
281281 Flattener : f ,
@@ -332,7 +332,7 @@ func identFromRef(ref string, contextPkg *loader.Package) (TypeIdent, error) {
332332// preserveFields copies documentation fields from src into dst, preserving
333333// field-level documentation when flattening, and preserving field-level validation
334334// as allOf entries.
335- func preserveFields (dst * apiext .JSONSchemaProps , src apiext .JSONSchemaProps ) {
335+ func preserveFields (dst * apiextensionsv1 .JSONSchemaProps , src apiextensionsv1 .JSONSchemaProps ) {
336336 srcDesc := src .Description
337337 srcTitle := src .Title
338338 srcExDoc := src .ExternalDocs
@@ -341,8 +341,8 @@ func preserveFields(dst *apiext.JSONSchemaProps, src apiext.JSONSchemaProps) {
341341 src .Description , src .Title , src .ExternalDocs , src .Example = "" , "" , nil , nil
342342
343343 src .Ref = nil
344- * dst = apiext .JSONSchemaProps {
345- AllOf : []apiext .JSONSchemaProps {* dst , src },
344+ * dst = apiextensionsv1 .JSONSchemaProps {
345+ AllOf : []apiextensionsv1 .JSONSchemaProps {* dst , src },
346346
347347 // keep these, in case the source field doesn't specify anything useful
348348 Description : dst .Description ,
@@ -371,11 +371,11 @@ type flattenVisitor struct {
371371
372372 currentPackage * loader.Package
373373 currentType * TypeIdent
374- currentSchema * apiext .JSONSchemaProps
375- originalField apiext .JSONSchemaProps
374+ currentSchema * apiextensionsv1 .JSONSchemaProps
375+ originalField apiextensionsv1 .JSONSchemaProps
376376}
377377
378- func (f * flattenVisitor ) Visit (baseSchema * apiext .JSONSchemaProps ) SchemaVisitor {
378+ func (f * flattenVisitor ) Visit (baseSchema * apiextensionsv1 .JSONSchemaProps ) SchemaVisitor {
379379 if baseSchema == nil {
380380 // end-of-node marker, cache the results
381381 if f .currentType != nil {
@@ -421,7 +421,7 @@ func (f *flattenVisitor) Visit(baseSchema *apiext.JSONSchemaProps) SchemaVisitor
421421
422422 // avoid loops (which shouldn't exist, but just in case)
423423 // by marking a nil cached pointer before we start recursing
424- f .cacheType (refIdent , apiext .JSONSchemaProps {})
424+ f .cacheType (refIdent , apiextensionsv1 .JSONSchemaProps {})
425425
426426 return & flattenVisitor {
427427 Flattener : f .Flattener ,
0 commit comments