Skip to content

Commit

Permalink
Use proper schema resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
mkjpryor committed Nov 29, 2024
1 parent b4353e4 commit e27684f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions kube_custom_resource/custom_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion kube_custom_resource/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#####
Expand Down

0 comments on commit e27684f

Please sign in to comment.