Skip to content

[project/schemas]: go types contains conflicting code if two xrd's in same api-group has integer enum field #444

Open

Description

@nkzk

What happened?

The generated go schemas from `crossplane project build`` seems to be conflicting when two XRDs in the same API group and version contain integer enums.

Example:

XRD's for custom Subnet and VirtualNetwork resources define a .spec.size integer enum with the values 8, 16, 32, 64, 128, 256, 512.

The generated models will declare the same package-level constant name for both enum types:

// Subnet model
const (
    Empty SubnetSpecSize = 8
)

// VirtualNetwork model
const (
    Empty VirtualNetworkSpecSize = 8
)

These declarations collide and the embedded functions that imports a type from this api group will fail:

crossplane: error: failed to build function "firewall": failed to build runtime images: failed to build function: build: go build: exit status 1: # dev.crossplane.io/models/io/example/azure/v1alpha1
../../schemas/go/io/example/azure/v1alpha1/virtualnetwork.go:109:2: Empty redeclared in this block
    ../../schemas/go/io/example/azure/v1alpha1/subnet.go:91:2: other declaration of Empty
../../schemas/go/io/example/azure/v1alpha1/virtualnetwork.go:115:7: invalid case Empty in switch on e (mismatched types SubnetSpecSize and VirtualNetworkSpecSize)

Expected behavior: Go model generation should generate unique constant names so resources in the same package compile successfully.

How can we reproduce it?

Use a Crossplane project with Go schema generation enabled (spec.schemas.languages: ["go"]) and an embedded Go function that imports the generated API package.

Create apis/subnets/definition.yaml:

---
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
  name: subnets.example.io
spec:
  scope: Namespaced
  group: example.io
  names:
    kind: Subnet
    plural: subnets
  versions:
    - name: v1alpha1
      served: true
      referenceable: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                size:
                  type: integer
                  enum: [8, 16, 32, 64, 128, 256, 512]

Create apis/virtualnetworks/definition.yaml:

---
apiVersion: apiextensions.crossplane.io/v2
kind: CompositeResourceDefinition
metadata:
  name: virtualnetworks.example.io
spec:
  scope: Namespaced
  group: example.io
  names:
    kind: VirtualNetwork
    plural: virtualnetworks
  versions:
    - name: v1alpha1
      served: true
      referenceable: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                size:
                  type: integer
                  enum: [8, 16, 32, 64, 128, 256, 512]

Run crossplane project build.

Observe the duplicate Empty constants and resulting Go compilation errors.

What environment did it happen in?

Crossplane CLI version: v2.5.0
Platform: linux/amd64
Crossplane version: v2.4.2 (the failure occurs locally during the CLI build)

Activity

  1. added
    bugSomething isn't working
    on Oct 22, 2026
  2. changed the title [-]Crossplane Project build generates incorrect Go code for integer enums[/-] [+]Crossplane Project build generates conflicting code if two xrd's in same api-group has same integer enum field[/+] on Oct 22, 2026
  3. changed the title [-]Crossplane Project build generates conflicting code if two xrd's in same api-group has same integer enum field[/-] [+]Crossplane Project build generates conflicting code if two xrd's in same api-group has integer enum field[/+] on Oct 22, 2026
  4. changed the title [-]Crossplane Project build generates conflicting code if two xrd's in same api-group has integer enum field[/-] [+][project/schemas]: go types contains conflicting code if two xrd's in same api-group has integer enum field[/+] on Oct 22, 2026
  5. nkzk commented on Oct 22, 2026

    @nkzk
    ContributorAuthor

    The generated code also seems to be missing enum values but created a separate issue for that: #445

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions