added apibuilder/validators endpoint to linter
nclazz/api-cli/pipeline/head There was a failure building this commit
Details
nclazz/api-cli/pipeline/head There was a failure building this commit
Details
parent
017130ecac
commit
dfa73d1256
|
@ -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)
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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": {}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue