sequelize-model-to-json-schema

1.0.1 • Public • Published

sequelize-to-json-schema

standard

Build Status codecov Dependency Status license

Sequelize model generate to json schema.

get started

  • install

    npm install sequelize-model-to-json-schema --save

how to use

  • transform

    • demo

      const s2json = require('sequelize-model-to-json-schema')
      const Project = sequelize.define('Project', {
        title: { type: Sequelize.STRING, comment: 'title' },
        bigint: { type: Sequelize.BIGINT, comment: 'test bigint' },
        number: { type: Sequelize.DOUBLE, comment: 'test double' },
        number_decimal: { type: Sequelize.DECIMAL, comment: 'test decimal' },
        uuid: { type: Sequelize.UUID, comment: 'test uuid' },
        description: { type: Sequelize.TEXT, comment: 'description' }
      })
      const transformModel = s2json.transform(Project)
      <!-- {
      type: 'object',
        properties:
        {
          id: { type: 'integer', format: 'int32', description: undefined },
          title: { type: 'string', maxLength: 255, description: 'title' },
          bigint: { type: 'integer', format: 'int32', description: 'test bigint' },
          number: { type: 'number', format: 'double', description: 'test double' },
          number_decimal: { type: 'number', description: 'test decimal' },
          uuid: { type: 'string', format: 'uuid', description: 'test uuid' },
          description: { type: 'string', description: 'description' },
          createdAt:
          { type: 'string', format: 'date-time', description: undefined },
          updatedAt:
          { type: 'string', format: 'date-time', description: undefined }
        }
      } -->
    • exclude

      const s2json = require('sequelize-model-to-json-schema')
      const Project = sequelize.define('Project', {
        title: { type: Sequelize.STRING, comment: 'title' },
        description: { type: Sequelize.TEXT, comment: 'description' }
      })
      const transformModel = s2json.transform(Project, {
        exclude: ['title']
      })
      <!-- {
        type: 'object',
        properties:
        {
          id: { type: 'integer', format: 'int32', description: undefined },
          description: { type: 'string', description: 'description' },
          createdAt:
            { type: 'string', format: 'date-time', description: undefined },
          updatedAt:
            { type: 'string', format: 'date-time', description: undefined }
        }
      } -->
  • convert

    • string

      const convertStr = {
        test: {
          type: Sequelize.STRING,
          comment: 'test field'
        }
      }
      const convertJson = s2json.convert(convertStr)
      <!-- {
        type: 'object',
        properties: {
          test: { type: 'string', description: 'test field' }
        }
      } -->
    • object

      const convertObj = {
        test: {
          type: Sequelize.JSON(),
          keys: {
            test: {
              type: Sequelize.STRING,
              comment: 'test field'
            }
          }
        }
      }
      const convertJson = s2json.convert(convertObj)
      <!-- {
        type: 'object',
        properties: {
          test: {
            type: 'object',
            properties: {
              test: { type: 'string', description: 'test field' }
            }
          }
        }
      } -->
    • array

      const convertArr = {
        test: {
          type: Sequelize.ARRAY(),
          items: {
            test: {
              type: Sequelize.STRING,
              comment: 'test field'
            }
          }
        }
      }
      const convertJson = s2json.convert(convertArr)
      <!-- {
        type: 'object',
        properties: {
          test: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                test: { type: 'string', description: 'test field' }
              }
            }
          }
        }
      } -->

Package Sidebar

Install

npm i sequelize-model-to-json-schema

Weekly Downloads

31

Version

1.0.1

License

MIT

Unpacked Size

11.7 kB

Total Files

4

Last publish

Collaborators

  • alfieri