Skip to content

refactor: collapse duplicate XPCommonAPIs constants and simplify crd_types template alias scheme #692

Description

@jschoombee

Background

PR #664 migrated the common API imports to github.com/crossplane/crossplane/apis/v2/core/v2. As part of that migration, two constants in pkg/types/reference.go were intentionally kept separate for source-level backward compatibility — but they now hold identical values:

```go
// Both resolve to the same package path since crossplane-runtime v2.3.0
PackagePathXPCommonAPIs = "github.com/crossplane/crossplane/apis/v2/core/v2"
PackagePathXPV2CommonAPIs = "github.com/crossplane/crossplane/apis/v2/core/v2"
```

crd_types.go.tmpl also uses two separate alias template variables (XPCommonAPIsPackageAlias / XPV2CommonAPIsPackageAlias) that today resolve to the same import, because typewriter's UsePackage deduplicates by path.

Problem

The dual-constant, dual-alias scheme creates an invisible invariant: both constants must remain identical or one CRD scope's generated imports will silently diverge without a compile error (until downstream providers regenerate). The naming also implies a distinction between "v1 common APIs" and "v2 common APIs" that no longer exists.

Proposed fix

  1. Introduce a single replacement constant (e.g. PackagePathXPCoreAPIs) pointing to github.com/crossplane/crossplane/apis/v2/core/v2.
  2. Deprecate PackagePathXPCommonAPIs and PackagePathXPV2CommonAPIs with a // Deprecated: comment redirecting to the new name.
  3. Update pkg/pipeline/crd.go to pass the single constant for both template keys.
  4. Simplify crd_types.go.tmpl to use one alias variable throughout.

Severity

Not urgent — no correctness issue today. Generated code is correct because UsePackage deduplicates by path. The risk is a future maintainer who diverges only one constant and silently breaks one CRD scope's codegen.

Deferred from #664 to keep that PR focused in size.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions