fix(defaults): add apiVersion and kind
Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
This commit is contained in:
parent
9c44291da2
commit
70e86c0d30
|
@ -38,7 +38,15 @@ def update(r: fnv1.Resource, source: dict | structpb.Struct | pydantic.BaseModel
|
|||
"""
|
||||
match source:
|
||||
case pydantic.BaseModel():
|
||||
r.resource.update(source.model_dump(exclude_defaults=True, warnings=False))
|
||||
data = source.model_dump(exclude_defaults=True, warnings=False)
|
||||
# In Pydantic, exclude_defaults=True in model_dump excludes fields
|
||||
# that have their value equal to the default. If a field like
|
||||
# apiVersion is set to its default value 's3.aws.upbound.io/v1beta2'
|
||||
# (and not explicitly provided during initialization), it will be
|
||||
# excluded from the serialized output.
|
||||
data['apiVersion'] = source.apiVersion
|
||||
data['kind'] = source.kind
|
||||
r.resource.update(data)
|
||||
case structpb.Struct():
|
||||
# TODO(negz): Use struct_to_dict and update to match other semantics?
|
||||
r.resource.MergeFrom(source)
|
||||
|
|
|
@ -90,7 +90,11 @@ class TestResource(unittest.TestCase):
|
|||
),
|
||||
want=fnv1.Resource(
|
||||
resource=resource.dict_to_struct(
|
||||
{"spec": {"forProvider": {"region": "us-west-2"}}}
|
||||
{
|
||||
"apiVersion": "s3.aws.upbound.io/v1beta1",
|
||||
"kind": "Bucket",
|
||||
"spec": {"forProvider": {"region": "us-west-2"}},
|
||||
}
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -759,11 +759,11 @@ class Status(BaseModel):
|
|||
|
||||
|
||||
class Bucket(BaseModel):
|
||||
apiVersion: Optional[str] = None
|
||||
apiVersion: Optional[str] = 's3.aws.upbound.io/v1beta2'
|
||||
"""
|
||||
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
|
||||
"""
|
||||
kind: Optional[str] = None
|
||||
kind: Optional[str] = 'Bucket'
|
||||
"""
|
||||
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
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue