| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package util |
| 18 |
|
| 19 |
import ( |
| 20 |
"reflect" |
| 21 |
|
| 22 |
"k8s.io/kube-openapi/pkg/schemamutation" |
| 23 |
"k8s.io/kube-openapi/pkg/validation/spec" |
| 24 |
) |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
func WrapRefs(schema *spec.Schema) *spec.Schema { |
| 30 |
walker := schemamutation.Walker{ |
| 31 |
SchemaCallback: func(schema *spec.Schema) *spec.Schema { |
| 32 |
orig := schema |
| 33 |
clone := func() { |
| 34 |
if orig == schema { |
| 35 |
schema = new(spec.Schema) |
| 36 |
*schema = *orig |
| 37 |
} |
| 38 |
} |
| 39 |
if schema.Ref.String() != "" && !reflect.DeepEqual(*schema, spec.Schema{SchemaProps: spec.SchemaProps{Ref: schema.Ref}}) { |
| 40 |
clone() |
| 41 |
refSchema := new(spec.Schema) |
| 42 |
refSchema.Ref = schema.Ref |
| 43 |
schema.Ref = spec.Ref{} |
| 44 |
schema.AllOf = []spec.Schema{*refSchema} |
| 45 |
} |
| 46 |
return schema |
| 47 |
}, |
| 48 |
RefCallback: schemamutation.RefCallbackNoop, |
| 49 |
} |
| 50 |
return walker.WalkSchema(schema) |
| 51 |
} |