JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 68592
  • Score
    100M100P100Q151602F
  • License Apache-2.0

Converts a RAML data type into JSON schema, and back

Package Exports

  • ramldt2jsonschema

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ramldt2jsonschema) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

ramldt2jsonschema

NPM version NPM downloads Build status Test coverage

This repository contains a node implementation that converts a RAML data type into JSON schema, and back.

Usage

Global (CLI)

npm install -g ramldt2jsonschema

This will install two command-line tools:

  • dt2js: RAML data type <> JSON schema
  • js2dt: JSON schema <> RAML data type

dt2js

dt2js <ramlFile> <ramlTypeName>

Options

  • <ramlFile> Path to a file containing at least one RAML data type (e.g. path/to/api.raml)
  • <ramlTypeName> RAML type name to convert to JSON schema

js2dt

js2dt <jsonFile> <ramlTypeName>

Options

  • <jsonFile> Path to a JSON schema file (e.g. path/to/schema.json)
  • <ramlTypeName> RAML type name to give to the exported RAML data type

Locally (JavaScript)

npm install ramldt2jsonschema --save

dt2js

var raml2json = require('ramldt2jsonschema')
var join = require('path').join
var fs = require('fs')

var filePath = join(__dirname, 'api.raml')
var ramlData = fs.readFileSync(filePath).toString()

raml2json.dt2js(ramlData, 'Cat', function (err, schema) {
  if (err) {
    console.log(err)
    return
  }
  console.log(JSON.stringify(schema, null, 2))
})

NOTE: when the inputed RAML contains !includes and those includes are not in the same directory as the script it is being ran from, you can use dt2js.setBasePath() to specify a different base path.

var raml2json = require('ramldt2jsonschema')
var join = require('path').join
var fs = require('fs')

var filePath = join(__dirname, 'api.raml')
var includesPath = '/different/path/to/includes/'
var ramlData = fs.readFileSync(filePath).toString()

raml2json.setBasePath(includesPath)
raml2json.dt2js(ramlData, 'Cat', function (err, schema) {
  if (err) {
    console.log(err)
    return
  }
  console.log(JSON.stringify(schema, null, 2))
})

js2dt

var raml2json = require('ramldt2jsonschema')
var join = require('path').join
var fs = require('fs')

var filePath = join(__dirname, 'schema.json')
var jsonData = fs.readFileSync(filePath).toString()

raml2json.js2dt(jsonData, 'Person', function (err, raml) {
  if (err) {
    console.log(err)
    return
  }
  console.log('#%RAML 1.0 Library\n')
  console.log(raml)
})

Limitations

  • in js2dt,

    • the following JSON schema properties are not supported and as a result, will not be converted:
      • not
      • number and integer's exclusiveMaximum and exclusiveMinimum
      • object's dependencies
      • array's additionalItems
    • the JSON schema oneOf property is processed the same way as the JSON schema anyOf property, it is converted to the RAML union type
    • the JSON schema type: 'string' with media and binaryEncoding: 'binary' is converted to the RAML file type
    • the JSON schema type: string with a pattern that matches exactly one of the RAML date types will be converted in the matching RAML date type
    • the JSON schema media property with anyOf, elements of which have the property mediaType will be converted to fileTypes in RAML
  • in dt2js,

    • the following RAML properties are not supported/converted:
      • annotations

License

Apache 2.0