Skip to content

chemdrew/schema-construct

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 

Repository files navigation

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

About

takes in jsonschema and returns a constructed object for that model

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published