express-json-schema
Adds express res.jsonSchema
method to allow automatic generation of JSON schemas from a JS/JSON files containing @schema @schema tags
Installation
npm install --save express-json-schema
Usage
var app = require('express')(),
expJsonSchema = require('express-json-schema');
app.use(expJsonSchema);
app.get('/', function(req, res){
res.jsonSchema('./examples/person.js');
});
app.listen(8080, function(){
console.log('Example app listening on port 8080');
});
Example person.js
var Person = {
name: '',
jobTitle: '',
telephone: '',
dateOfBirth: '',
address: {
}
};
Example response
{
"name": "Person",
"description": "This is an example Person object marked up with JSON schema tags to allow schema generation",
"properties": {
"name": {
"title": "Name",
"description": "Please enter your full name",
"type": "string",
"maxLength": 30,
"minLength": 1,
"required": true
},
"jobTitle": {
"title": "Job Title",
"type": "string"
},
"telephone": {
"title": "Telephone Number",
"description": "Please enter telephone number including country code",
"type": "string",
"required": true
},
"dateOfBirth": {
"type": "string",
"required": true
},
"address": {
"type": "object"
}
}
}
Supported tags
A list of supported tags can be viewed at jsdoc-to-json-schema
License
ISC License © 2016 John Doherty