schema-construct
takes in jsonschema and returns a constructor for that model
Last updated 4 years ago by chemdrew .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install schema-construct 
SYNC missed versions from official npm registry.

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
*/

Current Tags

  • 0.1.0                                ...           latest (4 years ago)

1 Versions

  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |