Skip to content

fix: Render a nested config that a tagged variant holds as a partial in Pkl - #225

Merged
milesj merged 1 commit into
masterfrom
0.21-pkl-partials
Nov 18, 2026
Merged

milesj merged 1 commit into
masterfrom
0.21-pkl-partials

Conversation

@milesj

@milesj milesj commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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. PklSchemaRenderer treats everything within a struct that isn't partial as a full type. So the nested config's module:

  • made every property required, even with mark_struct_fields_required: false, and
  • dropped its aliases, which are only rendered on nullable properties.

The 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:

variables {
  ["flag"] = new TemplateVariableBoolean { type = "boolean"; prompt = "Enable?" }
}
// Tried to read property `default` but its value is undefined.

Fix

  • TaggedType::to_schema marks the struct it creates around a value as partial when 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:

    class TemplateVariableBoolean extends TemplateVariableBoolSetting {
      type: "boolean"
    }

Two behavior changes go beyond the regression:

  • A nested config held by an externally or adjacently tagged variant also renders as a partial now. It was full before, in 0.20.12 too.
  • Any class that flattens a named struct extends its module, not only a tag's.

Verification

  • Added a snapshot test with a moon-shaped fixture, and types tests for the partial mark. Updated the tagged_enums snapshot and the partial-variant test.
  • cargo test --workspace passes, as do cargo test -p schematic_types and the default, no-feature, and single-feature builds of schematic.
  • Regenerated moon's schemas against this branch. Only the Pkl output changed: TypeScript and JSON Schema are the same once formatted.
  • In the regenerated modules, TemplateVariable*Setting.pkl are back to default: Boolean? = defaultValue with the hidden alias, and internal: Boolean?.
  • A template that sets only type and prompt, or uses defaultValue, passes pkl eval and loads through moon's ConfigLoader with the defaults filled in.

cargo clippy --workspace --all-targets reports five collapsible_if warnings, all in files this PR doesn't touch.

🤖 Generated with Claude Code

…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>
@milesj
milesj merged commit 25fc23e into master Nov 18, 2026
6 checks passed
@milesj
milesj deleted the 0.21-pkl-partials branch November 18, 2026 01:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant