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?
-
Initialize a new Crossplane project.
-
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
-
Generate types: crossplane project build
-
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
What happened?
When generating types for an XRD with a schema containing a field missing the
typeproperty, 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?
Initialize a new Crossplane project.
Add an XRD that contains a field missing the
typefield:Generate types:
crossplane project buildLook at the resulting types, such as
schemas/python/models/com/example/foobar/v1alpha1.py. Notice they are just stubs—they don't even include thespecfield which is correctly defined in the schema:What environment did it happen in?