Get unlimited public & private packages + package-based permissions with npm Pro.Get started »

openapi-jsonrpc-jsdoc

1.0.3 • Public • Published

openapi-jsonrpc-jsdoc

Install

npm i openapi-jsonrpc-jsdoc --save-dev

Example

Create JSON-RPC Methoc

// api/api-v1.js
/**
  * @description Название API
  * @param {object} parameters - params
  * @param {string} parameters.id - id
  */
module.exports = (parameters) => {
    return parameters.id;
}

Run package

// index.js
const fs = require('fs');
const openapiJSONRpcJSDoc = require('openapi-jsonrpc-jsdoc');
openapiJSONRpcJSDoc({
    api: '/',
    servers: [
        {
            url: '0.0.0.0:8080',
         },
    ],
    packageUrl: './package.json',
    files: './api/*.js',
}).then(data => {
  fs.writeFileSync('openapi.json', JSON.stringify(data, null, 2));  
});
Result
{
  "x-send-defaults": true,
  "openapi": "3.0.0",
  "x-api-id": "json-rpc-example",
  "x-headers": [],
  "x-explorer-enabled": true,
  "x-proxy-enabled": true,
  "x-samples-enabled": true,
  "x-samples-languages": [
    "curl",
    "node",
    "javascript"
  ],
  "info": {
    "version": "1.0.0",
    "title": "project-name",
    "description": "project-description"
  },
  "servers": [
    {
      "url": "0.0.0.0:8080"
    }
  ],
  "paths": {
    "/api/api-v1": {
      "post": {
        "operationId": "api-v1.js",
        "deprecated": false,
        "summary": "/api-v1",
        "description": "Название API",
        "tags": [
          "JSONRPC"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK"
          }
        },
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "method",
                  "id",
                  "jsonrpc",
                  "params"
                ],
                "properties": {
                  "method": {
                    "type": "string",
                    "default": "api-v1",
                    "description": "API method api-v1"
                  },
                  "id": {
                    "type": "integer",
                    "default": 1,
                    "format": "int32",
                    "description": "Request ID"
                  },
                  "jsonrpc": {
                    "type": "string",
                    "default": "2.0",
                    "description": "JSON-RPC Version (2.0)"
                  },
                  "params": {
                    "title": "Parameters",
                    "type": "object",
                    "required": [
                      "id"
                    ],
                    "properties": {
                      "id": {
                        "type": "string",
                        "description": "id"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BasicAuth": {
        "type": "http",
        "scheme": "digest"
      }
    }
  },
  "security": [
    {
      "BasicAuth": []
    }
  ],
  "tags": []
}

Install

npm i openapi-jsonrpc-jsdoc

DownloadsWeekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

12.5 kB

Total Files

9

Last publish

Collaborators

  • avatar