Skip to content

feat: zarf dev schema-generate from existing values#4961

Open
Racer159 wants to merge 4 commits into
zarf-dev:mainfrom
Racer159:feat/schema-generate-command
Open

feat: zarf dev schema-generate from existing values#4961
Racer159 wants to merge 4 commits into
zarf-dev:mainfrom
Racer159:feat/schema-generate-command

Conversation

@Racer159
Copy link
Copy Markdown
Contributor

@Racer159 Racer159 commented Jun 5, 2026

Description

This adds a zarf dev generate-schema command to load the Zarf values defaults and then generate an inferred schema from those values. It does this by:

  1. Loading and merging the Zarf values.files to create an initial default list
  2. Looping through the components[x].charts values.sourcePath and values.targetPath` to fill in any missing values
    • These can either be from Zarf's valuesFiles or the Helm Chart's values.yaml
  3. Deterministically map these values to inferred types in a JSON Schema and save the schema

This also will load an existing schema (if one exists) and reconcile that schema with the inferred types in case the Zarf package creator already has a schema and has added additional keys (such as description, required, etc).

Related Issue

Fixes #4918

Checklist before merging

Signed-off-by: Wayne Starr <me@racer159.com>
@Racer159 Racer159 requested review from a team as code owners June 5, 2026 19:22
@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 5, 2026

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit ba8804b
🔍 Latest deploy log https://app.netlify.com/projects/zarf-docs/deploys/6a2330ca81c5c70007e94c03

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 45.53991% with 116 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cmd/dev.go 11.53% 91 Missing and 1 partial ⚠️
src/pkg/value/generate.go 74.44% 17 Missing and 6 partials ⚠️
src/pkg/value/schema.go 91.66% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/pkg/packager/layout/assemble.go 56.20% <100.00%> (+0.13%) ⬆️
src/pkg/packager/load/load.go 70.68% <100.00%> (+0.16%) ⬆️
src/pkg/value/schema.go 96.33% <91.66%> (-0.58%) ⬇️
src/pkg/value/generate.go 74.44% <74.44%> (ø)
src/cmd/dev.go 39.26% <11.53%> (-3.93%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Wayne Starr <me@racer159.com>
@Racer159 Racer159 force-pushed the feat/schema-generate-command branch from 1b1c667 to 6f96560 Compare June 5, 2026 19:45
Racer159 added 2 commits June 5, 2026 13:54
Signed-off-by: Wayne Starr <me@racer159.com>
Signed-off-by: Wayne Starr <me@racer159.com>
Copy link
Copy Markdown
Member

@brandtkeller brandtkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

initial thoughts around the shape of existing schemas - review WIP

Comment thread src/cmd/dev.go
// Step 3: Generate JSON schema from the final map and save it
schema := value.GenerateJSONSchema(zarfValues)

outputFileName := "values.schema.json"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also consider the specific defined.Pkg.Values.Schema path?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we likely should - I'll update to do that (and fallback if there isn't one)

Comment thread src/cmd/dev.go
CachePath: cachePath,
RemoteOptions: defaultRemoteOptions(),
}
defined, err := load.PackageDefinition(ctx, basePath, loadOpts)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined is a DefinedPackage

type DefinedPackage struct {
	Pkg             v1alpha1.ZarfPackage
	ImportedSchemas []string
}

These ImportedSchemas likely need to be merged with the specified schema (or created if not specified) prior to the final resolve workflow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't do it but would we want to merge the helm chart schemas in too? I think we would still need the final reconcile at the end based on what we found as "truth" - it is available in helmChart.schema and for those sections will become an enforcement mechanism (so likely best to reencode that in the Zarf schema to fail early?)

@github-project-automation github-project-automation Bot moved this to In progress in Zarf Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

Generate Schema JSON from Zarf Values files

2 participants