Skip to content

Apply rename_all casing to RPC parameter names including a compat shim#63

Open
Eligioo wants to merge 3 commits into
masterfrom
camelcase-params
Open

Apply rename_all casing to RPC parameter names including a compat shim#63
Eligioo wants to merge 3 commits into
masterfrom
camelcase-params

Conversation

@Eligioo

@Eligioo Eligioo commented Jun 26, 2026

Copy link
Copy Markdown
Member

Extend #[service(rename_all = …)] and #[proxy(rename_all = …)] to rename RPC parameter names on the JSON wire including an automatic alias in order to retain backwards compatibility.

This PR supersedes #30 as it's non-breaking.

The three commits:

  • Rename method parameters to the configured casing — params now follow the same rename_all convention as method names (e.g. first_operandfirstOperand).
  • Generate a serde alias for backward compatibility — instead of renaming the Rust identifier, the macro keeps idents snake_case and emits #[serde(rename = "<new>", alias = "<old>")] per field. Servers therefore will accept both the new and the original name during the migration window. This also fixes a compile-time panic for rename_all = "kebab-case" (a hyphen is not a valid Rust identifier).
  • Warning at runtime when a legacy parameter name is used — the dispatcher emits a single log::warn! per request when a request still uses a pre-rename parameter name. Is a no-op when no params were renamed.

Examples

Old style still being accepted when rename_all is set to camelCase because of the alias for compatibility. Note: in this case a log::warn is outputted on the server side since at least one parameter isn't in camel case.

{
	"jsonrpc": "2.0",
	"method": "addNumbers",
	"params": {
		"first_operand": 2,
		"second_operand": 3
	},
	"id": 1
}

New style is also supported when rename_all is set to camelCase

{
	"jsonrpc": "2.0",
	"method": "addNumbers",
	"params": {
		"firstOperand": 2,
		"secondOperand": 3
	},
	"id": 1
}

@Eligioo
Eligioo requested a review from jsdanielh June 26, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant