Repository navigation
Description
Part of #138
Popularity: 1/7 corpus consumers (wolf)
Related issues
- Related fork issues & PRs: Prototype JSON Schema extensibility ($defs naming, custom wrapper x-* hooks, integer width bounds, title/examples) #100 / PR Add SchemaName, SchemaExtension, IntegerBounds, TupleBounds, OmitEmptyRequired, and flattened optional<variant> anyOf #121 (
SchemaName— avoids leaking mangledrfl__Reflector_...___ReflTypenames into OpenAPI), Triage & Design Notes (Fork-Only): Speculative Schema / Contract APIs #136 (out-of-band traits).
Problem
rfl::Reflector<T> only supports stateless 1-argument static T to(const ReflType&) deserialization. In real servers where domain structs hold non-serializable runtime dependencies (such as an EventBus pointer, immer::atom, or polymorphic std::shared_ptr<Runner> constructed via a factory), consumers cannot use rfl::json::read<DomainType> directly.
Instead, they must define non-standard 2-argument Reflector<T>::to(const ReflType&, Context) methods (or write-only Reflector<T> specializations with only from()) and manually bypass automatic Reflector<T> dispatch everywhere — leaking rfl::Reflector<T>::ReflType into API DTOs, endpoint handlers, tests, and rfl::json::to_schema<...>().
Observed Downstream Workarounds
games-on-whales/wolf (ac2461f6)
-
Non-standard 2-arg
Reflector<T>::to(ReflType, ev_bus)and write-onlyReflector<T>specializations:
src/moonlight-server/events/reflectors.hpp#L33-L203defines 6 reflectors (events::Runner,events::App,events::Profile,events::StartRunner,events::StreamSession,events::Lobby) that cannot be used byrfl::json::read<T>()directly:template <> struct Reflector<events::Runner> { using ReflType = events::RunnerTypes; static ReflType from(const events::Runner &v) { return v.serialize(); } static std::shared_ptr<events::Runner> to(const ReflType &v, const std::shared_ptr<events::EventBusType> &ev_bus) { return state::get_runner(v, ev_bus); } }; template <> struct Reflector<events::App> { struct ReflType { ... Reflector<events::Runner>::ReflType runner; }; static ReflType from(const events::App &v) { ... } static events::App to(const ReflType &app, const std::shared_ptr<events::EventBusType> &ev_bus) { ... } };
-
rfl::Reflector<T>::ReflTypeleaked across DTOs, endpoints, tests, and schemas:- API DTOs embed
ReflTypedirectly instead of domain types:src/moonlight-server/api/api.hpp#L74,#L83,#L97,#L147(e.g.std::vector<rfl::Reflector<events::App>::ReflType> apps;). - Endpoint handlers manually invoke
from()andto(..., ev_bus):src/moonlight-server/api/endpoints.cpp#L96-L111,#L161-L174,#L207-L213,#L401:auto app = rfl::json::read<rfl::Reflector<events::App>::ReflType>(req.body); ... return apps.push_back(rfl::Reflector<events::App>::to(app, this->state_->app_state->event_bus));
- Schema registration calls
rfl::json::to_schema<rfl::Reflector<...>::ReflType>()insrc/moonlight-server/api/unix_socket_server.cpp#L108,#L141,#L178, which leaks internalReflectornames directly into the published OpenAPI spec (docs/modules/dev/partials/spec.json#L179,#L550,#L667):"$ref": "#/components/schemas/rfl__Reflector_wolf__core__events__App___ReflType"
- API DTOs embed
-
Real production drift bug caused by manual
ReflType/to()duplication (wolf#465):
Commit00e16b11("fix(api): keep start_audio_server when deserialising an App", Fixesgames-on-whales/wolf#465) fixed a silent bug whereReflector<events::App>::to()omitted.start_audio_server = app.start_audio_server, leaving every app added viaPOST /api/v1/apps/addwith audio silently disabled even thoughfrom()andconfigTOML.cppboth populated it.
Root Cause in reflect-cpp
rfl::Reflector<T>is purely static/context-free (to(const ReflType&)); there is no mechanism to pass a read/deserialization context (or custom converter context) throughrfl::json::read<T>(input, ctx).- When
to_schema<Reflector<T>::ReflType>()is called directly (as forced by the above),make_type_namemangles the fullrfl::Reflector<...>::ReflTypenested type name into the schema$defskey.
Suggested Direction
- Evaluate whether
rfl::Reflector<T>/readshould support an optional user context argument (or document the recommended explicit-DTO separation pattern cleanly) so nested context-dependent types (Profile->App->Runner) don't force manual recursiveReflTypeplumbing. - Ensure
rfl::json::to_schema<T>()works cleanly on write-onlyReflector<T>types (usingT's schema name rather than forcing callers to passReflector<T>::ReflType) and supports explicit schema naming (Prototype JSON Schema extensibility ($defs naming, custom wrapper x-* hooks, integer width bounds, title/examples) #100 / Triage & Design Notes (Fork-Only): Speculative Schema / Contract APIs #136).
Upstream Overlap
- Json Schema with Reflector type munich-data-engineering/reflect-cpp#509 / Added support for JSON schemata for the Reflector type; fixes #509 munich-data-engineering/reflect-cpp#527 (closed/fixed via merged PR, partial, post-
wolfv0.21.0) — Addedto_schema<T>()support forReflector<T>types (including write-only reflectors viahas_write_reflector<U>), emittingT's own type name rather than forcing callers to passReflector<T>::ReflType. - Unfiled upstream: Context / dependency injection into
Reflector<T>::to(const ReflType&, Context).
Activity
clockblocker commentedon Nov 29, 2026
Triage decision: closing as
wontfix(not planned) for the upstream adoption track.Rationale: Injecting runtime context / dependency injection (e.g.,
EventBusor service lifecycles) intoReflector<T>::to()mixes runtime state into pure deserialization — an anti-pattern that would complicatereflect-cpp's core parser API across all formats. Explicit DTO-to-domain mapping at the application boundary is standard C++.