oas-raml-converter Quick Start

Jonathan Stoikovitch
RAML by Example

--

This is an introduction to oas-raml-converter. oas-raml-converter is a command line tool that helps convert to and from RAML and OAS.

Let’s begin by installing oas-raml-converter as a command-line tool:

$ npm i -g oas-raml-converter

and let’s also grab a RAML file:

$ curl https://raw.githubusercontent.com/raml-org/raml-examples/master/typesystem/simple.raml -o api.raml

Now, we can convert it from RAML 1.0 to OAS 2.0 with the following command:

$ oas-raml-converter --from RAML --to OAS20 ./api.raml > api.oas2

the output will look like this:

and we can even convert that same API Spec from RAML 1.0 to OAS 3.0 with:

$ oas-raml-converter --from RAML --to OAS30 ./api.raml > api.oas3

Using oas-raml-converter as a NodeJS library

oas-raml-converter can also be used as a library! This is particularly useful when processing either the input or the output. Let's see how it works.

In this scenario, I’ll use oas-raml-converter to convert from RAML 1.0 to OAS 2.0, and then, use yamljs to convert the output to the YAML syntax.

I’ll start by initializing my project and installing both libraries:

$ npm init --yes
(...)

$ npm install --save oas-raml-converter yamljs
(...)

then, let’s create an index.js file with the following code:

and then run with node . which will output my API Spec in OAS 2.0 format with the YAML syntax:

--

--