Repository navigation
fix: Render a nested config that a tagged variant holds as a partial in Pkl - #225
Merged
Merged
Conversation
…in Pkl
Since tagged variants became `SchemaType::Tagged`, the struct serde writes
around an internally tagged variant's value (`{ tag, Name: flatten }`) wasn't
marked partial. `PklSchemaRenderer` treats everything within a struct that
isn't partial as a full type, so the nested config's module made every
property required and dropped its aliases, even with
`mark_struct_fields_required: false`. The variant's class also declared the
config's properties itself, in full, so a module amending it had to set them
all.
- `TaggedType::to_schema` marks the struct it creates around a value as
partial when the value is, or holds, a partial config.
- A Pkl class that flattens a named struct extends that struct's module, which
is then declared `open`, like `class TemplateVariableBoolean extends
TemplateVariableBoolSetting { type: "boolean" }`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Regenerating moon's Pkl modules with 0.21.1 made template variables unusable without setting every field. Since tagged variants became
SchemaType::Tagged, the struct serde writes around an internally tagged variant's value ({ tag, Name: flatten }) isn't marked partial.PklSchemaRenderertreats everything within a struct that isn't partial as a full type. So the nested config's module:mark_struct_fields_required: false, andThe variant also became an inline class that declared the config's properties itself, in full. With pkl 0.26.2, this moon template fails to evaluate, though the 0.20.12 modules accepted it:
Fix
TaggedType::to_schemamarks the struct it creates around a value aspartialwhen the value is, or holds, a partial config. The tag stays a literal, so it's still required.A Pkl class that flattens a named struct now extends that struct's module, as a module does, and the module is declared
open. An internally tagged variant renders as:Two behavior changes go beyond the regression:
Verification
tagged_enumssnapshot and the partial-variant test.cargo test --workspacepasses, as docargo test -p schematic_typesand the default, no-feature, and single-feature builds ofschematic.TemplateVariable*Setting.pklare back todefault: Boolean? = defaultValuewith the hidden alias, andinternal: Boolean?.typeandprompt, or usesdefaultValue, passespkl evaland loads through moon'sConfigLoaderwith the defaults filled in.cargo clippy --workspace --all-targetsreports fivecollapsible_ifwarnings, all in files this PR doesn't touch.🤖 Generated with Claude Code