Git Product home page Git Product logo

generalize-cli's Introduction

generalize

npm version

Install:

npm install -g generalize-cli

Example

Suppose you want a schema for the NPM downloads API range results:

$ curl -s https://api.npmjs.org/downloads/range/last-week/npm
{
  "downloads": [
    {
      "day": "2015-05-21",
      "downloads": 136536
    },
    {
      "day": "2015-05-22",
      "downloads": 140254
    },
    {
      "day": "2015-05-23",
      "downloads": 95945
    },
    {
      "day": "2015-05-24",
      "downloads": 88592
    },
    {
      "day": "2015-05-25",
      "downloads": 115167
    },
    {
      "day": "2015-05-26",
      "downloads": 127149
    },
    {
      "day": "2015-05-27",
      "downloads": 131255
    }
  ],
  "start": "2015-05-21",
  "end": "2015-05-27",
  "package": "npm"
}

Run generalize on it!

$ curl -s https://api.npmjs.org/downloads/range/last-week/npm | generalize | jq .
[
  {
    "type": "object",
    "properties": {
      "downloads": [
        {
          "type": "array",
          "items": [
            {
              "type": "object",
              "properties": {
                "day": [
                  {
                    "type": "string"
                  }
                ],
                "downloads": [
                  {
                    "type": "number"
                  }
                ]
              }
            }
          ]
        }
      ],
      "start": [
        {
          "type": "string"
        }
      ],
      "end": [
        {
          "type": "string"
        }
      ],
      "package": [
        {
          "type": "string"
        }
      ]
    }
  }
]

In the current output, instead of proper JSON schema anyOf types, generalize uses arrays. If an array of schemas is 1-long, the array can be collapsed to just the single entry.

TODO

  • Proper JSON output
  • Optionality recognition

License

Copyright 2015 Christopher Brown. MIT Licensed.

generalize-cli's People

Contributors

chbrown avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.