2.6.0 • Published 6 years ago

generate-schema v2.6.0

Weekly downloads
27,870
License
MIT
Repository
github
Last release
6 years ago

Generate Schemas

Convert JSON Objects to MySQL Table Schema, JSON Schema, Mongoose Schema, ClickHouse Schema, Google BigQuery, or a Generic template for documentation, code generation, and more.

Build Status version License Downloads

Table of Contents

Installation

Install with npm:

$ npm i --save generate-schema

Optionally, add -g to the above if you want the generate-schema command line executable.

CLI

  Usage: generate-schema [options ...] [file]

  Common Options:

    -h, --help         output usage information
    -V, --version      output the version number
    -q, --quiet        Skip help message in program output

  Mode Options:
    -g, --generic      Generic JSON Primitives schema output
    -j, --json-schema  JSON Schema output
    -s, --mysql        MySQL Table Schema output
    -m, --mongoose     Mongoose Schema output
    -b, --big-query    Google BigQuery Schema output
    -c, --clickhouse   Clickhouse Table Schema output

REPL Mode

When no file is specified, generate-schema enters a REPL mode.

Example

$ generate-schema -b
generate-schema v2.5.1 (bigquery)
Type "exit" to quit.
Type {a:"b"} to see an example.
> {a:"b"}
[
  {
    "name": "a",
    "type": "STRING",
    "mode": "NULLABLE"
  }
]

Usage

var GenerateSchema = require('generate-schema')

Example

// Capture Schema Output
var schema = GenerateSchema.json('Product', [
    {
        "id": 2,
        "name": "An ice sculpture",
        "price": 12.50,
        "tags": ["cold", "ice"],
        "dimensions": {
            "length": 7.0,
            "width": 12.0,
            "height": 9.5
        },
        "warehouseLocation": {
            "latitude": -78.75,
            "longitude": 20.4
        }
    },
    {
        "id": 3,
        "name": "A blue mouse",
        "price": 25.50,
        "dimensions": {
            "length": 3.1,
            "width": 1.0,
            "height": 1.0
        },
        "warehouseLocation": {
            "latitude": 54.4,
            "longitude": -32.7
        }
    }
])

Outputs:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "title": "Product Set",
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "id": {
        "type": "number"
      },
      "name": {
        "type": "string"
      },
      "price": {
        "type": "number"
      },
      "tags": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "dimensions": {
        "type": "object",
        "properties": {
          "length": {
            "type": "number"
          },
          "width": {
            "type": "number"
          },
          "height": {
            "type": "number"
          }
        }
      },
      "warehouseLocation": {
        "type": "object",
        "properties": {
          "latitude": {
            "type": "number"
          },
          "longitude": {
            "type": "number"
          }
        }
      }
    },
    "required": [
      "id",
      "name",
      "price",
      "dimensions",
      "warehouseLocation"
    ],
    "title": "Product"
  }
}

Methods

g.generic(Object object)

Generates a generic schema from object. Property types are described using primitives.

g.mysql([String tableName,] Mixed object)

Generates MySQL Table Schema from object.

  • tableName is optional, defaults to generic
  • object must be of type Object or Array

g.json([String title,] Mixed object)

Generates JSON Schema from object.

  • title is optional
  • object must be of type Object or Array

g.mongoose(Object object)

Generates a Mongoose Schema from object.

g.bigquery(Object object)

Generates a Google BigQuery schema from object.

g.clickhouse([String tableName,] Mixed object, String dateField)

Generates ClickHouse Table Schema from object.

  • tableName is optional, defaults to generic
  • object must be of type Object or Array
  • dateField Date field for ENGINE, must be of type Date

License

MIT

json-schema-editor-zapijson-schema-editor-visual-labpeckertestyapidoctdp-datamodeler@pixiebrix/extension@everything-registry/sub-chunk-1731financial-insightsoptic-helpermission.climobiqplexsdk-testeopenapi-schema-types-from-examplespostman-to-openapi-json-extendedmoon-appmoon-app-typesmoon-commonmoon-common-backendmoon-coremoon-fe-pluginsmoon-ui-generatemoon-utilmoon-wanmi-app-taromoon-wanmi-core-taroasyncapi-kafka-generate-docbip-pod-flowbody-json-schema-editorcausal-net.utilscheck-list-app@zhigang1992/firestore-bigquery-change-trackerastjstodotast-to-people-types@asyncapi/java-templateauto-techs@artsdatabanken/lastejobbavantationact-to-perplevue3-json-schema@yued/json-schema-editor-visual@yued/postman-to-openapiynov-expressionjsapib2swaggerapidoc-openapi-3apidoc-openapi-3-1apidoc-swagger-3apidoc-swagger-converteryapi-enyapi-toolsyapi-vendoryapi-verndoryapi-wfasdfartyapi-proyach.open.yapi@trayio/falafel@tuia/mock2yapigulp-json2dtshar-to-swaggerhexcrystal-json-editorhitl-helperhjson2generator-cedrus-api-czar-litegeek-jsonhoomi-auto-yapihoomi-yapijson-to-typescriptjson-schema-visualjson-sdk-wwgjson-schema-react-editorjson-schema-editor-blockjson-schema-editor-hsjson-schema-editor-rcjson-schema-editor-reactjson-schema-editor-starjson-schema-editor-thaontjson-schema-editor-tooljson-schema-editor-visualjson-schema-editor-visual-antd4json-schema-editor-visual-antd4-externalsjson-schema-editor-visual-basedjson-schema-editor-visual-customjson-schema-editor-visual-ideallifejson-schema-editor-visual-v4json-schema-editor-visual-ycjson-schema-editor-vuejson-schema-show-visualjson-schema-to-react-schemajson-schema-editjson-schema-editor-bkclabjson-schema-editor-bkclab-1jupyter-ijavascript-utilskonxtractkongge-tptlastejobbinsomnia-oas-converterinsomnia-openapi-converterlol.tsknife4j-swagger-nodejs2schemajso-clijson-editor-gao
2.6.0

6 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.0

7 years ago

2.3.3

7 years ago

2.3.2

7 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.1.1

9 years ago

2.1.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.1.0

9 years ago

1.0.0

9 years ago