Code Monkey home page Code Monkey logo

raml-json-enhance-node's Introduction

raml-json-enhance-node

A RAML's JSON enhancer node package to enhance JSON output of the RAML parser.

Introduction

The project is based on the raml2object node library but adjusted to work with the API Console. API Console is composed of web components from the Advanced REST Client elements ecosystem. The elements (and therefore the API Console) requires this enhancement in order to display documentation for the API spec.

Affected properties

This is the list of properties in the JavaScript object returned by the RAL JS parser affected by the enhancement process

  • types, traits, resourceTypes, annotationTypes, securitySchemes - Becomes an object instead of array, keys are object name (with library variable name if applicable)
  • responses, body, queryParameters, headers, properties, baseUriParameters, annotations, uriParameters are recusively transformed into the arrays
  • types/{object} - Expanded form for a RAML type and a canonical form with computed inheritance and pushed unions to the top level of the type structure. See documantaion for the expansion library.
  • resource/parentUrl - a full URL of the parent resource
  • resource/allUriParameters - list of all URI parameters that apply to this resource (computed from the root down to current resource)
  • resource/securedBy - Replaces security schema name with schema's definition.
  • method/allUriParameters - The same as for a resource but applied to a method that is direct child of the resource.
  • method/absoluteUri - Full, absolute URL to the method containg URI parametes in their RAML's form, eg /{fileId}
  • method/securedBy - The same as for the resource
  • method/*/headers - Full list of all possible headers compured from traits, security schemes etc
  • method/*/queryParameters - Full list of all possible queryParameters compured from traits, security schemes etc
  • method/responses - Full list of all possible response compured from traits, security schemes etc
  • type/properties/items - replaces type name with type definition
  • */example(s) - always produces examples as an array of example contents
  • */structuredExample - content is moved to the *.example array

Installation

npm install --save raml-json-enhance-node

Usage

Basic

const {RamlJsonEnhancer} = require('raml-json-enhance-node');

const enhancer = new RamlJsonEnhancer();
enhancer.enhance(ramlJsonOutput.specification)
.then((json) => {
  console.log(json);
})
.catch((cause) => console.error(cause));

From RAML file

const {RamlJsonGenerator} = require('raml-json-enhance-node');

const enhancer = new RamlJsonGenerator('./api.raml', {
  prettyPrint: true
});
enhancer.generate()
.then((json) => {
  console.log(json); // formatted JSON with `prettyPrint` option.
});

Saving output to file

Enhancer only

const {RamlJsonEnhancer} = require('raml-json-enhance-node');

const enhancer = new RamlJsonEnhancer();
enhancer.enhanceToFile(ramlJsonOutput.specification, './api.json')
.then((json) => {
  // JSON is now saved in api.json file.
  console.log(json);
})
.catch((cause) => console.error(cause));

From RAML file

const {RamlJsonGenerator} = require('raml-json-enhance-node');

const enhancer = new RamlJsonGenerator('./api.raml', {
  output: './api.json'
});
enhancer.generate()
.then((json) => {
  // The file is saved now.
  console.log(json); // And JS object is available to use.
});

raml-json-enhance-node's People

Contributors

jarrodek avatar svc-scm avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raml-json-enhance-node's Issues

TypeError: Converting circular structure to JSON

I'm using raml-json-enhance-node at version 0.3.2

With the following expansion script:

const {RamlJsonGenerator} = require('raml-json-enhance-node');

process.stdout.write("\n# Converting RAML to enhanced JSON ...");

const enhancer = new RamlJsonGenerator('./test.raml', {
    output: './test.json',
    prettyPrint: true
});
enhancer.generate()
    .then(function(json) {
        process.stdout.write(" \x1b[32mdone\x1b[0m.\n");
    })
    .catch((cause) => {
        process.stdout.write(" \x1b[31mfailed\x1b[0m.\n");
        console.error(cause);
    });

and the used test.raml file

#%RAML 1.0
title: Example API
types:
    CategoryReference:
        type: object
        properties:
            id: string
            obj: Category
    Category:
        type: object
        properties:
            name:
                type: string
            parent?:
                type: CategoryReference
/{id}:
  post:
    responses:
      201:
        body:
          application/json:
            type: Category

I get following type error

TypeError: Converting circular structure to JSON
    at JSON.stringify (<anonymous>)
    at Promise (node_modules/raml-json-enhance-node/lib/json-generator.js:104:25)
    at new Promise (<anonymous>)
    at JsonGenerator.save (node_modules/raml-json-enhance-node/lib/json-generator.js:101:12)
    at parse.then.then (node_modules/raml-json-enhance-node/lib/json-generator.js:61:26)
    at <anonymous>

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.