diff --git a/src/cmd/cmd.lint.js b/src/cmd/cmd.lint.js index fc6eac2..02ff13d 100644 --- a/src/cmd/cmd.lint.js +++ b/src/cmd/cmd.lint.js @@ -2,13 +2,13 @@ const linter = require('../linter') const path = require('path') module.exports = { - run(args) { + async run(args) { if(!args.spec) { throw 'No spec provided!' } let spec = require(path.resolve(process.cwd(), args.spec)) - let result = linter.lint(spec) + let result = await linter.lint(spec) if(!result.success) { console.error('Errors while linting!') process.exit(-1) diff --git a/src/linter.js b/src/linter.js index f0c5b0b..9a5300b 100644 --- a/src/linter.js +++ b/src/linter.js @@ -37,10 +37,14 @@ function regex(regex) { } async function validateOnApiBuilder(spec) { - let res = await axios.post(`${apibuilder_baseurl}/validations`, { - data: spec - }) - console.log(res) + try { + let res = await axios.post(`${apibuilder_baseurl}/validations`, spec) + return res.data + }catch(err) { + return err.response.data + } + + } const linterMappings = [ @@ -64,10 +68,17 @@ const linterMappings = [ module.exports.validate = validateOnApiBuilder -module.exports.lint = function(spec) { +module.exports.lint = async function(spec) { let results = { success: true } + + let apibuilder_result = await validateOnApiBuilder(spec) + if(!apibuilder_result) { + results.success = false + results.apibuilder = apibuilder_result.errors + apibuilder_result.errors.forEach(console.error) + } linterMappings.forEach(element => { let value = objectPath.get(spec, element.path); element.linters.forEach(linter => { diff --git a/templates/default.json b/templates/default.json index e339a74..b0439de 100644 --- a/templates/default.json +++ b/templates/default.json @@ -1,6 +1,8 @@ { - "name": "", - "description": "", + "apidoc": { + }, + "name": "service", + "description": "description", "info": {}, "imports": [], "headers": [], @@ -18,18 +20,19 @@ "resources": { "healthcheck": { "path": "/_internal_/healthcheck", - "operations": { - "method": "GET", - "path": "/healthcheck", - "description": "Simple healthcheck endpoint to test the status of the service.", - "responses": { - "200": { "type": "healthcheck", "description": "Get the current health status of the service." } + "operations": [ + { + "method": "GET", + "path": "/healthcheck", + "description": "Simple healthcheck endpoint to test the status of the service.", + "responses": { + "200": { "type": "healthcheck", "description": "Get the current health status of the service." } + } } - } + ] + } }, - "attributes": {}, - "annotations": { - - } + "attributes": [], + "annotations": {} } diff --git a/tests/lint.test.js b/tests/lint.test.js index 621fc24..6710e59 100644 --- a/tests/lint.test.js +++ b/tests/lint.test.js @@ -52,8 +52,9 @@ describe('linter for spec', () => { }) }) -describe('apibuilder validator', () => { - it('validates the spec', () => { - linter.validate(require('../templates/default.json')) +describe('apibuilder validator', async () => { + await it('validates the spec', async () => { + let result = await linter.validate(require('../templates/default.json')) + expect(result.valid).to.be.true }) }) \ No newline at end of file