hero_rpc2: OpenRpcDocument::from_value constructor (#90 framework gap) #99

Merged
timur merged 1 commit from issue-90-openrpc-from-value into development 2026-05-20 23:14:17 +00:00
Owner

Small framework addition surfaced while migrating hero_service onto hero_rpc2 in #90 Phase 2.

OSIS services build their OpenRPC document offline via codegen (the canonical <workspace>/docs/openrpc.json layout from #73) and include_str! it into the binary. Wiring it through ServerBuilder::with_discover was impossible — the existing API only accepted documents that the in-process OpenRpcBuilder had constructed from typed JsonSchema registrations, with no constructor to lift a raw serde_json::Value into the wrapping OpenRpcDocument newtype.

One-line addition: OpenRpcDocument::from_value(Value) -> Self. Same no-validation contract OpenRpcBuilder::build() has (the doc the builder produces also isn't validated against the spec — the convention is "the producer is responsible for correctness").

Test: tests/http_well_known.rs::openrpc_json_endpoint_returns_doc_from_value pins the round-trip — value in via from_value, exact same JSON out via GET /openrpc.json.

Unblocks the Phase 2 / 3 / 4 service migrations on #90; every OSIS service now wires with_discover(OpenRpcDocument::from_value(parsed_spec)) with their embedded docs/openrpc.json.

Small framework addition surfaced while migrating hero_service onto hero_rpc2 in [#90](https://forge.ourworld.tf/lhumina_code/hero_rpc/issues/90) Phase 2. OSIS services build their OpenRPC document offline via codegen (the canonical `<workspace>/docs/openrpc.json` layout from [#73](https://forge.ourworld.tf/lhumina_code/hero_rpc/issues/73)) and `include_str!` it into the binary. Wiring it through `ServerBuilder::with_discover` was impossible — the existing API only accepted documents that the in-process `OpenRpcBuilder` had constructed from typed `JsonSchema` registrations, with no constructor to lift a raw `serde_json::Value` into the wrapping `OpenRpcDocument` newtype. One-line addition: `OpenRpcDocument::from_value(Value) -> Self`. Same no-validation contract `OpenRpcBuilder::build()` has (the doc the builder produces also isn't validated against the spec — the convention is "the producer is responsible for correctness"). Test: `tests/http_well_known.rs::openrpc_json_endpoint_returns_doc_from_value` pins the round-trip — value in via `from_value`, exact same JSON out via `GET /openrpc.json`. Unblocks the Phase 2 / 3 / 4 service migrations on [#90](https://forge.ourworld.tf/lhumina_code/hero_rpc/issues/90); every OSIS service now wires `with_discover(OpenRpcDocument::from_value(parsed_spec))` with their embedded `docs/openrpc.json`.
feat(hero_rpc2): OpenRpcDocument::from_value constructor for codegen-built specs (#90)
Some checks failed
Test / test (push) Failing after 1m30s
Test / test (pull_request) Failing after 1m51s
709285ea7d
Phase 2 of hero_rpc#90 (migrating hero_service onto hero_rpc2) ran into
a small gap. Services in the Hero ecosystem don't build their OpenRPC
document at startup via `OpenRpcBuilder` — they `include_str!` the
codegen-produced `<workspace>/docs/openrpc.json` (the canonical layout
locked in #73). There was no way to lift that pre-built JSON into the
typed `OpenRpcDocument` that `ServerBuilder::with_discover` expects.

Add a one-line `OpenRpcDocument::from_value(Value) -> Self` constructor
that wraps an arbitrary JSON value. The caller is expected to feed in a
document that already conforms to OpenRPC — the constructor performs no
validation (matches the existing `OpenRpcBuilder::build` contract, which
also returns whatever the builder produced unchecked).

Test in `http_well_known.rs::openrpc_json_endpoint_returns_doc_from_value`
pins the round-trip: a JSON value handed in via `from_value` is exactly
what `GET /openrpc.json` serves.

Unblocks the Phase 2 / 3 service migrations — every OSIS service can
now wire `with_discover(OpenRpcDocument::from_value(parsed))` with the
spec it loaded from its embedded `docs/openrpc.json`.
timur merged commit c9067946f1 into development 2026-05-20 23:14:17 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lhumina_code/hero_rpc!99
No description provided.