Skip to content

docs: generate yaml reference from pydantic#1450

Open
frodehk wants to merge 5 commits intomainfrom
docs/generate-yaml-reference-from-pydantic
Open

docs: generate yaml reference from pydantic#1450
frodehk wants to merge 5 commits intomainfrom
docs/generate-yaml-reference-from-pydantic

Conversation

@frodehk
Copy link
Copy Markdown
Contributor

@frodehk frodehk commented Mar 20, 2026

Auto-generate a single-page YAML reference doc from the Pydantic models, so documentation stays in sync with the code.

Adds a new package scripts/yaml_reference_docs/ with this pipeline:

Pydantic models → KeywordNode tree → PageDoc → Markdown (index.md)
Module Responsibility
keyword_tree.py Traverse the Pydantic model hierarchy and build a tree of YAML keywords
introspect.py Extract type labels, default values, and child models from Pydantic fields
doc_model.py Dataclasses for the intermediate document model (PageDoc, SectionDoc, ItemDoc)
page_builder.py Convert the keyword tree into a PageDoc ready for rendering
render_markdown.py Render a PageDoc to Markdown for Docusaurus
example_builder.py Generate YAML snippet examples
mdx.py Escape text that would break MDX parsing (e.g. <YYYY-MM-DD>)
generate.py CLI entry point — runs the full pipeline and writes index.md

The generator relies on Field(title="KEYWORD") to discover YAML keywords. Several existing model fields were missing title, so this PR adds Field(title=...) where needed. This has no runtime effect — it only adds metadata that Pydantic already supports.

The generated page appears under About → YAML Overview in the sidebar.

How to review

git checkout docs/generate-yaml-reference-from-pydantic

# Re-generate (optional — index.md is already committed)
python -m scripts.yaml_reference_docs

# Preview in Docusaurus
cd docs
npm install
npm run start

Then navigate to YAML Overview in the sidebar.

Refs:
equinor/ecalc-internal#1613


Type of Work

  • Patch: X.Y.Z+1. NEGLIGIBLE visible changes, does not change input or output - OR changes behaviour. Use chore:, refactor: etc
  • Minor: X.Y+1.Z. Minor changes, might ADD new input (YAML), or other backwards-compatible changes. Use feat:, fix:
  • Major: X+1.Y.Z. Major and most likely BREAKING changes, wo. backwards compatibility, or removing temporary backwards compatibility functionality. Use ! or BREAKING:.

See here (internal): https://github.com/equinor/ecalc-internal/discussions/1044

Have you remembered and considered?

  • IF FEAT: I have remembered to update documentation
  • IF FIX OR FEAT: I have remembered to update manual changelog (docs/drafts/next.draft.md)
  • IF BREAKING: I have remembered to update migration guide (docs/docs/migration_guides/)
  • IF BREAKING: I have committed with BREAKING: in footer or ! in header
  • I have added tests (if not, comment why)
  • I have used conventional commits syntax (if you squash, make sure that conventional commit is used)
  • I have included the Github issue nr in the footer!

What is this PR all about?

What else did you consider?

Between the lines?

@frodehk frodehk self-assigned this Mar 20, 2026
@frodehk frodehk requested review from a team as code owners March 20, 2026 08:18
@frodehk frodehk force-pushed the docs/generate-yaml-reference-from-pydantic branch 3 times, most recently from dccb7f5 to 2d5a71c Compare March 23, 2026 07:41
@frodehk frodehk force-pushed the docs/generate-yaml-reference-from-pydantic branch from 2d5a71c to 5871473 Compare March 23, 2026 07:42
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