Giter Site home page Giter Site logo

json-schema-tools / referencer Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 1.19 MB

Flatten a JSON Schema by turning its subschemas into refs. The result is a schema which is 'maximally reffed'. The opposite of dereferencing.

Home Page: https://json-schema-tools.github.io/referencer/

License: Apache License 2.0

JavaScript 5.50% TypeScript 94.50%

referencer's Introduction

JSON Schema Referencer

CircleCI branch npm GitHub release GitHub commits since latest release

Referencer is a package that exports a single function - a function that accepts and returns a JSON Schema. The returned schema is 'flat', as in, any subschemas of the schema have been converted into $refs. Further, any of the subschemas' subschema are also $reffed, recurively until everything is a $ref, and the definition section is fully populated.

The input schema may have refs, but the refs must already be in the definitions section. The input schema, as well as all of its subschemas must have titles. Their titles must also be unique for their content. We would like to use $id, but it has special meaning and therefor title is used as the unique identifier on-which schemas will be referenced.

Features:

  • Cyclic schemas become cyclic references
  • Completely synchronous
  • immutable by default, option to mutate in place.
  • No external dependencies
  • Fully typed against the generated meta-schema typings
  • magically makes your json schema smaller.

Usage

install it: npm install @json-schema-tools/referencer

use it:

import referencer from "@json-schema-tools/referencer";

const result = referencer({
  title: "example",
  type: "object",
  properties: {
    foo: { title: "foo", type: "number" },
    bar: { title: "bar", type: "string" }
  }
});

console.log(result);

// outputs
{
  title: "example",
  type: "object",
  properties: {
    foo: {$ref: "#/definitions/foo" },
    bar: { $ref: "#/definitions/bar" }
  },
  definitions: {
    foo: { title: "foo", type: "number" }
    bar: { title: "bar", type: "string" }
  }
}

License

Apache-2.0

Contributing

How to contribute, build and release are outlined in CONTRIBUTING.md, BUILDING.md and RELEASING.md respectively. Commits in this repository follow the CONVENTIONAL_COMMITS.md specification.

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.