Package detail

alterschema

sourcemeta118.9kApache-2.01.1.3

Convert between schema specifications

json, json-schema, jsonschema, openapi

readme

alterschema

This project implements a language-independent set of formal transformations to automatically transform JSON Schema documents across versions of the specification.

Try the web playground at: https://alterschema.sourcemeta.com

Coverage

From To Type Status Description
2019-09 2020-12 Lossless Full JSON Schema 2019-09 to JSON Schema 2020-12
draft7 2019-09 Lossless Full JSON Schema Draft 7 to JSON Schema 2019-09
draft6 draft7 Lossless Full JSON Schema Draft 6 to JSON Schema Draft 7
draft4 draft6 Lossless Full JSON Schema Draft 4 to JSON Schema Draft 6
draft3 draft4 Lossless Minimal [^1] JSON Schema Draft 3 to JSON Schema Draft 4

[^1]: This is a heavy work-in-progress. Subscribe to https://github.com/sourcemeta/alterschema/issues/83 for the latest updates.

Transformations are transitively applied. For example, transforming from draft6 to 2019-09 implies transforming draft6 to draft7 and draft7 to 2019-09.

Bindings

JavaScript

// (1) Install by running "npm install --save alterschema"
const alterschema = require('alterschema')

// (2) alterschema(schema: JSON, from: string, to: string) -> JSON
// Transform the input document `schema` according to the
// `from` and `to` string parameters.
const result = await alterschema({ ... }, '2019-09', '2020-12')

console.log(result)

Command-line tool

# (1) Install globally through npm
npm install --global alterschema
# (2) Run the command-line tool
alterschema --from <from> --to <to> path/to/schema.json

Others

We accept contributions to implement alterschema in any programming language. To produce an alterschema implementation, your programming language of choice must support a JSON Schema 2020-12 validator and a JSON-e interpreter.

Acknowledgements

Special thanks to @gregdeniss for curating the initial set of upgrade rules.

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

1.1.3 - 2023-03-29

Changed

  • Upgrade @hyperjump/json-schema to 0.23.5 to fix undeclared subdependency proble.

1.1.2 - 2023-02-03

Changed

  • Pin @hyperjump/json-schema to 0.23.2 to fix TypeScript problems

1.1.1 - 2022-08-24

Changed

  • Fix additionalItems not being transformed to items in $ref
  • Fix items not being transformed to prefixItems in $ref

1.1.0 - 2022-08-23

Added

  • Add support for upgrading $recursiveRef and $recursiveAnchor to $dynamicRef and $dynamicAnchor

1.0.6 - 2022-08-15

Changed

  • Correctly replace dependencies to dependentRequired
  • Fix sub-schema walking not working correctly in certain structural transformations

1.0.5 - 2022-08-15

Changed

  • Upgrade @hyperjump/json-schema to fix rimraf issue when installing alterschema with sudo

1.0.4 - 2022-08-10

Changed

  • Fix definitions not being upgraded to $defs in $ref JSON Pointers

1.0.3 - 2022-08-05

Changed

  • Fix enum being always casted to const

1.0.2 - 2022-08-01

Changed

  • Fix Node.js CLI entrypoint

1.0.1 - 2022-08-01

Changed

  • Improve "from" and "to" argument validation

1.0.0 - 2022-08-01

Added

  • Full JSON Schema draft4 to JSON Schema draft6 upgrade support
  • Full JSON Schema draft6 to JSON Schema draft7 upgrade support
  • Full JSON Schema draft7 to JSON Schema 2019-09 upgrade support

0.0.1 - 2022-07-01

Added

  • Partial JSON Schema 2019-09 to JSON Schema 2020-12 upgrade support