npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lenra/json-schema-unifier

v1.1.0

Published

<div id="top"></div> <!-- *** This README was created with https://github.com/othneildrew/Best-README-Template -->

Downloads

16

Readme

Contributors Forks Stargazers Issues MIT License

Usage

To unify many JSON Schema files into a single file, create a main JSON Schema file that correspond to the main element to check and has $ref to the other ones.

// person.schema.json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/person.schema.json",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    },
    "address": {
      "$ref": "address.schema.json"
    }
  }
}

Create the referenced files:

// address.schema.json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/address.schema.json",
  "title": "Address",
  "type": "object",
  "properties": {
    "streetAddress": {
      "type": "string"
    },
    "city": {
      "type": "string"
    },
    "state": {
      "type": "string"
    },
    "country": {
      "type": "string"
    }
  },
  "required": ["streetAddress", "city", "state", "country"]
}

The references are resolved recursively and the result is a single file with all the definitions.

// unified.schema.json
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://example.com/person.schema.json",
  "title": "Person",
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "lastName": {
      "type": "string",
      "description": "The person's last name."
    },
    "age": {
      "description": "Age in years which must be equal to or greater than zero.",
      "type": "integer",
      "minimum": 0
    },
    "address": {
      "$ref": "#/definitions/address"
    }
  },
  "definitions": {
    "address": {
      "title": "Address",
      "type": "object",
      "properties": {
        "streetAddress": {
          "type": "string"
        },
        "city": {
          "type": "string"
        },
        "state": {
          "type": "string"
        },
        "country": {
          "type": "string"
        }
      },
      "required": ["streetAddress", "city", "state", "country"]
    }
  }
}

as a CLI

To use the CLI, install the package globally:

npm install -g @lenra/json-schema-unifier

Then run the command:

json-schema-unifier person.schema.json

By default, the output is printed to the console. To save it to a file, use the --output option:

json-schema-unifier person.schema.json --output unified.schema.json

You also can specify the output format with the --format option. The available formats are json and yaml:

json-schema-unifier person.schema.json --format yaml

A --verbose option is also available to print the logs to the console.

as a Library

To use the library, install it as a dependency:

npm install @lenra/json-schema-unifier

Then import it in your code:

import { JsonSchemaUnifier } from '@lenra/json-schema-unifier';

const result = JsonSchemaUnifier.unify('person.schema.json');

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please open an issue with the tag "enhancement". Don't forget to give the project a star if you liked it! Thanks again!

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Lenra - @lenra_dev - [email protected]

Project Link: https://github.com/lenra-io/json-schema-unifier