Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce the number of types loaded by the generator #3803

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading