Skip to content

Use your Sequelize models in JSON Schemas or Swagger

License

Notifications You must be signed in to change notification settings

ShaunParsons/sequelize-json-schema

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sequelize-json-schema

NPM Version CircleCI

Use your Sequelize models in JSON Schemas or Swagger

Main use case for this code is to generate models for hand crafted swagger.json.

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command:

$ npm install sequelize-json-schema

Example

let Simple = sequelize.define('simple', {
  title: Sequelize.STRING,
  description: Sequelize.TEXT
});

let def = definition(Simple);

console.log(def);

And result will be:

{
  type: 'object',
  properties: {
    id: {
      type: 'integer',
      format: 'int32'
    },
    title: { type: 'string' },
    description: { type: 'string' },
    createdAt: {
      type: 'string',
      format: 'date-time'
    },
    updatedAt: {
      type: 'string',
      format: 'date-time'
    }
  }
}

Using with Swagger

This tool generates definitions part of the Swagger Manifest. So if you have Swagger definition for your API just extend definitions with JSON generated by this tool.

{
  "swagger": "2.0",
  "info": {
    "title": "API",
    "version": "1.0.0"
  },
  "paths": {
    "simple": {
      "get": {      
        "parameters": [ ],
        "responses": {
          "200": { "$ref": "#/definitions/simple" }
        }
      }
    }
  },
  "definitions": {
    "simple": {
      type: 'object',
      properties: {
        id: {
          type: 'integer',
          format: 'int32'
        },
        title: { type: 'string' },
        description: { type: 'string' },
        createdAt: {
          type: 'string',
          format: 'date-time'
        },
        updatedAt: {
          type: 'string',
          format: 'date-time'
        }
      }
    }
  }
}

LICENSE

MIT License

About

Use your Sequelize models in JSON Schemas or Swagger

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.4%
  • Makefile 2.6%