Fix multiple OpenRPC schema issues #3502
Open
+101
−26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have an automation that checks the JSON schema specification against my TypeScript (TS) library. I perform a lot of validations to ensure that my TS library is up to date. At the end of the process, I also use GPT-5 to validate the implementation with an LLM (https://github.com/onmax/albatross-rpc-client-ts/blob/main/scripts/validate-schema.ts#L237-L264). I run this validation once a month.
Yesterday, I fixed the problems that the AI found in my library. See closed issues: https://github.com/onmax/albatross-rpc-client-ts/issues?q=sort%3Aupdated-desc%20is%3Aissue%20state%3Aclosed. However, there are some issues that are part of the JSON schema generation process. This PR attempts to address these issues.
For each fix, you will see all the affected methods with two links:
Important
The code written in this PR has been 100% AI. Maybe it is not the most optimal solution!
Summary
Fixes #3499, #3500, #3501, #3503, #3504, #3505 - Multiple OpenRPC schema corrections
This PR fixes 6 issues in the OpenRPC schema generator to accurately reflect the actual Rust implementation.
Changes
#3500: Optional parameters (565d67e)
📋 Details
Issue:
Option<T>parameters always marked as requiredFix: Enable nullable params by checking for
Optionwrapper with AST-based detection (tools/src/rpc-schema/parser.rs:273)Example:
new_signing_secret_key: Option<String>now hasrequired: falseAffected:
createUpdateValidatorTransaction,sendUpdateValidatorTransactioncreateUpdateValidatorTransaction,sendUpdateValidatorTransactionSchema Comparison:
newSigningSecretKey"required": true"required": falsenewVotingSecretKey"required": true"required": falsenewRewardAddress"required": true"required": falsenewSignalData"required": true"required": false#3501: Underscore field names (8fbfd4b)
📋 Details
Issue: Fields like
_0,_1converted to"0","1"in schemaFix: Preserve underscore prefixes, only camelCase other fields (tools/src/rpc-schema/parser.rs:50, 160)
Example: MempoolInfo now has
"_0","_1"fieldsAffected:
mempoolContentmempoolContentSchema Comparison:
"0": { "type": "number" }"_0": { "type": "number" }"1": { "type": "number" }"_1": { "type": "number" }"2": { "type": "number" }"_2": { "type": "number" }"5": { "type": "number" }"_5": { "type": "number" }#3503: BitSet type mapping (a4ab5c8)
📋 Details
Issue: BitSet mapped as object instead of array
Fix: Map BitSet as array of numbers (tools/src/rpc-schema/parser.rs:87, 133)
Example:
disabled: BitSetnow generates{ "type": "array", "items": { "type": "number" } }Affected:
getCurrentPenalizedSlots,getPreviousPenalizedSlotsgetCurrentPenalizedSlots,getPreviousPenalizedSlotsSchema Comparison:
"object""array"{ "type": "number" }{})[]or[5, 12, 33]#3504: ValidityStartHeight union type (25b86ce)
📋 Details
Issue: ValidityStartHeight only accepts number, but deserializer supports string ("+N" syntax)
Fix: Use oneOf to accept both string and number (tools/src/rpc-schema/parser.rs:429)
Example:
validityStartHeightnow accepts"string"ornumberAffected:
createBasicTransaction, and all other transaction methodscreateBasicTransaction, and all other transaction methodsSchema Comparison:
"number"onlyoneOf: ["string", "number"]1000000✅"+150"❌1000000✅"+150"✅#3505: RPCData envelope (25b86ce)
📋 Details
Issue: Results documented as raw values, but server wraps in
{ data, metadata }Fix: Generate object schema with data and metadata properties, including required fields (tools/src/rpc-schema/parser.rs:344)
Example: All method results now show RPCData envelope structure with required fields
Affected:
getBlockNumber)getBlockNumber)Schema Comparison:
"number"(direct value)"object"(envelope)data+metadata["data", "metadata"]31832934{ "data": 31832934, "metadata": null }Bonus fix: Generic type panic (25b86ce)
📋 Details
Issue: Parser panicked on non-Path generic arguments (e.g., tuple types)
Fix: Handle all generic argument types gracefully (tools/src/rpc-schema/parser.rs:549)
Schema Comparison
Files available at: https://github.com/nimiq/developer-center/pull/158/files#diff-0c6879564246475a0e967d833463378cb40a07da8cdb8561884cf920f3c98475