Skip to main content

Import an OpenRPC / JSON-RPC API

The OpenRPC importer (openrpc) reads an OpenRPC document, the standard description of a JSON-RPC 2.0 service, into the Catalog. OpenRPC is the de-facto API description across web3: Ethereum clients, wallets and many blockchain nodes publish one. Each method becomes an operation, and the component schemas become types. You can then search, version, diff, lint and convert it like any other catalog item.

Import it​

What you haveHow to bring it in
An OpenRPC document (.json, .openrpc.json)Upload, paste or link it in the import wizard (Import to catalog → OpenRPC), or apiome import openrpc ./openrpc.json.
A running JSON-RPC serviceapiome import openrpc --discover https://rpc.example.com/

Parameters and results written as references to reusable content descriptors ({"$ref": "#/components/contentDescriptors/BlockNumber"}) are resolved, so every method keeps all of its parameters, in order.

Each method keeps its parameters, paramStructure, result, errors (with their code, message and data), tags and deprecated flag. A reference into components/errors is followed. A method with no result is a notification and is cataloged as a one-way operation.

Discover a live service​

A JSON-RPC service that supports OpenRPC service discovery answers the reserved method rpc.discover with its own OpenRPC document. Give --discover the service's JSON-RPC endpoint:

apiome import openrpc --discover https://rpc.example.com/

The CLI sends one JSON-RPC call to the endpoint:

{"jsonrpc": "2.0", "id": 1, "method": "rpc.discover", "params": []}

It reports the endpoint that answered (Discovered OpenRPC document at …) and imports the document it returned. The endpoint's path and query are kept, so a provider URL that carries an API key, such as https://mainnet.example.com/v3/<key>, works as given. The key never becomes the name of the imported file. --discover must be the only input.

MessageWhyWhat to do
does not implement rpc.discoverThe service answered Method not found (-32601).Ask the provider for the OpenRPC document and import the file.
answered rpc.discover with an errorThe service returned another JSON-RPC error, such as a rate limit.Retry, or check the credentials the endpoint needs.
returned no OpenRPC documentThe reply's result is not an OpenRPC document.Check that the URL is the JSON-RPC endpoint and not a web page.
returned HTTP …The endpoint refused the call.Check the URL and that the endpoint accepts POST.

Breaking changes between versions​

JSON-RPC callers pass parameters by position (an array) or by name (an object), and a method's paramStructure (by-position, by-name, or either, the default) says which. A new version of an OpenRPC catalog item is compared parameter by parameter with that in mind:

ChangeSeverityRule
A parameter removedBreakingopenrpc.param-removed
A required parameter addedBreakingopenrpc.required-param-added
An optional parameter added after the othersSafeopenrpc.optional-param-added
A parameter moved to another positionBreaking; safe when the method is by-nameopenrpc.param-moved
A parameter renamed, position and schema unchangedBreaking; safe when the method is by-positionopenrpc.param-renamed
An optional parameter made requiredBreakingopenrpc.made-required
A required parameter made optionalSafeopenrpc.made-optional
A parameter's schema changedDangerousopenrpc.param-schema-changed
paramStructure no longer allows a call style it allowedBreakingopenrpc.param-structure-narrowed
paramStructure changed to eitherSafeopenrpc.param-structure-widened

Every other change (a removed method, a changed result) is graded by the standard rules.

Lint rules​

On top of the common rules, every OpenRPC catalog item is checked by the openrpc pack:

RuleSeverityChecks
openrpc.unique-method-namesErrorNo two methods share a name.
openrpc.unique-param-namesErrorNo two parameters of a method share a name.
openrpc.required-params-firstErrorEvery required parameter comes before the optional ones.
openrpc.reserved-method-nameWarningNo method name begins with rpc., which JSON-RPC reserves (rpc.discover is allowed).
openrpc.method-describedInfoEvery method has a summary or a description.