Repository navigation
Description
Part of #138
Popularity: 1/7 corpus consumers (moqx)
Related issues
- Directly corroborates fork work in Map (Lane 4): Schema & Contract Fidelity #88 (Map: Schema & Contract Fidelity), Prototype JSON Schema extensibility ($defs naming, custom wrapper x-* hooks, integer width bounds, title/examples) #100 (JSON Schema extensibility:
$defsnaming, integer width bounds), closed rfl::json::to_schema: flatten nested anyOf for std::optional<std::variant<...>> #109 (rfl::json::to_schema: flatten nestedanyOfforstd::optional<std::variant<...>>), and Triage & Design Notes (Fork-Only): Speculative Schema / Contract APIs #136 (Speculative Schema / Contract APIs).
Evidence in openmoq/moqx (60bab7f13925acbaf578670223e660d71e891547)
moqx commits the output of rfl::json::to_schema as its public editor/validator JSON Schema (config.schema.json, 84 KB, verified by ConfigSchema.CommittedSchemaIsCurrent) and ships a jq-based markdown doc generator over it. Three concrete schema fidelity issues are visible in moqx's committed schema and tests:
-
Namespace-mangled
$defskeys leak internal C++ namespaces into the published JSON Schema:test/config/LoaderTest.cpp#L391-L415:const auto& defs = schema->defs.value(); for (const auto& [type, expected] : cases) { SCOPED_TRACE(type); const auto it = defs.find("openmoq__moqx__config__" + type); ASSERT_NE(it, defs.end());
config.schema.json#L3-L16: every$defsentry is namedopenmoq__moqx__config__Parsed*(e.g.,openmoq__moqx__config__ParsedAuthConfig__AnonymousScope__ExactNamespace).
-
Doubly-nested
anyOfforstd::optional<rfl::Variant<...>>:src/config/loader/ParsedConfig.h#L457-L481(std::optional<NamespaceMatch>andstd::optional<TrackMatch>, each a 4-wayrfl::Variant) produces nestedanyOfinsideanyOfinconfig.schema.json#L511-L555:(Fixed on the fork in rfl::json::to_schema: flatten nested anyOf for std::optional<std::variant<...>> #109.)"namespace_match": { "description": "Namespace match; omit to match any namespace", "anyOf": [ { "anyOf": [ { "$ref": "#/$defs/openmoq__moqx__config__ParsedAuthConfig__AnonymousScope__ExactNamespace" }, ... ] }, { "type": "null" } ] }
-
Unsigned / fixed-width integer types emit bare
"type": "integer"with no width/sign bounds:src/config/loader/ParsedConfig.h#L28(uint16_t port) andParsedConfig.h#L110-L113(uint8_t) emit bare"type": "integer"with nominimum: 0ormaximum: 65535/255inconfig.schema.json#L256-L259andconfig.schema.json#L2142-L2145, so IDE YAML schema validators accept negative numbers and out-of-range ports unless prose descriptions are enforced manually.
(Historical note: moqx also had to upgrade from reflect-cpp v0.18.0 to v0.22.0 in commit 26e037a5 because v0.18.0 emitted rfl::Description<..., std::optional<T>> fields as required, and had to rewrite scripts/dev/config-schema-to-markdown.sh#L24-L44 when v0.22.0 switched from #/definitions/ to #/$defs/.)
Root Cause in reflect-cpp
In upstream v0.22.0's rfl::json::schema::TypeHelper:
$defskeys always use fully-qualified mangled C++ type names (namespace__Struct) with no configurable naming strategy.std::optional<T>wrapsT's schema blindly inanyOf: [T_schema, {type: "null"}]without flattening whenT_schemais already ananyOf.- Integral types map uniformly to
{"type": "integer"}without emittingminimum/maximumbounds for unsigned or fixed-width integers.
Suggested Direction / Fix
- Keep rfl::json::to_schema: flatten nested anyOf for std::optional<std::variant<...>> #109's nested-
anyOfflattening in the rewrite. - Support opt-in
$defsnaming strategies (e.g., short/unqualified names or custom namer) and opt-in integer width/sign bounds (minimum/maximum) per Prototype JSON Schema extensibility ($defs naming, custom wrapper x-* hooks, integer width bounds, title/examples) #100 / Map (Lane 4): Schema & Contract Fidelity #88.
Upstream Overlap
- Automatic min and max in json schema for integers munich-data-engineering/reflect-cpp#683 (open, exact for integer width/unsigned bounds) — "Automatic min and max in json schema for integers"; after initial hesitation over overhead, maintainer
@liuzicheng1987clarified "sorry, I misunderstood the issue. I think this is very possible." - oneOf instead of anyOf in json_schema for rfl::Variant munich-data-engineering/reflect-cpp#375 (open, partial) — Requests
oneOfinstead ofanyOfin JSON Schema forrfl::Variant(maintainer agreed "oneOf is more accurate. We should change it"); nestedanyOfflattening forstd::optional<rfl::Variant<...>>is not specifically filed. - Unfiled upstream: Configurable / non-namespace-mangled
$defsschema key naming.
Activity
clockblocker commentedon Nov 29, 2026
Tracking & PR Cross-Reference
Status: 2/3 addressed in
upstream-queue(Draft PR #209); custom$defsnaming parked ondiscuss/ssot.upstream-queue(Draft PR Upstream PR Queue (sorted by mergeability score) #209):anyOfforstd::optional<Variant>/rfl::Generic(fork issue rfl::json::to_schema: flatten nested anyOf for std::optional<std::variant<...>> #109, originally prototyped in fork PR Add SchemaName, SchemaExtension, IntegerBounds, TupleBounds, OmitEmptyRequired, and flattened optional<variant> anyOf #121 / branchwave5/nested-anyof-schema) → polished & queued as Rank Read structs with defaults that hold a Validator without a valid default #12 in Draft PR Upstream PR Queue (sorted by mergeability score) #209 (commit873c6002, score 86/100).rfl::IntegerBounds) (fork PR Add opt-in rfl::IntegerBounds and rfl::TupleBounds JSON Schema processors #137, refs upstreammunich-data-engineering/reflect-cpp#683) → polished & queued as Rank Add rfl::cli::usage to generate usage and help text #23 in Draft PR Upstream PR Queue (sorted by mergeability score) #209 (commit8bb48c32, score 80/100).oneOfschema fidelity (fork PR Emit oneOf for rfl::TaggedUnion in JSON schema, add VariantsAsOneOf #14, refs upstreammunich-data-engineering/reflect-cpp#375) → split in Draft PR Upstream PR Queue (sorted by mergeability score) #209 into Rank Add rfl::cli::BlankItemsAsMissing to keep blank list items #4 (commitb9dc1e93, score 92/100,rfl::TaggedUniononeOf) and Rank Accept--key valuefor long options that take a value #25 (commit3d529a03, score 74/100,rfl::VariantsAsOneOfopt-in processor).SchemaName<T>/SchemaExtension<T>for unmangled$defskeys (fork PR Add SchemaName, SchemaExtension, IntegerBounds, TupleBounds, OmitEmptyRequired, and flattened optional<variant> anyOf #121, scored 40/100) remains parked ondiscuss/ssotpending upstream maintainer design sign-off (see Draft PR Upstream PR Queue (sorted by mergeability score) #209 parked table).