1.0.14 ā€¢ Published 8 months ago

open-rpc-compiler v1.0.14

Weekly downloads
-
License
ISC
Repository
github
Last release
8 months ago

Overview

Organize OpenRPC doc into files and directories and compile a complete OpenRPC document.

Directory structure

šŸ“‚ openrpc/  
ā”œā”€ā”€ šŸ“‚ components/  
|   ā””ā”€ā”€ā”€ šŸ“‚ schemas/  
ā”‚        ā””ā”€ā”€ā”€ šŸ“„ jointPosition.json  
ā”‚ā”€ā”€ā”€šŸ“„ info.json  
ā””ā”€ā”€ā”€šŸ“‚ methods/  
    ā””ā”€ā”€ šŸ“‚ tags/  
         ā””ā”€ā”€ šŸ“‚ motion/  
              ā””ā”€ā”€ šŸ“„ getJointPosition.json  

Example Info file

./info.json

{
    "version": "0.1.0",
    "title": "Motion Controller API"
}

Example Schema File

./components/schemas/jointPosition.json

{
    "type": "object",
    "properties": {
        "jointIndex": {
            "type": "integer"
        },
        "position": {
            "type": "integer"
        }
    }
}

Example Method File

Note, by placing a method file inside a tags subdirectory, the name of the subdirectory will be assigned as a tag for the method.

./methods/tags/motion/getJointPosition.json

{
    "name": "getPosition",
    "description": "Get current joint positions",
    "params": [],
    "result": {
        "name": "jointPositions",
        "description": "updated joint positions",
        "schema": {
            "type": "array",
            "items": {
                "$ref": "#components/schemas/jointPosition"
            }
        }
    },
    "examples": [
        {
            "name": "getPosition",
            "params": [],
            "result": {
                "name": "jointPositions",
                "value": [
                    {
                        "jointIndex": 1,
                        "position": 393
                    },
                    {
                        "jointIndex": 5,
                        "position": 1829
                    }
                ]
            }
        }
    ]
}

Install

npm install open-rpc-compiler --no-save

Compile into a single openrpc.json document

open-rpc-compile > openrpc.json

Example Output

{
  "openrpc": "1.2.4",
  "info": {
    "version": "0.1.0",
    "title": "Motion Controller API"
  },
  "methods": [
    {
      "name": "getPosition",
      "description": "Get current joint positions",
      "params": [],
      "result": {
        "name": "jointPositions",
        "description": "updated joint positions",
        "schema": {
          "type": "array",
          "items": {
            "$ref": "#components/schemas/jointPosition"
          }
        }
      },
      "examples": [
        {
          "name": "getPosition",
          "params": [],
          "result": {
            "name": "jointPositions",
            "value": [
              {
                "jointIndex": 1,
                "position": 393
              },
              {
                "jointIndex": 5,
                "position": 1829
              }
            ]
          }
        }
      ],
      "tags": [
        {
          "name": "motion"
        }
      ]
    },
  ],
  "components": {
    "schemas": {
      "jointPosition": {
        "type": "object",
        "properties": {
          "jointIndex": {
            "type": "integer"
          },
          "position": {
            "type": "integer"
          }
        }
      }
    }
  }
}
1.0.14

8 months ago

1.0.13

8 months ago

1.0.12

8 months ago

1.0.11

8 months ago

1.0.10

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago