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.4 to 0.0.5

util.js

16

api_units/Entity.js

@@ -82,12 +82,10 @@ let Path = require("./Path");

addMethodsToPath(){
if(this.entity.inputs.length){
let method = this.path.addMethod("post", this.entity.inputs, this);
this.addResponsesToMethod(method);
this.addTagsToMethod(method);
let method;
if (this.entity.constant){
method = this.path.addMethod("get", this.entity.inputs, this);
} else {
method = this.path.addMethod("post", this.entity.inputs, this);
}
if(this.entity.outputs.length) {
let get_method = this.path.addMethod("get", this.entity.inputs, this);
this.addResponsesToMethod(get_method);
this.addTagsToMethod(get_method);
}
this.addResponsesToMethod(method);
this.addTagsToMethod(method);
}

@@ -94,0 +92,0 @@

@@ -8,15 +8,6 @@ #!/usr/bin/env node

const isString = thing => typeof thing === 'string';
const isJSONFile = thing => path.extname(thing).toLowerCase() === '.json';
const isWritable = dirname => fs.access(dirname, fs.constants.W_OK, err => !!err )
const errorClose = (msg) => {
let errorMsg = `Error: ${msg} Run "abi2oas --help" to see command syntax.`
console.log("");
console.error(errorMsg);
console.log("");
return new Error(errorMsg);
}
const { errorClose } = require('./util');
program
.version('0.0.4')
.version('0.0.5')
.name('abi2oas')

@@ -26,9 +17,3 @@ .description("Autogenerate an Open API JSON corresponding to the functions in a smart contract's ABI. \n Call with the paths to your config file and your desired OpenAPI output file.")

.action((config_file, output_file) => {
if (!fs.existsSync(config_file)) return errorClose(`Specified config file "${config_file}" does not exist.`)
if (!isJSONFile(config_file)) return errorClose(`Specified config file "${config_file}" is not a JSON file.`)
if (!isJSONFile(output_file)) return errorClose(`Specified output file "${output_file}" is not a JSON file.`)
if (!isWritable(path.dirname(output_file))) return errorClose(`Specified output directory "${path.dirname(output_file)}" is not writable.`)
let generatedAPI = OpenAPIGenerator.convert(config_file, output_file);
console.log(`Completed generating OpenAPI JSON for ${generatedAPI.info.title}, output is in ${output_file}.`);
return OpenAPIGenerator.convert(config_file, output_file);
})

@@ -43,5 +28,7 @@

if (require.main === module) {
program.parse(process.argv)
let args = process.argv;
if (args.length-1 !== 2) return errorClose(`abi2oas requires 2 arguments, not ${args.length - 1}.`)
program.parse(args);
} else {
module.exports = OpenAPIGenerator;
}

@@ -12,3 +12,5 @@ let fs = require("fs");

const { isJSONFile, isWritable, isString, errorClose } = require('./util');
/**

@@ -62,2 +64,3 @@ * @class

]));
/*

@@ -124,2 +127,9 @@ transaction receipt schema...

static convert(config, file_path){
if (isString(config)){
if (!fs.existsSync(config)) return errorClose(`Specified config file "${config}" does not exist.`)
if (!isJSONFile(config)) return errorClose(`Specified config file "${config}" is not a JSON file.`)
}
if (!isJSONFile(file_path)) return errorClose(`Specified output file "${file_path}" is not a JSON file.`)
if (!isWritable(path.dirname(file_path))) return errorClose(`Specified output directory "${path.dirname(file_path)}" is not writable.`)
let generator = new OpenAPIGenerator(config);

@@ -126,0 +136,0 @@ generator.init();

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

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

@@ -47,3 +47,3 @@ # abi2oas

- Each function's name becomes an API path (e.g. `whitelistAddress` function yields `/whitelistAddress` path). If the function accepts inputs, then its path can accept POST requests. If the function also returns outputs, then its path also accepts GET requests.
- Each function's name becomes an API path (e.g. `whitelistAddress` function yields `/whitelistAddress` path). If the function is `constant`, then its path accepts GET requests. Otherwise, it accepts POST requests.
- A tag is automatically generated for each function, representing its dynamic scope (e.g. a `whitelistAddressScope` tag). All methods for each function automatically have its tag, along with any other custom tags specified in the config.

@@ -100,5 +100,6 @@ - Definitions are automatically generated for each function-method's params and response (e.g. `whitelistAddress_post_params` & `whitelistAddress_post_params_response`), as well as definitions for receipts and basic types.

-[] Check that the static `convert` method is working when imported to another npm package.
-[] Fix autogen to use GET or POST based on whether the function is `constant`, not whether it has inputs or outputs.
-[x] Fix autogen to use GET or POST based on whether the function is `constant`, not whether it has inputs or outputs.
-[] Add default definitions for Ethereum primitive types other than address & receipt
-[] User-friendly CLI interaction via commander
-[] Write tests
-[] Write tests for a variety of contracts

@@ -105,0 +106,0 @@ ### Long-Term

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