0.1.0 • Published 8 years ago

schema-construct v0.1.0

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

here is how you use it

works great for swagger - kinda the point of it

###model class

var schemaConstruct = require('schema-construct');

var error = schemaConstruct({
  type: 'object',
  properties: {
    code: {
      type: 'string'
    },
    message: {
      type: 'string'
    },
    stack: {
      type: 'string'
    }
  },
  additionalProperties: false
});

error.prototype.toXml = function() {
  // whatever you wanna do to make this happen
}

module.exports = error;

###something that uses that model

var Error = require('./models/error');
var error = new Error();

console.log(error);
/*
{
  code: null,
  message: null,
  stack: null
}
*/

console.log(error.schema);
/*
{
  type: 'object',
  properties: {
    code: {
      type: 'string'
    },
    message: {
      type: 'string'
    },
    stack: {
      type: 'string'
    }
  },
  additionalProperties: false
}
*/

console.log(error.toXml());
/*
  hopefully whatever you did to make this xml worked lol
*/