Skip to content

Commit

Permalink
Reduce the number of types loaded by the generator (#3803)
Browse files Browse the repository at this point in the history
* Pass configuration into loadAllSchemas()

* Reduce the number of loaded types
  • Loading branch information
theunrepentantgeek authored Feb 22, 2024
1 parent 37f8d37 commit 08f7cf0
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions v2/tools/generator/internal/codegen/pipeline/load_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ func loadSwaggerData(
) (jsonast.SwaggerTypes, error) {
schemas, err := loadAllSchemas(
ctx,
config.SchemaRoot,
config.LocalPathPrefix(),
idFactory,
config.Status.Overrides,
config,
log)
if err != nil {
return jsonast.SwaggerTypes{}, err
Expand Down Expand Up @@ -684,12 +682,14 @@ func shouldSkipDir(filePath string) bool {
// shouldSkipDir), and returns those files in a map of path→swagger spec.
func loadAllSchemas(
ctx context.Context,
rootPath string,
localPathPrefix string,
idFactory astmodel.IdentifierFactory,
overrides []config.SchemaOverride,
config *config.Configuration,
log logr.Logger,
) (map[string]jsonast.PackageAndSwagger, error) {
rootPath := config.SchemaRoot
localPathPrefix := config.LocalPathPrefix()
overrides := config.Status.Overrides

var mutex sync.Mutex
schemas := make(map[string]jsonast.PackageAndSwagger)

Expand Down Expand Up @@ -726,6 +726,15 @@ func loadAllSchemas(
astmodel.GeneratorVersion,
version)

// We need the file if the version is short (e.g. "v1") because those are often shared between
// resource providers.
// Alternatively, we need the file if we have configuration for the group
fileNeeded := len(version) < 10 ||
config.ObjectModelConfiguration.IsGroupConfigured(pkg)
if !fileNeeded {
return nil
}

// all files are loaded in parallel to speed this up
logInfoSparse(
log,
Expand Down

0 comments on commit 08f7cf0

Please sign in to comment.