Skip to content

Commit 08f7cf0

Browse files
Reduce the number of types loaded by the generator (#3803)
* Pass configuration into loadAllSchemas() * Reduce the number of loaded types
1 parent 37f8d37 commit 08f7cf0

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

v2/tools/generator/internal/codegen/pipeline/load_types.go

+15-6
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ func loadSwaggerData(
313313
) (jsonast.SwaggerTypes, error) {
314314
schemas, err := loadAllSchemas(
315315
ctx,
316-
config.SchemaRoot,
317-
config.LocalPathPrefix(),
318316
idFactory,
319-
config.Status.Overrides,
317+
config,
320318
log)
321319
if err != nil {
322320
return jsonast.SwaggerTypes{}, err
@@ -684,12 +682,14 @@ func shouldSkipDir(filePath string) bool {
684682
// shouldSkipDir), and returns those files in a map of path→swagger spec.
685683
func loadAllSchemas(
686684
ctx context.Context,
687-
rootPath string,
688-
localPathPrefix string,
689685
idFactory astmodel.IdentifierFactory,
690-
overrides []config.SchemaOverride,
686+
config *config.Configuration,
691687
log logr.Logger,
692688
) (map[string]jsonast.PackageAndSwagger, error) {
689+
rootPath := config.SchemaRoot
690+
localPathPrefix := config.LocalPathPrefix()
691+
overrides := config.Status.Overrides
692+
693693
var mutex sync.Mutex
694694
schemas := make(map[string]jsonast.PackageAndSwagger)
695695

@@ -726,6 +726,15 @@ func loadAllSchemas(
726726
astmodel.GeneratorVersion,
727727
version)
728728

729+
// We need the file if the version is short (e.g. "v1") because those are often shared between
730+
// resource providers.
731+
// Alternatively, we need the file if we have configuration for the group
732+
fileNeeded := len(version) < 10 ||
733+
config.ObjectModelConfiguration.IsGroupConfigured(pkg)
734+
if !fileNeeded {
735+
return nil
736+
}
737+
729738
// all files are loaded in parallel to speed this up
730739
logInfoSparse(
731740
log,

0 commit comments

Comments
 (0)