Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

abi2oas

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abi2oas - npm Package Compare versions

Comparing version 0.0.12 to 0.1.0

18

index.js

@@ -14,5 +14,16 @@ #!/usr/bin/env node

.description(package.description)
.usage('<config_file_path> <output_file_path>')
.action((config_file, output_file) => {
return OpenAPIGenerator.convert(config_file, output_file);
.usage('<contract_file_path> <output_file_path>')
.option('-C, --config <config_path>', 'Specify path to config.json from current working directory. If other options are also specified, they will override values in file.')
.option('-v, --apiVersion <version>', 'Specify a version for your new API; defaults to 1.0.0.')
.option('-h, --host <host>', 'Specify a hostname for your new OpenAPI; defaults to "localhost:8080"')
.option('-b, --base <base>', 'Specify a base path for your new OpenAPI; defaults to "/" .')
.option('-s, --schemes <schemes...>', 'Specify default schemes as a comma-separated list, no spaces; defaults to "https".', str => str.split(','))
.action((contract_file, output_file, options) => {
let config = {};
if (options.config) config = JSON.parse(fs.readFileSync(options.config));
if (options.apiVersion) config.version = options.apiVersion;
if (options.host) config.host = options.host;
if (options.base) config.basePath = options.base;
if (options.schemes) config.schemes = options.schemes;
return OpenAPIGenerator.convert(contract_file, output_file, config);
})

@@ -23,2 +34,3 @@

' Both paths should be relative to the current working directory.',
' Any options specified in command will override values in a specified config file.',
' For more information about configuration and generation, view the abi2oas homepage on GitHub.'

@@ -25,0 +37,0 @@ ]);

30

OpenAPIGenerator.js

@@ -14,3 +14,2 @@ let fs = require("fs");

/**

@@ -28,12 +27,6 @@ * @class

* */
constructor(config) {
"use strict";
let usingPathArg = typeof config === 'string';
this.config = usingPathArg ? JSON.parse(fs.readFileSync(config)) : config;
let config_path = usingPathArg ? path.dirname(config) : process.cwd();
console.log('config_path in abi2oas: ',config_path);
let contract_path = path.resolve(config_path, this.config.contract);
console.log('resulting contract_path in abi2oas: ',contract_path);
this.contract = JSON.parse(fs.readFileSync(contract_path)); //cs = contract_schema
constructor(contract_path, config={}) {
this.config = typeof config === 'string' ?
JSON.parse(fs.readFileSync(config)) : config;
this.contract = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), contract_path)));
}

@@ -48,3 +41,8 @@

let license = new License("Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0.html");
let info = new Info(this.contract.contractName, this.contract.contractName, license, this.config.version);
let info = new Info(
this.contract.contractName,
this.contract.contractName,
license,
this.config.version || '1.0.0'
);
this.openAPI = new Swagger(info, {

@@ -115,2 +113,3 @@ schemes: this.config.schemes || ["https"],

if(file_path){
// TODO: Add safety check to make sure output directory exists
fs.writeFileSync(file_path, openAPIStr);

@@ -131,3 +130,3 @@ }else{

* */
static convert(config, file_path){
static convert(contract_path, file_path, config={}){
if (isString(config)){

@@ -137,6 +136,9 @@ if (!fs.existsSync(config)) return errorClose(`Specified config file "${config}" does not exist.`)

}
if (!isString(contract_path)) return errorClose(`Specified contract_path was not a string: ${contract_path}`);
if (!isJSONFile(contract_path)) return errorClose(`Specified contract_path is not a valid JSON filename: ${contract_path}`);
if (!fs.existsSync(contract_path)) return errorClose(`Specified contract_path does not point to an existing file: ${contract_path}`);
if (!isString(file_path)) return errorClose("Provided output path was not a string.");
if (!isJSONFile(file_path)) return errorClose(`Specified output file "${file_path}" is not a JSON file.`)
let generator = new OpenAPIGenerator(config);
let generator = new OpenAPIGenerator(contract_path, config);
generator.init();

@@ -143,0 +145,0 @@ generator.process();

{
"name": "abi2oas",
"version": "0.0.12",
"version": "0.1.0",
"description": "Ingests a smart contract's ABI and autogenerates an OpenAPI JSON, ready for Swagger codegen.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -52,8 +52,7 @@ # abi2oas

## Config
The config JSON includes the path to the contract, ethereum options, and swagger options. The path to the contract should be relative to the location of the config file.
The config JSON includes the path to the contract, ethereum options, and swagger options.
```
{
"version": "1.0.0",
"contract": "<path_to_your_contract.json>",
"version": "1.0.0", // optional, "1.0.0" is default
"schemes": ["https"], // optional, ["https"] is default

@@ -101,3 +100,3 @@ "host": "localhost:8080", // optional, "localhost:8080" is default

-[x] User-friendly CLI interaction via commander
-[] Check that the static `convert` method is working when imported to another npm package.
-[x] Check that the static `convert` method is working when imported to another npm package.
-[] Add default definitions for Ethereum primitive types other than address & receipt

@@ -107,4 +106,4 @@ -[] Write tests for a variety of contracts

### Long-Term
-[] Event Support
## Licensing

@@ -111,0 +110,0 @@ abi2oas is developed & maintained by [Eximchain](https://eximchain.com/), released for public use under the Apache-2.0 License.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc