Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Raisel Melian committed Jan 12, 2019
0 parents commit 88a58f6
Show file tree
Hide file tree
Showing 13 changed files with 1,767 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/.circleci
/.git
/.github
/*.md
/Dockerfile
/docs
/.dockerignore
/.editorconfig
/.eslintrc.json
/.gitignore
/test

9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
187 changes: 187 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
{
"env": {
"es6": true,
"node": true
},
"extends": "eslint:recommended",
"rules": {
"accessor-pairs": "error",
"array-bracket-spacing": [
"error",
"never"
],
"array-callback-return": "error",
"arrow-body-style": "error",
"arrow-parens": [
"error",
"as-needed"
],
"arrow-spacing": [
"error",
{
"after": true,
"before": true
}
],
"block-spacing": "error",
"brace-style": [
"error",
"stroustrup"
],
"camelcase": "error",
"class-methods-use-this": "error",
"comma-style": [
"error",
"last"
],
"computed-property-spacing": [
"error",
"never"
],
"consistent-this": "error",
"default-case": "error",
"dot-location": [
"error",
"property"
],
"dot-notation": [
"error",
{
"allowKeywords": true
}
],
"eol-last": "error",
"func-call-spacing": "error",
"id-blacklist": "error",
"id-match": "error",
"jsx-quotes": "error",
"linebreak-style": [
"error",
"unix"
],
"lines-around-comment": "error",
"lines-around-directive": "error",
"max-nested-callbacks": "error",
"max-statements-per-line": "error",
"multiline-ternary": [
"error",
"never"
],
"new-parens": "error",
"no-alert": "error",
"no-array-constructor": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-confusing-arrow": "error",
"no-console": "off",
"no-div-regex": "error",
"no-duplicate-imports": "error",
"no-empty": [
"error",
{
"allowEmptyCatch": true
}
],
"no-eq-null": "error",
"no-eval": "error",
"no-extra-bind": "error",
"no-extra-label": "error",
"no-floating-decimal": "error",
"no-global-assign": "error",
"no-implicit-globals": "error",
"no-implied-eval": "error",
"no-inner-declarations": [
"error",
"functions"
],
"no-invalid-this": "error",
"no-iterator": "error",
"no-label-var": "error",
"no-labels": "error",
"no-lone-blocks": "error",
"no-mixed-operators": "error",
"no-mixed-requires": "error",
"no-multi-spaces": "error",
"no-multi-str": "error",
"no-multiple-empty-lines": "error",
"no-negated-condition": "error",
"no-new": "error",
"no-new-func": "error",
"no-new-object": "error",
"no-new-require": "error",
"no-new-wrappers": "error",
"no-octal-escape": "error",
"no-path-concat": "error",
"no-proto": "error",
"no-prototype-builtins": "error",
"no-restricted-globals": "error",
"no-restricted-imports": "error",
"no-restricted-modules": "error",
"no-restricted-properties": "error",
"no-restricted-syntax": "error",
"no-script-url": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-shadow-restricted-names": "error",
"no-spaced-func": "error",
"no-template-curly-in-string": "error",
"no-throw-literal": "error",
"no-trailing-spaces": "error",
"no-undef-init": "error",
"no-undefined": "error",
"no-underscore-dangle": "error",
"no-unmodified-loop-condition": "error",
"no-unneeded-ternary": [
"error",
{
"defaultAssignment": true
}
],
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-unused-vars": "warn",
"no-useless-call": "error",
"no-useless-computed-key": "error",
"no-useless-concat": "error",
"no-useless-constructor": "error",
"no-useless-escape": "error",
"no-useless-rename": "error",
"no-void": "error",
"no-whitespace-before-property": "error",
"no-with": "error",
"object-curly-newline": "error",
"object-property-newline": [
"error",
{
"allowMultiplePropertiesPerLine": true
}
],
"one-var-declaration-per-line": "error",
"prefer-numeric-literals": "error",
"prefer-rest-params": "error",
"prefer-spread": "error",
"radix": "error",
"rest-spread-spacing": "error",
"semi-spacing": "error",
"sort-imports": "error",
"sort-vars": "error",
"space-in-parens": [
"error",
"never"
],
"space-unary-ops": "error",
"strict": "error",
"symbol-description": "error",
"template-curly-spacing": "error",
"unicode-bom": [
"error",
"never"
],
"wrap-iife": "error",
"yield-star-spacing": "error",
"yoda": [
"error",
"never"
]
}
}
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
build.sh
.coveralls.yml
.node-version
.nyc_output
yarn.lock
resolved.yaml

# Logs
logs
*.log
npm-debug.log*

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history
31 changes: 31 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env node

// @ts-check

'use strict';

const program = require('commander');
const { version } = require('./package.json');
const validate = require('./validate');

function collect(val, item) {
item.push(val);
return item;
}

program
.version(version)
.usage('<command>')
.option('-c, --config [configFile]', 'config file (containing JSON/YAML). See README for potential values.');

program
.command('validate <file-or-url>')
.description('validate Async-API documents')
.action(validate.command);


program.parse(process.argv);

if (!process.argv.slice(2).length) {
program.help();
}
7 changes: 7 additions & 0 deletions lib/linter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict';
const parse = require('./parser');

const lint = specFile => new Promise((resolve, reject) => {
});

module.exports = {lint};
105 changes: 105 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
const fs = require('fs');
const path = require('path');
const ZSchema = require('z-schema');
const YAML = require('js-yaml');
const RefParser = require('json-schema-ref-parser');

const validator = new ZSchema();

async function getFileContent (filePath) {
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(__dirname, filePath), (err, content) => {
if (err) return reject(err);
resolve(content);
});
});
}

function parseContent (content) {
content = content.toString('utf8');
try {
return JSON.parse(content);
} catch (e) {
return YAML.safeLoad(content);
}
}

async function dereference (json) {
return RefParser.dereference(json, {
dereference: {
circular: 'ignore'
}
});
}

async function bundle (json) {
return RefParser.bundle(json, {
dereference: {
circular: 'ignore'
}
});
}

async function validate (json, schema) {
return new Promise((resolve, reject) => {
validator.validate(json, schema, (err, valid) => {
if (err) return reject(err);
return resolve(json);
});
});
}

async function parse (filePath) {
let content, parsedContent, dereferencedJSON, bundledJSON, parsed;

try {
if (typeof filePath === 'string') {
content = await getFileContent(filePath);
} else if (typeof filePath === 'object') {
content = JSON.stringify(filePath);
} else {
// console.error(`Could not find a valid asyncapi definition: ${filePath}`);
throw `Could not find a valid asyncapi definition: ${filePath}`;
}
} catch (e) {
// console.error('Can not load the content of the AsyncAPI specification file');
throw e;
}

try {
parsedContent = parseContent(content);
} catch (e) {
console.error('Can not parse the content of the AsyncAPI specification file');
// console.error(e);
throw e;
}

try {
dereferencedJSON = await dereference(parsedContent);
} catch (e) {
console.error('Can not dereference the JSON obtained from the content of the AsyncAPI specification file');
// console.error(e);
throw e;
}

try {
bundledJSON = await bundle(dereferencedJSON);
} catch (e) {
console.error('Can not bundle the JSON obtained from the content of the AsyncAPI specification file');
// console.error(e);
throw e;
}

try {
const asyncAPIschema = require('asyncapi')[bundledJSON.asyncapi];
parsed = await validate(bundledJSON, asyncAPIschema);
} catch (e) {
console.error('Invalid JSON obtained from the content of the AsyncAPI specification file');
// console.error(e);
throw e;
}

return JSON.parse(JSON.stringify(parsed));
};

module.exports = parse;
Loading

0 comments on commit 88a58f6

Please sign in to comment.