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 = expJsonSchema = ; // add as middlewareapp; // use within route handlerapp; // start the serverapp;
Example person.js
/** * @schema.name Person * @schema.description This is an example Person object marked up with JSON schema tags to allow schema generation */var Person = /** * @schema.title Name * @schema.description Please enter your full name * @schema.type string * @schema.maxLength 30 * @schema.minLength 1 * @schema.required true */ name: '' /** * @schema.title Job Title * @schema.type string */ jobTitle: '' /** * @schema.title Telephone Number * @schema.description Please enter telephone number including country code * @schema.type string * @schema.required true */ telephone: '' /** * @schema.type string * @schema.required true */ dateOfBirth: '' /** * @schema.type object */ 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