{"library":"raml-parser","title":"RAML 0.8 Parser","description":"The `raml-parser` package provides a JavaScript implementation for parsing RAML (RESTful API Modeling Language) version 0.8 specifications. It is built using CoffeeScript and is designed for use in both Node.js environments via CommonJS `require` and directly in web browsers by including a script tag. The current stable version is 0.8.18. This parser specifically targets the RAML 0.8 specification, which is an older standard. For projects requiring support for RAML 1.0, a separate, newer parser (`raml-js-parser-2`) is available and recommended. Release cadence for `raml-parser` is infrequent, focusing primarily on bug fixes and maintenance for the 0.8 specification, such as recent patches addressing circular references in JSON schemas and `$ref`erenced schema support. Its primary differentiator is its strict adherence to the deprecated RAML 0.8 standard, making it suitable mainly for maintaining legacy systems built on that specific version.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install raml-parser"],"cli":{"name":"raml-parser","version":null}},"imports":["const raml = require('raml-parser');","RAML.Parser.loadFile('myAPI.raml')","raml.loadFile('path/to/myAPI.raml').then(...);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const raml = require('raml-parser');\nconst fs = require('fs');\n\n// Create a dummy RAML file for demonstration\nconst dummyRamlContent = [\n  '#%RAML 0.8',\n  '---',\n  'title: My Example API',\n  'baseUri: http://api.example.com/{version}',\n  'version: v1',\n  '/users:',\n  '  get:',\n  '    description: Retrieve a list of users',\n  '    responses:',\n  '      200:',\n  '        body:',\n  '          application/json:',\n  '            schema: |',\n  '              { \"$schema\": \"http://json-schema.org/draft-04/schema#\", \"type\": \"array\", \"items\": { \"type\": \"object\", \"properties\": { \"id\": { \"type\": \"integer\" }, \"name\": { \"type\": \"string\" } } } }',\n  '              type: array',\n  '              items: userDef',\n  '  post:',\n  '    description: Create a new user',\n  '    body:',\n  '      application/json:',\n  '        schema: userDef',\n  'resourceTypes:',\n  '  - userDef: { type: object, properties: { id: { type: integer }, name: { type: string } } }'\n].join('\\n');\n\nfs.writeFileSync('myAPI.raml', dummyRamlContent);\n\n// 1. Load from a RAML file\nraml.loadFile('myAPI.raml').then( function(data) {\n  console.log('--- Parsed API from file (Object Model) ---');\n  console.log(JSON.stringify(data, null, 2));\n}, function(error) {\n  console.error('Error parsing file: ' + error);\n});\n\n// 2. Load from a string definition\nconst definitionString = [\n  '#%RAML 0.8',\n  '---',\n  'title: My String API',\n  'baseUri: http://string-api.example.com',\n  '/products:',\n  '  get:',\n  '    description: Get all products',\n  '    responses: { 200: { body: { \"application/json\": { example: \"[{ \\\"id\\\": 1, \\\"name\\\": \\\"Product A\\\" }]\" } } } }'\n].join('\\n');\n\nraml.load(definitionString).then( function(data) {\n  console.log('\\n--- Parsed API from string (Object Model) ---');\n  console.log(JSON.stringify(data, null, 2));\n}, function(error) {\n  console.error('Error parsing string: ' + error);\n});\n\n// 3. Compose an AST from a RAML string\nraml.compose(definitionString).then(function(rootNode) {\n  console.log('\\n--- Composed AST from string ---');\n  console.log('Root Node Type:', rootNode.kind);\n  console.log('Root Node Value:', rootNode.value);\n}, function(error) {\n  console.error('Error composing AST from string: ' + error);\n});\n\n// Clean up the dummy file\nprocess.on('exit', () => {\n  if (fs.existsSync('myAPI.raml')) {\n    fs.unlinkSync('myAPI.raml');\n  }\n});","lang":"javascript","description":"This quickstart demonstrates how to parse a RAML 0.8 file and a RAML 0.8 string into an object model, and also how to generate an Abstract Syntax Tree (AST) from a RAML string, using both `loadFile`/`load` and `compose` methods.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}