Skip to content

Commit 5c71c23

Browse files
authored
Define JSON-RPC v2.0 (#1)
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent b6418e6 commit 5c71c23

24 files changed

+3069
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Batch Request",
4+
"description": "An array of request objects sent to the server in a single batch",
5+
"$comment": "https://www.jsonrpc.org/specification#batch",
6+
"examples": [
7+
[
8+
{
9+
"id": "1",
10+
"jsonrpc": "2.0",
11+
"method": "sum",
12+
"params": [ 1, 2, 4 ]
13+
},
14+
{
15+
"jsonrpc": "2.0",
16+
"method": "notify_hello",
17+
"params": [ 7 ]
18+
},
19+
{
20+
"id": "2",
21+
"jsonrpc": "2.0",
22+
"method": "subtract",
23+
"params": [ 42, 23 ]
24+
}
25+
],
26+
[
27+
{
28+
"id": 1,
29+
"jsonrpc": "2.0",
30+
"method": "get_data"
31+
}
32+
],
33+
[
34+
{
35+
"jsonrpc": "2.0",
36+
"method": "notify_update"
37+
},
38+
{
39+
"id": "req-1",
40+
"jsonrpc": "2.0",
41+
"method": "fetch",
42+
"params": {
43+
"key": "value"
44+
}
45+
}
46+
]
47+
],
48+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
49+
"type": "array",
50+
"minItems": 1,
51+
"items": {
52+
"anyOf": [
53+
{
54+
"$ref": "./request.json"
55+
},
56+
{
57+
"$ref": "./notification.json"
58+
}
59+
]
60+
}
61+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Batch Response",
4+
"description": "An array of response objects returned by the server in response to a batch request",
5+
"$comment": "https://www.jsonrpc.org/specification#batch",
6+
"examples": [
7+
[
8+
{
9+
"id": "1",
10+
"jsonrpc": "2.0",
11+
"result": 7
12+
},
13+
{
14+
"id": "2",
15+
"jsonrpc": "2.0",
16+
"result": 19
17+
},
18+
{
19+
"id": null,
20+
"error": {
21+
"code": -32600,
22+
"message": "Invalid Request"
23+
},
24+
"jsonrpc": "2.0"
25+
}
26+
],
27+
[
28+
{
29+
"id": 1,
30+
"jsonrpc": "2.0",
31+
"result": {
32+
"status": "ok"
33+
}
34+
}
35+
],
36+
[
37+
{
38+
"id": "req-1",
39+
"error": {
40+
"code": -32601,
41+
"message": "Method not found"
42+
},
43+
"jsonrpc": "2.0"
44+
}
45+
]
46+
],
47+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
48+
"type": "array",
49+
"minItems": 1,
50+
"items": {
51+
"$ref": "./response.json"
52+
}
53+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Predefined Error Code",
4+
"description": "An error code from the predefined range reserved by the JSON-RPC 2.0 specification",
5+
"$comment": "https://www.jsonrpc.org/specification#error_object",
6+
"examples": [ -32700, -32600, -32601, -32602, -32603, -32000 ],
7+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
8+
"type": "integer",
9+
"anyOf": [
10+
{
11+
"title": "Parse error",
12+
"description": "Invalid JSON was received by the server",
13+
"const": -32700
14+
},
15+
{
16+
"title": "Invalid request",
17+
"description": "The JSON sent is not a valid Request object",
18+
"const": -32600
19+
},
20+
{
21+
"title": "Method not found",
22+
"description": "The method does not exist / is not available",
23+
"const": -32601
24+
},
25+
{
26+
"title": "Invalid params",
27+
"description": "Invalid method parameter(s)",
28+
"const": -32602
29+
},
30+
{
31+
"title": "Internal error",
32+
"description": "Internal JSON-RPC error",
33+
"const": -32603
34+
},
35+
{
36+
"title": "Server error",
37+
"description": "Implementation-defined server error",
38+
"maximum": -32000,
39+
"minimum": -32099
40+
}
41+
]
42+
}

