Skip to content

Refactor v2 config: separate schema from generator configuration#157

Merged
ericof merged 2 commits intomainfrom
156-refactor-v2-config-format
Apr 1, 2026
Merged

Refactor v2 config: separate schema from generator configuration#157
ericof merged 2 commits intomainfrom
156-refactor-v2-config-format

Conversation

@ericof
Copy link
Copy Markdown
Member

@ericof ericof commented Apr 1, 2026

Summary

Refactors the cookieplone.json v2 format to cleanly separate the form schema (user-facing questions) from generator configuration (extensions, no_render, versions, subtemplates).

Key changes

  • SubTemplate TypedDict (cookieplone/config/schemas.py): typed structure for subtemplate entries with id, title, and enabled keys, plus JSON Schema validation for the full v2 config format.
  • config.versions as top-level context namespace: version pinning values are now accessible via {{ versions.<key> }} (alongside {{ cookiecutter.<key> }}), injected into state.data at creation time.
  • Jinja2-rendered enabled field: subtemplate enabled values can be static ("1"/"0") or Jinja2 expressions (e.g. {{ cookiecutter.has_frontend }}), rendered against the current context during generation.
  • create_jinja_env facade: wraps StrictEnvironment creation and injects context into env.globals so Jinja2 expressions can resolve template variables.
  • process_subtemplates utility: converts v2 subtemplate dicts into the [id, title, enabled] list format expected by post-generation hooks.
  • Documentation: updated schema-v2 reference and subtemplates concept pages.

Files changed (highlights)

Area Files
New modules cookieplone/config/schemas.py, cookieplone/utils/subtemplates.py
Config parsing cookieplone/config/state.py, cookieplone/config/v2.py, cookieplone/config/v1.py
Generator cookieplone/generator/main.py
Utilities cookieplone/utils/cookiecutter.py, cookieplone/utils/config.py
Docs docs/src/reference/schema-v2.md, docs/src/concepts/subtemplates.md
Tests tests/config/test_schemas.py, tests/utils/test_subtemplates.py, tests/utils/test_cookiecutter.py, + updates to existing test files

Test plan

  • All existing tests pass
  • New tests for SubTemplate TypedDict and JSON Schema validation
  • New tests for create_jinja_env (context injection, globals resolution)
  • New tests for process_subtemplates (static values, Jinja2 expressions, empty lists)
  • New tests for _generate_state versions injection into state.data
  • Verified ruff and ruff-format pass via pre-commit hooks

Closes #156

Split the flat cookieplone.json v2 format into distinct `schema` and
`config` sections.  Generator settings (extensions, no_render, versions,
subtemplates) now live under `config` instead of being mixed with form
fields in `properties`.

Key changes:

- Add `SubTemplate` TypedDict and JSON Schema validation in
  `cookieplone/config/schemas.py`.
- `ParsedConfig` and `CookieploneState` use `list[SubTemplate]` for
  typed subtemplate entries.
- `config.versions` is injected as a top-level context namespace
  (`{{ versions.<key> }}`), alongside `cookiecutter`.
- New `process_subtemplates` utility renders Jinja2 `enabled`
  expressions against the current context.
- `create_jinja_env` injects context into `env.globals` so Jinja2
  expressions can resolve `cookiecutter.*` and `versions.*` variables.
- Documentation updated for schema-v2 reference and subtemplates concept.

Closes #156
@ericof ericof requested a review from a team as a code owner April 1, 2026 18:30
Add sub-template vocabulary to Vale accept list and remove colon
from heading to satisfy Microsoft.HeadingColons rule.
@ericof ericof merged commit f913005 into main Apr 1, 2026
10 checks passed
@ericof ericof deleted the 156-refactor-v2-config-format branch April 1, 2026 19:55
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.

Refactor cookieplone.json v2: separate schema from config

1 participant