src/dt2js.js
function traverse (obj, ast, rootFileDir, libraries) {
  function recurse (keys, currentNode, nodeFileDir) {
    if (currentNode.key) {
      keys = keys.concat([currentNode.key.value])
    }
    // kind 5 is an include
    if (currentNode.value && currentNode.value.kind === 5) {
      const location = currentNode.value.value
      const [include, contentType, newNodeFileDir] = resolveInclude(rootFileDir, nodeFileDir, location)
      // If it's json, parse it
      const ramlContentTypes = [
        'application/raml+yaml',
        'text/yaml',
        'text/x-yaml',
        'application/yaml',
        'application/x-yaml'
      ]
      if (path.extname(location) === '.json' || contentType === 'application/json') {
        deep(obj, keys.join('.'), JSON.parse(include))
        // If it's raml or yaml, parse it as raml
      } else if (['.raml', '.yaml', '.yml'].indexOf(path.extname(location)) > -1 || ramlContentTypes.indexOf(contentType) > -1) {
        currentNode.value = yap.load(include)
        if (currentNode.value.errors.length > 0) {
          throw new Error('Invalid RAML data in one of the included files')
        }
        recurse(keys, currentNode.value, newNodeFileDir)
        // If it's anything else, just add it as a string.
      } else {
        currentNode.value = include
      }
    // a leaf node to be added
    } else if (currentNode.value && currentNode.value.value) {
      let val = !currentNode.value.doubleQuoted
        // convert back from string type
        ? destringify(currentNode.value.value)
        : currentNode.value.value
      val = libraryOrValue(libraries, val)
      deep(obj, keys.join('.'), val)
    // a leaf that is an array
    } else if (currentNode.value && currentNode.value.items) {
      const values = currentNode.value.items.map(function (el) { return el.value })
      deep(obj, keys.join('.'), values)
    // an object that needs further traversal
    } else if (currentNode.mappings) {
      for (let i = 0; i < currentNode.mappings.length; i++) {
        recurse(keys, currentNode.mappings[i], nodeFileDir)
      }
    } else if (currentNode.key && currentNode.key.value === 'examples') {
      const vals = currentNode.value.mappings.map(function (el) {
        return el.value.value
      })
      deep(obj, keys.join('.'), vals)
    // an object that needs further traversal
    } else if (currentNode.value && currentNode.value.mappings) {
      for (let o = 0; o < currentNode.value.mappings.length; o++) {
        recurse(keys, currentNode.value.mappings[o], nodeFileDir)
      }
    }
  }
  recurse([], ast, rootFileDir)
}
function traverse (obj, ast, rootFileDir, libraries) {
  function recurse (keys, currentNode, nodeFileDir) {
    if (currentNode.key) {
      keys = keys.concat([currentNode.key.value])
    }
    // kind 5 is an include
    if (currentNode.value && currentNode.value.kind === 5) {
      const location = currentNode.value.value
      const [include, contentType, newNodeFileDir] = resolveInclude(rootFileDir, nodeFileDir, location)
      // If it's json, parse it
      const ramlContentTypes = [
        'application/raml+yaml',
        'text/yaml',
        'text/x-yaml',
        'application/yaml',
        'application/x-yaml'
      ]
      if (path.extname(location) === '.json' || contentType === 'application/json') {
        deep(obj, keys.join('.'), JSON.parse(include))
        // If it's raml or yaml, parse it as raml
      } else if (['.raml', '.yaml', '.yml'].indexOf(path.extname(location)) > -1 || ramlContentTypes.indexOf(contentType) > -1) {
        currentNode.value = yap.load(include)
        if (currentNode.value.errors.length > 0) {
          throw new Error('Invalid RAML data in one of the included files')
        }
        recurse(keys, currentNode.value, newNodeFileDir)
        // If it's anything else, just add it as a string.
      } else {
        currentNode.value = include
      }
    // a leaf node to be added
    } else if (currentNode.value && currentNode.value.value) {
      let val = !currentNode.value.doubleQuoted
        // convert back from string type
        ? destringify(currentNode.value.value)
        : currentNode.value.value
      val = libraryOrValue(libraries, val)
      deep(obj, keys.join('.'), val)
    // a leaf that is an array
    } else if (currentNode.value && currentNode.value.items) {
      const values = currentNode.value.items.map(function (el) { return el.value })
      deep(obj, keys.join('.'), values)
    // an object that needs further traversal
    } else if (currentNode.mappings) {
      for (let i = 0; i < currentNode.mappings.length; i++) {
        recurse(keys, currentNode.mappings[i], nodeFileDir)
      }
    } else if (currentNode.key && currentNode.key.value === 'examples') {
      const vals = currentNode.value.mappings.map(function (el) {
        return el.value.value
      })
      deep(obj, keys.join('.'), vals)
    // an object that needs further traversal
    } else if (currentNode.value && currentNode.value.mappings) {
      for (let o = 0; o < currentNode.value.mappings.length; o++) {
        recurse(keys, currentNode.value.mappings[o], nodeFileDir)
      }
    }
  }
  recurse([], ast, rootFileDir)
}
function traverse ( obj , ast , rootFileDir , libraries ) { function recurse ( keys , currentNode , nodeFileDir ) { if ( currentNode . key ) { keys = keys . concat ( [ currentNode . key . value ] ) } // kind 5 is an include if ( currentNode . value && currentNode . value . kind === 5 ) { const location = currentNode . value . value const [ include , contentType , newNodeFileDir ] = resolveInclude ( rootFileDir , nodeFileDir , location ) // If it's json, parse it const ramlContentTypes = [ 'application/raml+yaml' , 'text/yaml' , 'text/x-yaml' , 'application/yaml' , 'application/x-yaml' ] if ( path . extname ( location ) === '.json' || contentType === 'application/json' ) { deep ( obj , keys . join ( '.' ) , JSON . parse ( include ) ) // If it's raml or yaml, parse it as raml } else if ( [ '.raml' , '.yaml' , '.yml' ] . indexOf ( path . extname ( location ) ) > - 1 || ramlContentTypes . indexOf ( contentType ) > - 1 ) { currentNode . value = yap . load ( include ) if ( currentNode . value . errors . length > 0 ) { throw new Error ( 'Invalid RAML data in one of the included files' ) } recurse ( keys , currentNode . value , newNodeFileDir ) // If it's anything else, just add it as a string. } else { currentNode . value = include } // a leaf node to be added } else if ( currentNode . value && currentNode . value . value ) { let val = ! currentNode . value . doubleQuoted // convert back from string type ? destringify ( currentNode . value . value ) : currentNode . value . value val = libraryOrValue ( libraries , val ) deep ( obj , keys . join ( '.' ) , val ) // a leaf that is an array } else if ( currentNode . value && currentNode . value . items ) { const values = currentNode . value . items . map ( function ( el ) { return el . value } ) deep ( obj , keys . join ( '.' ) , values ) // an object that needs further traversal } else if ( currentNode . mappings ) { for ( let i = 0 ; i < currentNode . mappings . length ; i ++ ) { recurse ( keys , currentNode . mappings [ i ] , nodeFileDir ) } } else if ( currentNode . key && currentNode . key . value === 'examples' ) { const vals = currentNode . value . mappings . map ( function ( el ) { return el . value . value } ) deep ( obj , keys . join ( '.' ) , vals ) // an object that needs further traversal } else if ( currentNode . value && currentNode . value . mappings ) { for ( let o = 0 ; o < currentNode . value . mappings . length ; o ++ ) { recurse ( keys , currentNode . value . mappings [ o ] , nodeFileDir ) } } } recurse ( [ ] , ast , rootFileDir ) }
traverses AST generated by yaml-ast-parser
and create json object..

@param  {Object} obj - The object to hold the parsed raml
@param  {Object} ast - The ast from yaml-ast-parser
@param  {String} rootFileDir - a directory to be used
as cwd while resolving includes
@param  {Object} libraries - an object holding libraries to be used
@returns  {Object} - js object representing raml
traverses AST generated by yaml - ast - parser and create json object ..