Skip to content

Conversation

@gauteoh
Copy link

@gauteoh gauteoh commented Dec 3, 2025

Summary

First of all, thank you for a very nice helm tool!

I've added some changes, mainly in propagating definitions from external schemas and root schema annotations to parent schemas. This ensures that @schema.root annotations and $defs/definitions from external schema files work correctly in generated JSON schemas. I also see that Helm v3.18.0 (https://github.com/helm/helm/releases/tag/v3.18.0) added support for JSON Schema 2020, so perhaps I'll look into that some time.

I also merged #155 into this fork.

Changes

1. Definitions Propagation from Dependencies (cmd/helm-schema/main.go)

Merge $defs and definitions from dependency chart schemas into parent chart schemas:

  • Propagates definitions from dependency schemas to parent at lines 238-270
  • Handles both $defs (Draft-07+) and definitions (legacy) keywords
  • Warns on definition name conflicts, keeping parent's version
  • Debug logging for tracking definition merging

2. Root Schema Annotations Propagation (pkg/schema/schema.go)

Complete propagation of all root schema fields from contentSchema to document-level schema:

  • Title
  • Description
  • AdditionalProperties
  • CustomAnnotations
  • Ref
  • Examples
  • Deprecated
  • ReadOnly
  • WriteOnly

Previously, these fields were being extracted from @schema.root comments but not copied to the final schema object.

3. Comprehensive Test Coverage (pkg/schema/root_schema_test.go)

Added 13 new tests across 3 test functions:

  • TestDefinitionsPropagationFromExternalSchema: Tests collection and propagation of definitions from external schema files (both $defs and definitions keywords)
  • TestCheckUsesDefinitions: Tests logic that determines whether to use definitions vs $defs based on reference style.
  • TestRootSchemaAnnotationsPropagation: Tests propagation of all root schema fields (Ref, Examples, Deprecated, ReadOnly, WriteOnly)

Root Schema Annotations

Users can now use all @schema.root annotation fields:

# @schema.root
# title: My Chart Values
# description: Configuration for my Helm chart
# deprecated: true
# readOnly: false
# x-custom-annotation: custom-value
# @schema.root
foo: bar

External Schema References with Definitions

Definitions from external schema files are properly collected and merged:

# @schema
# $ref: ./common-schemas.json#/$defs/baseService
# @schema
service:
  port: 8080

All definitions from common-schemas.json will appear in the generated schema's $defs or definitions section, making the schema self-contained and valid.

Dependency Schema Merging

When processing chart dependencies, definitions from dependency schemas are now propagated to parent charts, enabling proper schema composition across chart hierarchies. The name of the definition will be overwritten by the last who defined it. This can be problematic if you have equally named definitions across several subcharts.

@gauteoh
Copy link
Author

gauteoh commented Dec 3, 2025

Forgot to add, this PR also adds support for overriding schemas in subcharts. If a subchart property has custom schema annotations (detected via HasData), the automatic schema merge from the dependency is skipped, allowing users to define their own schema for that subchart instead of using the included one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant