Skip to content

Missing type field results in silent schema generation failure #278

Description

@eric-carlsson

What happened?

When generating types for an XRD with a schema containing a field missing the type property, it generates stub types containing no fields, but doesn't print any warning or error.

Instead, it should print a warning or error, ideally pointing to the invalid line/type.

How can we reproduce it?

  1. Initialize a new Crossplane project.

  2. Add an XRD that contains a field missing the type field:

    apiVersion: apiextensions.crossplane.io/v2
    kind: CompositeResourceDefinition
    metadata:
      name: foobar.example.com
    spec:
      group: example.com
      names:
        kind: Foobar
        plural: foobar
      scope: Namespaced
      versions:
        - name: v1alpha1
          referenceable: true
          served: true
          schema:
            openAPIV3Schema:
              type: object
              properties:
                spec:
                  properties:
                    foobar:
                      description: Notice this field's missing the "type" field
    
  3. Generate types: crossplane project build

  4. Look at the resulting types, such as schemas/python/models/com/example/foobar/v1alpha1.py. Notice they are just stubs—they don't even include the spec field which is correctly defined in the schema:

    # generated by datamodel-codegen:
    #   filename:  workdir/example_com_v1alpha1_foobar.yaml
    
    from __future__ import annotations
    
    from pydantic import BaseModel
    
    from ....io.k8s.apimachinery.pkg.apis.meta import v1
    
    
    class Foobar(BaseModel):
        pass
    
    
    class FoobarList(BaseModel):
        apiVersion: str | None = None
        """
        APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
        """
        items: list[Foobar]
        """
        List of foobar. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md
        """
        kind: str | None = None
        """
        Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
        """
        metadata: v1.ListMeta | None = None
        """
        Standard list metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
        """

What environment did it happen in?

  • Crossplane CLI version: v2.4.1
  • Platform (e.g., linux/amd64): darwin/arm64
  • Crossplane version (if applicable): N/A

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