info_tfgrid/collections/tfgrid4specs/openrpc_openapi_spec.md
2024-10-03 17:29:42 +03:00

287 lines
7.8 KiB
Markdown

## openapi spec as endpoint for OpenRPC Rest Server
copy paste in https://editor.swagger.io/
```json
{
"openapi": "3.0.0",
"info": {
"title": "Mycelium Agent RPC API",
"description": "An API for Mycelium Agent for handling asynchronous tasks, returning results, and managing RPC call statuses.",
"version": "1.0.0"
},
"paths": {
"/rpc_in": {
"post": {
"summary": "Initiates an RPC call",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RPCIn"
}
}
}
},
"responses": {
"200": {
"description": "RPC initiated",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"rpc_id": {
"type": "string",
"description": "Unique identifier of the initiated RPC call"
}
}
}
}
}
}
}
}
},
"/rpc_return": {
"post": {
"summary": "Handles an asynchronous return of an RPC call result",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RPCReturn"
}
}
}
},
"responses": {
"200": {
"description": "RPC return received",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"confirmation": {
"type": "string",
"example": "RPC return successfully received"
}
}
}
}
}
}
}
}
},
"/rpc_check": {
"get": {
"summary": "Checks the status of an RPC call",
"parameters": [
{
"name": "rpc_id",
"in": "query",
"required": true,
"schema": {
"type": "string"
},
"description": "The unique identifier of the RPC call"
},
{
"name": "signature",
"in": "query",
"required": true,
"schema": {
"type": "string"
},
"description": "Signature of the rpc_id, signed by the caller"
}
],
"responses": {
"200": {
"description": "Status of the RPC call",
"content": {
"application/json": {
"schema": {
"type": "string",
"enum": ["done", "error", "running", "pending"]
}
}
}
}
}
}
},
"/rpc_kill": {
"post": {
"summary": "Stops an RPC call that is running",
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/RPCKill"
}
}
}
},
"responses": {
"200": {
"description": "RPC call stopped",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"confirmation": {
"type": "string",
"example": "RPC call 12345 has been stopped"
}
}
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"RPCIn": {
"type": "object",
"required": [
"rpc_id",
"method_name",
"params",
"pubkey",
"signature",
"async"
],
"properties": {
"rpc_id": {
"type": "string",
"description": "A unique identifier for the RPC call."
},
"method_name": {
"type": "string",
"description": "The name of the method being called."
},
"params": {
"type": "object",
"description": "The parameters for the method call in JSON format, is encrypted."
},
"pubkey": {
"type": "string",
"description": "The public key of the Mycelium Agent making the call."
},
"signature": {
"type": "string",
"description": "A signature of rpc_id + method_name + params + return_url + return_topic, signed with the Mycelium Agent private key."
},
"async": {
"type": "boolean",
"description": "Indicates whether the call should be asynchronous."
},
"return_url": {
"type": "string",
"nullable": true,
"description": "The URL to return the result. Optional, used when async is true."
},
"return_topic": {
"type": "string",
"description": "The topic for the sender to know what the return result is related to."
}
},
"example": {
"rpc_id": "12345",
"method_name": "get_data",
"params": { "key": "value" },
"pubkey": "abc123",
"signature": "signeddata",
"async": true,
"return_url": "http://callback.url/result",
"return_topic": "my_topic"
}
},
"RPCReturn": {
"type": "object",
"required": [
"rpc_id",
"method_name",
"params",
"pubkey",
"signature",
"topic",
"result"
],
"properties": {
"rpc_id": {
"type": "string",
"description": "The unique identifier of the RPC call, corresponding to the original call."
},
"method_name": {
"type": "string",
"description": "The name of the method being returned."
},
"params": {
"type": "object",
"description": "The parameters of the original method in JSON format."
},
"pubkey": {
"type": "string",
"description": "The public key of the RPC server."
},
"signature": {
"type": "string",
"description": "Signature of rpc_id + method_name + params + result, signed with the server's private key."
},
"topic": {
"type": "string",
"description": "The topic to identify the return message."
},
"result": {
"type": "object",
"description": "The result of the RPC call in JSON format."
}
},
"example": {
"rpc_id": "12345",
"method_name": "get_data",
"params": { "key": "value" },
"pubkey": "server_pubkey",
"signature": "signed_result_data",
"topic": "my_topic",
"result": { "data": "returned_value" }
}
},
"RPCKill": {
"type": "object",
"required": [
"rpc_id",
"signature"
],
"properties": {
"rpc_id": {
"type": "string",
"description": "The unique identifier of the RPC call to stop."
},
"signature": {
"type": "string",
"description": "The signature of the rpc_id, signed by the caller."
}
},
"example": {
"rpc_id": "12345",
"signature": "signed_rpc_id"
}
}
}
}
}
```