From e27684f2c6ac0a0ddb6fc8c70645fbc708c7bf42 Mon Sep 17 00:00:00 2001 From: Matt Pryor Date: Fri, 29 Nov 2024 15:48:26 +0000 Subject: [PATCH] Use proper schema resolution --- kube_custom_resource/custom_resource.py | 11 +++++++++-- kube_custom_resource/schema.py | 3 ++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/kube_custom_resource/custom_resource.py b/kube_custom_resource/custom_resource.py index b5f270c..7d73605 100644 --- a/kube_custom_resource/custom_resource.py +++ b/kube_custom_resource/custom_resource.py @@ -253,8 +253,15 @@ class CustomResource( ) @classmethod - def model_json_schema(cls, *args, **kwargs): - json_schema = super().model_json_schema(*args, **kwargs) + def __get_pydantic_json_schema__( + cls, + core_schema: CoreSchema, + handler: GetJsonSchemaHandler + ) -> JsonSchemaValue: + json_schema = handler(core_schema) + json_schema = handler.resolve_ref_schema(json_schema) + # Remove the API version, kind and metadata from the schema as they are + # not required for a valid CRD for key in ["apiVersion", "kind", "metadata"]: json_schema["properties"].pop(key) json_schema["required"].remove(key) diff --git a/kube_custom_resource/schema.py b/kube_custom_resource/schema.py index 9b31b24..46a592b 100644 --- a/kube_custom_resource/schema.py +++ b/kube_custom_resource/schema.py @@ -371,7 +371,8 @@ def __get_pydantic_json_schema__( core_schema: CoreSchema, handler: GetJsonSchemaHandler ) -> JsonSchemaValue: - json_schema = super().__get_pydantic_json_schema__(core_schema, handler) + json_schema = handler(core_schema) + json_schema = handler.resolve_ref_schema(json_schema) ##### # Post-process the generated schema to make it compatible with a Kubernetes CRD #####