What is webapi-parser?
webapi-parser is a versatile library for parsing, validating, and transforming API definitions. It supports multiple API specification formats including RAML, OpenAPI, and AsyncAPI, making it a powerful tool for developers working with various API standards.
What are webapi-parser's main functionalities?
Parsing API Definitions
This feature allows you to parse API definitions written in RAML, OpenAPI, or AsyncAPI formats. The code sample demonstrates parsing a simple RAML 1.0 API definition.
const wap = require('webapi-parser');
async function parseApi() {
const model = await wap.raml10.parse(`#%RAML 1.0
title: My API
version: v1
baseUri: http://api.example.com/v1
`);
console.log(model);
}
parseApi();
Validating API Definitions
This feature allows you to validate API definitions to ensure they conform to the respective specification. The code sample demonstrates validating a RAML 1.0 API definition.
const wap = require('webapi-parser');
async function validateApi() {
const model = await wap.raml10.parse(`#%RAML 1.0
title: My API
version: v1
baseUri: http://api.example.com/v1
`);
const report = await wap.raml10.validate(model);
console.log(report);
}
validateApi();
Transforming API Definitions
This feature allows you to transform API definitions from one format to another, such as from RAML to OpenAPI. The code sample demonstrates transforming a RAML 1.0 API definition to an OpenAPI 2.0 definition.
const wap = require('webapi-parser');
async function transformApi() {
const model = await wap.raml10.parse(`#%RAML 1.0
title: My API
version: v1
baseUri: http://api.example.com/v1
`);
const oasModel = await wap.oas20.generate(model);
console.log(oasModel);
}
transformApi();
Other packages similar to webapi-parser
swagger-parser
swagger-parser is a powerful tool for parsing, validating, and dereferencing OpenAPI (Swagger) definitions. It is specifically focused on OpenAPI, making it a great choice if you are working exclusively with OpenAPI specifications. Compared to webapi-parser, it does not support RAML or AsyncAPI.
api-spec-converter
api-spec-converter is a utility for converting between different API specification formats, including OpenAPI, RAML, and API Blueprint. While it offers conversion capabilities similar to webapi-parser, it does not provide parsing or validation functionalities.
webapi-parser
API Spec parser based on AMF. Currently supports RAML 0.8, 1.0 and OAS 2.0.
This project is a thin wrapper that exposes API Spec-related capabilities from AMF. It is written in Scala and offered in two versions: JavaScript and Java.
📃 Documentation
📦 Examples
🛠 Installation
JavaScript
Install the npm package:
$ npm install webapi-parser
and require/reference as follows:
const wap = require('webapi-parser').WebApiParser
Usage examples are located in the examples directory.
Java
Specify webapi-parser
as a dependency and set both MuleSoft and Jitpack repositories.
Gradle:
dependencies {
compile 'org.raml:webapi-parser:x.y.z'
}
...
repositories {
maven {
url "https://repository-master.mulesoft.org/nexus/content/repositories/releases"
}
maven {
url "https://jitpack.io"
}
mavenCentral()
}
Maven:
<dependency>
<groupId>org.raml</groupId>
<artifactId>webapi-parser</artifactId>
<version>X.Y.Z</version>
</dependency>
...
<repositories>
<repository>
<id>MuleSoftReleases</id>
<url>https://repository-master.mulesoft.org/nexus/content/repositories/releases</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
To install snapshot versions set additional Sonatype snapshots repository.
Gradle:
...
repositories {
...
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots'
}
}
Maven:
...
<repositories>
...
<repository>
<id>SonatypeSnapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
Usage examples are located in the examples directory.
If you wish to contribute to this project, please review our Contribution Guidelines.