@@ -58,6 +58,10 @@ type Parser struct {
58
58
GroupVersions map [* loader.Package ]schema.GroupVersion
59
59
// CustomResourceDefinitions contains the known CustomResourceDefinitions for types in this parser.
60
60
CustomResourceDefinitions map [schema.GroupKind ]apiext.CustomResourceDefinition
61
+ // FlattenedSchemata contains fully flattened schemata for use in building
62
+ // CustomResourceDefinition validation. Each schema has been flattened by the flattener,
63
+ // and then embedded fields have been flattened with FlattenEmbedded.
64
+ FlattenedSchemata map [TypeIdent ]apiext.JSONSchemaProps
61
65
62
66
// PackageOverrides indicates that the loading of any package with
63
67
// the given path should be handled by the given overrider.
@@ -95,6 +99,9 @@ func (p *Parser) init() {
95
99
if p .CustomResourceDefinitions == nil {
96
100
p .CustomResourceDefinitions = make (map [schema.GroupKind ]apiext.CustomResourceDefinition )
97
101
}
102
+ if p .FlattenedSchemata == nil {
103
+ p .FlattenedSchemata = make (map [TypeIdent ]apiext.JSONSchemaProps )
104
+ }
98
105
}
99
106
100
107
// indexTypes loads all types in the package into Types.
@@ -162,8 +169,20 @@ func (p *Parser) NeedSchemaFor(typ TypeIdent) {
162
169
schema := infoToSchema (ctxForInfo )
163
170
164
171
p .Schemata [typ ] = * schema
172
+ }
173
+
174
+ func (p * Parser ) NeedFlattenedSchemaFor (typ TypeIdent ) {
175
+ p .init ()
176
+
177
+ if _ , knownSchema := p .FlattenedSchemata [typ ]; knownSchema {
178
+ return
179
+ }
180
+
181
+ p .NeedSchemaFor (typ )
182
+ partialFlattened := p .flattener .FlattenType (typ )
183
+ fullyFlattened := FlattenEmbedded (partialFlattened , typ .Package )
165
184
166
- return
185
+ p . FlattenedSchemata [ typ ] = * fullyFlattened
167
186
}
168
187
169
188
// NeedCRDFor lives off in spec.go
0 commit comments