Skip to content

Schema/JSON: rfl::json::to_schema emits nested anyOf for optional<Variant>, namespace-mangled $defs keys, and no unsigned/width bounds #180

Backlog

Description

@clockblocker

Part of #138
Popularity: 1/7 corpus consumers (moqx)

Related issues

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:

  1. Namespace-mangled $defs keys 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 $defs entry is named openmoq__moqx__config__Parsed* (e.g., openmoq__moqx__config__ParsedAuthConfig__AnonymousScope__ExactNamespace).
  2. Doubly-nested anyOf for std::optional<rfl::Variant<...>>:

  3. Unsigned / fixed-width integer types emit bare "type": "integer" with no width/sign bounds:

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

  1. $defs keys always use fully-qualified mangled C++ type names (namespace__Struct) with no configurable naming strategy.
  2. std::optional<T> wraps T's schema blindly in anyOf: [T_schema, {type: "null"}] without flattening when T_schema is already an anyOf.
  3. Integral types map uniformly to {"type": "integer"} without emitting minimum/maximum bounds for unsigned or fixed-width integers.

Suggested Direction / Fix

Upstream Overlap

Activity

  1. added
    known-downstream-workarounds
    on Nov 29, 2026
  2. clockblocker commented on Nov 29, 2026

    @clockblocker
    OwnerAuthor

    Tracking & PR Cross-Reference

    Status: 2/3 addressed in upstream-queue (Draft PR #209); custom $defs naming parked on discuss/ssot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    known-downstream-workarounds

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions