apidoc-plugin-schema
Advanced tools
Comparing version
46
index.js
@@ -1,36 +0,34 @@ | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
var elementParser = require('./parser/api_schema'); | ||
var schemas = { | ||
const elementParser = require('./parser/api_schema'); | ||
const schemas = { | ||
'jsonschema': require('./schema/jsonschema') | ||
}; | ||
var app = {}; | ||
let app = {}; | ||
module.exports = { | ||
init: function(_app) { | ||
app = _app; | ||
app.addHook('parser-find-elements', parserSchemaElements); | ||
} | ||
init: function(_app) { | ||
app = _app; | ||
app.addHook('parser-find-elements', parserSchemaElements, 200); | ||
} | ||
}; | ||
function parserSchemaElements(elements, element, block, filename) { | ||
if ( element.name === 'apischema' ) { | ||
elements.pop(); | ||
if ( element.name !== 'apischema' ) { return elements; } | ||
elements.pop(); | ||
var values = elementParser.parse(element.content, element.source); | ||
app.log.debug('apischema.path',values.path); | ||
if (schemas[values.schema]) { | ||
var relativePath=path.join(path.dirname(filename), values.path); | ||
var data = fs.readFileSync(relativePath, 'utf8').toString(); | ||
var new_elements = schemas[values.schema](relativePath, data, values.element, values.group); | ||
const values = elementParser.parse(element.content, element.source); | ||
app.log.debug('apischema.path',values.path); | ||
if (schemas[values.schema]) { | ||
const data = fs.readFileSync( path.join(path.dirname(filename), values.path), 'utf8').toString(); | ||
const new_elements = schemas[values.schema](data, values.element, values.group); | ||
// do not use concat | ||
for(var i = 0,l=new_elements.length; i<l;i++) { | ||
elements.push(new_elements[i]); | ||
} | ||
// do not use concat | ||
for(let i = 0,l=new_elements.length; i<l;i++) { | ||
elements.push(new_elements[i]); | ||
} | ||
} | ||
return elements; | ||
} | ||
return elements; | ||
} |
{ | ||
"name":"apidoc-plugin-schema", | ||
"version":"0.1.3", | ||
"version":"0.1.4", | ||
"description": "Schema Plugin for apidoc.", | ||
@@ -5,0 +5,0 @@ "copyright": "Copyright (c) 2016 will Farrell. All rights reserved.", |
@@ -31,2 +31,5 @@ # apidoc-plugin-schema | ||
## Developer Note | ||
This plugin uses `parser-find-elements` @ priority `201`. | ||
## TODO | ||
@@ -33,0 +36,0 @@ - Add in unit test for jsonschema |
@@ -98,16 +98,16 @@ | ||
param.enum = param.enum.map((item) => { | ||
if (typeof item === 'string') { | ||
values.push('"'+item+'"'); // ensures values with spaces render properly | ||
} else if (item === null) { | ||
// required to be at beginning | ||
values.unshift('null'); | ||
} else if (item === true) { | ||
// required to be at beginning | ||
values.unshift('true'); | ||
} else if (item === false) { | ||
// required to be at beginning | ||
values.unshift('false'); | ||
} | ||
return item; | ||
}); | ||
if (typeof item === 'string') { | ||
values.push('"'+item+'"'); // ensures values with spaces render properly | ||
} else if (item === null) { | ||
// required to be at beginning | ||
values.unshift('null'); | ||
} else if (item === true) { | ||
// required to be at beginning | ||
values.unshift('true'); | ||
} else if (item === false) { | ||
// required to be at beginning | ||
values.unshift('false'); | ||
} | ||
return item; | ||
}); | ||
@@ -114,0 +114,0 @@ return '='+values.join(','); |
11061
0.25%44
7.32%265
-0.75%