feat: schema generation#1178
Conversation
✨ Highlights
🧾 Changes by Scope
🔝 Top Files
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1178 +/- ##
===========================================
+ Coverage 78.85% 79.07% +0.21%
===========================================
Files 308 306 -2
Lines 32157 32460 +303
Branches 6456 6441 -15
===========================================
+ Hits 25359 25667 +308
- Misses 4436 4438 +2
+ Partials 2362 2355 -7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
An automated preview of the documentation is available at https://1178.mrdocs.prtest2.cppalliance.org/index.html If more commits are pushed to the pull request, the docs will rebuild at the same URL. 2026-05-01 14:49:11 UTC |
762bc4d to
cdda298
Compare
Add a --schemas[=<dir>] option that writes a JSON Schema file (mrdocs-dom-schema.json) describing every object and field available to Handlebars templates. The schema is derived from the same compile-time reflection metadata used by MapReflectedType.hpp, so it stays in sync with the code automatically. The option requires no config file or source files — it writes the schema and exits immediately.
OperatorKind was the only enum serialized as a raw integer. All other enums serialize as human-readable strings. Change tag_invoke to use getOperatorName, consistent with the rest.
--schemas now writes both mrdocs-dom-schema.json (Handlebars DOM) and mrdocs.rnc (XML output). The XML schema mirrors XMLWriter.cpp's serialization.
…ClassKind
Replace manual toString and tag_invoke overloads with
MRDOCS_DESCRIBE_ENUM for four enums whose kebab-case names match the
existing string representations.
The XML writer now emits these fields (e.g. <access>public</access>,
<constexpr>constexpr</constexpr>) where they were previously silently
skipped. None/none sentinel values are suppressed via a generic
has_none_enumerator check.
TypeKind stays manual because toKebabCase("LValueReference") produces
"l-value-reference", not the established "lvalue-reference".
… --schemas This guarantees the RELAX NG schema stays in sync with the C++ type definitions. Every CI run now validates all golden test XML files against a schema derived from the same reflection metadata that produces the XML.
cdda298 to
b9fac7c
Compare
|
Path coverage is OK, isn't it? I added the PR description. |
This adds a small lookup table keyed by (typeName, memberName) carrying hand-written descriptions for the DOM seen by Handlebars templates which become "description" fields in the JSON schema.
alandefreitas
left a comment
There was a problem hiding this comment.
What about documentation? How do I use the feature? What about the schema in the documentation? Do we have no schema files in the repository? How do we check if the files are up to date in CI? Some of the changes in the golden files are also kind of weird (like ids changing and things like that and some groups are just empty, which could probably be removed in the schema - I'm not sure).
The PR is great though. The only reason I left many comment is because the PR is huge. 😅
| */ | ||
| inline | ||
| std::string | ||
| toJson(dom::Value const& v, int indent = 0) |
There was a problem hiding this comment.
Don't we already have this functionality defined somewhere else in the Dom library?
| */ | ||
| inline | ||
| std::string | ||
| toJson(dom::Value const& v, int indent = 0) |
There was a problem hiding this comment.
Why is this file in Schemas if it's a general JSON emitter (not JSON schema emitter)?
| */ | ||
| inline | ||
| std::string | ||
| toJson(dom::Value const& v, int indent = 0) |
There was a problem hiding this comment.
Why would the JSON schema go through dom::Value anyway?
| @@ -0,0 +1,761 @@ | |||
| // | |||
There was a problem hiding this comment.
I don't think we need public mrdocs/Schemas at all. Each generator (or category of generator) has an associated schema (or not). If even the generators aren't public, I see no reason for the scheme logic to be public.
| return entry.text; | ||
| } | ||
| } | ||
| return {}; |
There was a problem hiding this comment.
How do we ensure we never get here?
| /** Build the complete DOM JSON Schema document. | ||
| */ | ||
| inline dom::Value | ||
| buildDomSchema() |
There was a problem hiding this comment.
DOM Schema means JSON schema?
| // ------------------------------------------------------- | ||
| // Header | ||
| // ------------------------------------------------------- | ||
| line("#"); |
There was a problem hiding this comment.
This main function is kind of hard for a human to read. Is this one of these cases where instead of using reflection to improve the schema, we make the function very complex to match the bad pattern we used to have before?
| output, suitable for writing directly to `mrdocs.rnc`. | ||
| */ | ||
| inline std::string | ||
| buildRncSchema() |
There was a problem hiding this comment.
Should we be using RNC for XML at all? If we have reflection, why not already output the final schema?
| properties.set("class", withDesc(std::move(classSchema), "class")); | ||
|
|
||
| dom::Object boolSchema; | ||
| boolSchema.set("type", "boolean"); |
|
|
||
| } // (anon) | ||
|
|
||
| TEST_SUITE( |
There was a problem hiding this comment.
No tests for the other ones?


This PR addes a
--schemas[=<dir>]option that generates a mrdocs-dom-schema.json (Handlebars DOM) and mrdocs.rnc (XML output). Both schemas are generated from the reflection metadata. The old, hand-written, mrdocs.rnc is replaced entirely in CI.