Generator: emit servers block in openrpc.json so openrpc_client!::connect() resolves to the service's Unix socket #92

Open
opened 2026-05-20 09:46:21 +00:00 by timur · 1 comment
Owner

Problem

The generated openrpc.json lacks a servers block. Without it, hero_rpc_derive::openrpc_client!'s generated connect() method has no idea which Unix socket the service runs on, and consumers can't call it without manually supplying the socket path.

Found by the hero_logic#46 agent during the template-pattern migration — they patched a servers block into the openrpc.json in a build.rs post-process step. That hack is what this issue removes.

What to do

The generator already has access to the service's socket path via service.toml ([[binaries.sockets]] with protocol = "openrpc"). Emit a servers block in every generated openrpc.json referencing that socket:

"servers": [
  {
    "name": "<service>",
    "url": "unix://<socket-path>",
    "description": "<service> over Unix domain socket"
  }
]

Applies to both the aggregate docs/openrpc.json and the per-domain docs/<domain>/openrpc.json files.

Acceptance

  • Every generated openrpc.json includes a servers block referencing the service's RPC socket.
  • openrpc_client!'s connect() resolves to the right socket without manual configuration.
  • hero_logic (and any other consumer) can drop the build.rs servers-patching step.
  • recipe_server + hero_service regenerate clean.
## Problem The generated `openrpc.json` lacks a `servers` block. Without it, `hero_rpc_derive::openrpc_client!`'s generated `connect()` method has no idea which Unix socket the service runs on, and consumers can't call it without manually supplying the socket path. Found by the [hero_logic#46](https://forge.ourworld.tf/lhumina_code/hero_logic/pulls/46) agent during the template-pattern migration — they patched a `servers` block into the openrpc.json in a `build.rs` post-process step. That hack is what this issue removes. ## What to do The generator already has access to the service's socket path via `service.toml` (`[[binaries.sockets]]` with `protocol = "openrpc"`). Emit a `servers` block in every generated `openrpc.json` referencing that socket: ```json "servers": [ { "name": "<service>", "url": "unix://<socket-path>", "description": "<service> over Unix domain socket" } ] ``` Applies to both the aggregate `docs/openrpc.json` and the per-domain `docs/<domain>/openrpc.json` files. ## Acceptance - Every generated `openrpc.json` includes a `servers` block referencing the service's RPC socket. - `openrpc_client!`'s `connect()` resolves to the right socket without manual configuration. - `hero_logic` (and any other consumer) can drop the `build.rs` servers-patching step. - `recipe_server` + `hero_service` regenerate clean. ## Related - Discovery: [hero_logic#46 PR body](https://forge.ourworld.tf/lhumina_code/hero_logic/pulls/46) item 2 - Pairs with the title fix: companion issue filed alongside
Author
Owner

Implementation pushed on branch issue-91-92-93-generator-fixes. Bundled with the other two generator fixes from the same root (the hero_logic#46 build.rs post-process patches).

  • #91 title format is now <service> - <domain> (space-dash-space). Aggregate strip logic updated to match.
  • #92 emits servers[] from service.toml [[binaries.sockets]] with protocol = "openrpc", URL shape unix://${HERO_SOCKET_DIR}/<path> so openrpc_client!::connect() resolves via resolve_socket_path_with_override. Per-domain narrows by binary name suffix _<domain>; aggregate keeps the union.
  • #93 generate_server_lib_rs discovers hand-written *.rs / <dir>/mod.rs modules carrying //! @server-feature: and emits pub mod lines for them. Marker-required (server crates carry internal helpers; SDK-style discover-everything would over-expose).

Verified via example/recipe_server regen + cargo build --workspace clean + cargo test -p hero_rpc_generator --lib (131 passed).

Implementation pushed on branch [issue-91-92-93-generator-fixes](https://forge.ourworld.tf/lhumina_code/hero_rpc/src/branch/issue-91-92-93-generator-fixes). Bundled with the other two generator fixes from the same root (the hero_logic#46 build.rs post-process patches). - **#91** title format is now `<service> - <domain>` (space-dash-space). Aggregate strip logic updated to match. - **#92** emits `servers[]` from `service.toml` `[[binaries.sockets]]` with `protocol = "openrpc"`, URL shape `unix://${HERO_SOCKET_DIR}/<path>` so `openrpc_client!::connect()` resolves via `resolve_socket_path_with_override`. Per-domain narrows by binary name suffix `_<domain>`; aggregate keeps the union. - **#93** `generate_server_lib_rs` discovers hand-written `*.rs` / `<dir>/mod.rs` modules carrying `//! @server-feature:` and emits `pub mod` lines for them. Marker-required (server crates carry internal helpers; SDK-style discover-everything would over-expose). Verified via `example/recipe_server` regen + `cargo build --workspace` clean + `cargo test -p hero_rpc_generator --lib` (131 passed).
Sign in to join this conversation.
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#92
No description provided.