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

jsonapi2raml

v0.2.7

Published

Generates RAML for REST APIs that follow JSON-API spec.

Downloads

6

Readme

npm version JavaScript Style Guide

jsonapi2raml

Utility used to generate RAML v1.0 Documentation for REST APIs that follow the JSON-API spec.

Installation

npm install jsonapi2raml

Demo

Demo

CLI

Usage

jsonapi2raml <file-name> <file-output> [options]

Note: To use jsonapi2raml from CLI you need to install it globally.

| Options | Description | | ------------ | ----------- | | <payload> | The name of the file containing the payload which jsonapi2raml will parse to generate the RAML Documenation. More info about the structure of this file below. | | <output> | The name of the file or directory where jsonapi2raml will be generating the RAML documentation in. | | version | Shows version. |

API

You can use the API directly:

const jsonapi2raml = require('jsonapi2raml')
jsonapi2raml.generate({
  payload: [...],
  output: 'path/to/raml',
  generator: jsonapi2raml.generators.singleFile
})

Generators

A Generator is a function that will be invoked by jsonapi2raml once the parsing has been done. This function will be invoked with the following info:

  • Output file name.
  • Generated RAML objects.

Example of a Generator argument:

{
  output: 'path/to/raml',
  assets: {
    // The names of RAML Types common to all REST APIs which follow the JSON-API
    // Spec. More info in '/src/libs/asset-names.js'
    names: {..},
    raml: {
      // RAML Endpoints.
      endpoints: {..},
      // RAML Trait Representational objects common to all REST APIs which
      // follow the JSON-API Spec
      traits: {..},
      // RAML Resource Types Representational objects common to all REST APIs
      // which follow the JSON-API Spec
      resourceTypes: {..},
      types: {
        // RAML Types Representational objects common to all REST APIs which
        // follow the JSON-API Spec
        generic: {..},
        // RAML Types Representational objects related to the provided JSON-API
        // Resources
        payload: {..}
      }
    }
  }
}

Default Generators

jsonapi2raml comes with the following generators:

Single File

Generates the RAML Documentation in a single file.

const jsonapi2raml = require('jsonapi2raml')
jsonapi2raml.generate({
  payload: [...],
  output: 'path/to/raml',
  generator: jsonapi2raml.generators.singleFile
})

Payload Structure

For jsonapi2raml to generate the RAML Documentation of a REST API that follow the JSON-API spec all it needs is info about the JSON-API Resources.

Example of a Payload file:

[{
  "type": "user",
  "attributes": {
    "name": {
      "type": "string",
      "maxLength": 10,
      "pattern": "/[a-zA-Z]/"
    },
    "age": "integer"
  },
  "relationships": {
    "token": {
      "data": {
        "type": "token"
      }
    }
  }
}, {
  "type": "token",
  "attributes": {
    "value": "string",
    "created": "datetime"
  }
}]

Note: The value of an attribute should be a RAML Built-in Type.

Acknowledgments

Thanks for your feedback & support!