Coder Social home page Coder Social logo

iq-scm / raml-js-parser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from raml-org/raml-js-parser

0.0 0.0 0.0 4.06 MB

(deprecated) A RAML parser based on PyYAML written in CoffeScript and available for use as NodeJs module or in-browser.

JavaScript 87.45% CoffeeScript 12.32% HTML 0.08% RAML 0.15%

raml-js-parser's Introduction

RAML Parser

![Gitter](https://badges.gitter.im/Join Chat.svg)

Build Status Dependency Status

This is a JavaScript parser for RAML version 0.8 as defined in the 0.8 RAML specification

A newer version is now available as a beta. It supports RAML 1.0 as well as RAML 0.8.

Contributing

If you are interested in contributing some code to this project, thanks! Please first read and accept the Contributors Agreement.

To discuss this project, please use its github issues or the RAML forum.

Usage for NodeJS

Load

Loading a RAML file is as easy as follows:

  var raml = require('raml-parser');

  raml.loadFile('myAPI.raml').then( function(data) {
    console.log(data);
  }, function(error) {
    console.log('Error parsing: ' + error);
  });

You can alternatively load from a string containing the api definition:

  var raml = require('raml-parser');

  var definition = [
    '#%RAML 0.8',
    '---',
    'title: MyApi',
    'baseUri: http://myapi.com',
    '/Root:'
  ].join('\n');

  raml.load(definition).then( function(data) {
    console.log(data);
  }, function(error) {
    console.log('Error parsing: ' + error);
  });

The shape of the returned object is (unofficially) documented in this Typescript interface.

Abstract Syntax Tree

Generating an AST from a RAML file is as easy as follows:

  var raml = require('raml-parser');

  var myAPI;
  raml.composeFile('myAPI.raml').then( function(rootNode) {
    console.log('Root Node: ' + rootNode)
  }, function(error) {
    console.log('Error parsing: ' + error);
  });

you can also alternatively generate an AST from a string containing the api definition:

  var raml = require('raml-parser');

  var definition = [
    '#%RAML 0.8',
    '---',
    'title: MyApi',
    'baseUri: http://myapi.com',
    '/Root:'
  ].join('\n');

  raml.compose(definition).then( function(rootNode) {
    console.log('Root Node: ' + rootNode)
  }, function(error) {
    console.log('Error parsing: ' + error);
  });

Usage for In-Browser

Using the RAML parser from inside the browser requires the user to actually include the RAML javascript file in a script tag as follows:

<script src="raml-parser.min.js"></script>

from there on the usage is pretty much the same as NodeJS, the script defines a RAML.Parser object globally which can be used as follows:

RAML.Parser.loadFile('http://localhost:9001/myAPI.raml').then( function(data) {
  console.log(data)
}, function(error) {
  console.log('Error parsing: ' + error);
});

Notice that the in-browser version can fetch remote API definitions via XHR.

raml-js-parser's People

Contributors

3miliano avatar aldonline avatar alejofernandez avatar blakeembrey avatar clarkcutler avatar dariusk avatar gitter-badger avatar pose avatar repocho avatar svacas avatar xaka avatar

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.