schemas/jsonrpc/v2.0/code.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Error Code",
4+
"description": "A number that indicates the error type that occurred",
5+
"$comment": "https://www.jsonrpc.org/specification#error_object",
6+
"examples": [ -32700, -32600, -32601, -32000, 100, -1 ],
7+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
8+
"anyOf": [
9+
{
10+
"$ref": "./code-predefined.json"
11+
},
12+
{
13+
"type": "integer"
14+
}
15+
]
16+
}

schemas/jsonrpc/v2.0/error.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Error Object",
4+
"description": "An object that describes an error that occurred during the request",
5+
"$comment": "https://www.jsonrpc.org/specification#error_object",
6+
"examples": [
7+
{
8+
"code": -32600,
9+
"message": "Invalid Request"
10+
},
11+
{
12+
"code": -32601,
13+
"message": "Method not found"
14+
},
15+
{
16+
"code": -32000,
17+
"data": {
18+
"details": "Database connection failed"
19+
},
20+
"message": "Server error"
21+
}
22+
],
23+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
24+
"type": "object",
25+
"required": [ "code", "message" ],
26+
"properties": {
27+
"code": {
28+
"description": "The error type",
29+
"$ref": "./code.json"
30+
},
31+
"data": {
32+
"description": "Additional error information"
33+
},
34+
"message": {
35+
"description": "The error description",
36+
"type": "string"
37+
}
38+
}
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Identifier",
4+
"description": "An identifier established by the client that must be matched in the response if included in a request",
5+
"$comment": "https://www.jsonrpc.org/specification#request_object",
6+
"examples": [ "abc123", 42, null, "request-1" ],
7+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
8+
"type": [ "string", "integer", "null" ]
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Internal Method Name",
4+
"description": "A method name reserved for system extensions that begins with the prefix 'rpc.'",
5+
"$comment": "https://www.jsonrpc.org/specification#request_object",
6+
"examples": [ "rpc.discover", "rpc.introspect", "rpc.system.info" ],
7+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
8+
"type": "string",
9+
"pattern": "^rpc\\."
10+
}

schemas/jsonrpc/v2.0/method.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Method Name",
4+
"description": "A string containing the name of the method to be invoked",
5+
"$comment": "https://www.jsonrpc.org/specification#request_object",
6+
"examples": [ "subtract", "update", "notify_hello", "rpc.discover", "sum" ],
7+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
8+
"anyOf": [
9+
{
10+
"$ref": "./method-internal.json"
11+
},
12+
{
13+
"type": "string"
14+
}
15+
]
16+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Notification",
4+
"description": "A request object without an identifier that must not be responded to by the server",
5+
"$comment": "https://www.jsonrpc.org/specification#notification",
6+
"examples": [
7+
{
8+
"jsonrpc": "2.0",
9+
"method": "update"
10+
},
11+
{
12+
"jsonrpc": "2.0",
13+
"method": "notify_hello",
14+
"params": [ 7 ]
15+
},
16+
{
17+
"jsonrpc": "2.0",
18+
"method": "notify_sum",
19+
"params": {
20+
"a": 1,
21+
"b": 2
22+
}
23+
}
24+
],
25+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
26+
"type": "object",
27+
"required": [ "jsonrpc", "method" ],
28+
"properties": {
29+
"id": {
30+
"description": "Must not be included",
31+
"not": true
32+
},
33+
"jsonrpc": {
34+
"description": "The protocol version",
35+
"const": "2.0"
36+
},
37+
"method": {
38+
"description": "The method name",
39+
"$ref": "./method.json"
40+
},
41+
"params": {
42+
"description": "The method parameters",
43+
"$ref": "./parameters.json"
44+
}
45+
}
46+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"title": "JSON-RPC 2.0 Parameter Structures",
4+
"description": "A structured value that holds the parameter values to be used during the invocation of the method",
5+
"$comment": "https://www.jsonrpc.org/specification#parameter_structures",
6+
"examples": [
7+
[ 42, "foo" ],
8+
{
9+
"age": 30,
10+
"name": "John"
11+
},
12+
[]
13+
],
14+
"x-license": "https://github.com/sourcemeta/std/blob/main/LICENSE",
15+
"type": [ "array", "object" ]
16+
}

0 commit comments

Comments
 (0)