cybertk / ramlev

Validate/Verify examples in RAML
Other
30 stars 5 forks source link

Cannot read relative paths? #6

Closed pateketrueke closed 10 years ago

pateketrueke commented 10 years ago

Hi, I'm playing with ramlev to write a grunt-plugin but it can't load any relative file.

new Ramlev({
  ramlPath: path.resolve(__dirname + '/../example/index.raml')
}).run();

Output:

{ [Error: cannot read ./people/collection/index.raml (Error: ENOENT, open './people/collection/index.raml')]
  context: 'while reading ./people/collection/index.raml',
  context_mark: null,
  message: 'cannot read ./people/collection/index.raml (Error: ENOENT, open \'./people/collection/index.raml\')',
  problem_mark:
   { name: undefined,
     line: 5,
     column: 9,
     buffer: '#%RAML 0.8\n\ntitle: My API\nversion: 0.1.0\n\n/people: !include ./people/collection/index.raml\n\u0000',
     pointer: 51 },
  note: undefined }
cannot read ./people/collection/index.raml (Error: ENOENT, open './people/collection/index.raml')

I did the same with raml4js and works perfectly.

pateketrueke commented 10 years ago

Update:

var raml_file = path.resolve(__dirname + '/../example/index.raml');

process.chdir(path.resolve(raml_file + '/..'));

new Ramlev({
  ramlPath: raml_file
}).run();

Using process.chdir() works, but is really required?

cybertk commented 10 years ago

ramlev use raml-js-parser to load RAML, I think this is a bug of raml-js-parser

raml.load(source).then (raml) ->
cybertk commented 10 years ago

It's caused by raml.load(). I replace it with raml.loadFile(), then it works.