Open patrickhousley opened 8 years ago
Hi @patrickhousley I cannot seem to be able to reproduce this. How are you testing?
this is the RAML I am using (with you collection.yaml
file)
#%RAML 0.8
title: Example API
mediaType: application/json
resourceTypes:
- collection: !include collection.yaml
/carts:
type:
collection:
get-example: foo
post-example: bar
maybe there is something weird in your types/carts.yaml
file, which is not included in the issue
I was bitten by the same bug so it's a real one.
I don't doubt it, can you share a RAML that I can use? @FredericHeem
Test:
it('should dereference schemas and load the raml object', function (done) {
raml.loadFile(__dirname + '/../raml-files/dereference-json-schema.raml', { dereferenceSchemas: true }).then(function (ramlObj) {
done();
}, function (err) {
done(err);
});
});
dereference-json-schema.raml:
#%RAML 0.8
---
title: example
resourceTypes:
- collection: !include resourceTypes/collection.yaml
resourceTypes/collection.yaml
get:
description: Get a collection of <<resourcePathName>>.
responses:
200:
body:
schema: <<resourcePathName>>
example: <<get-example>>
post:
description: Creates a <<resourcePathName | !singularize>>.
body:
schema: <<resourcePathName | !singularize>>
example: <<post-example>>
responses:
201:
description: Successfully created the resource.
headers:
Location:
description: The location of the created resource.
type: string
Result:
patrickhousley@phousley-mac ~/Documents/projects/github/raml-js-parser (master *+)$ npm tst
> raml-parser@0.8.18 test /Users/patrickhousley/Documents/projects/github/raml-js-parser
> grunt test
Running "coffeelint:app" (coffeelint) task
>> 21 files lint free.
Running "coffee:files" (coffee) task
File lib/composer.js created.
File lib/construct.js created.
File lib/errors.js created.
File lib/events.js created.
File lib/joiner.js created.
File lib/loader.js created.
File lib/nodes.js created.
File lib/parser.js created.
File lib/protocols.js created.
File lib/raml.js created.
File lib/reader.js created.
File lib/resolver.js created.
File lib/resourceTypes.js created.
File lib/scanner.js created.
File lib/schemas.js created.
File lib/securitySchemes.js created.
File lib/tokens.js created.
File lib/traits.js created.
File lib/transformations.js created.
File lib/util.js created.
File lib/validator.js created.
Running "connect:server" (connect) task
Started connect web server on 127.0.0.1:9001.
Running "mochacli:all" (mochacli) task
(node:93590) DeprecationWarning: child_process: options.customFds option is deprecated. Use options.stdio instead.
․․․․
3 passing (581ms)
1 failing
1) Schemas should dereference schemas and load the raml object:
SyntaxError: Unexpected token < in JSON at position 0
at Object.parse (native)
at /Users/patrickhousley/Documents/projects/github/raml-js-parser/lib/raml.js:302:25
at Array.map (native)
at RamlParser.__dirname.RamlParser.RamlParser.dereferenceSchemas (/Users/patrickhousley/Documents/projects/github/raml-js-parser/lib/raml.js:295:36)
at RamlParser.dereferenceSchemas (/Users/patrickhousley/Documents/projects/github/raml-js-parser/lib/raml.js:5:61)
at /Users/patrickhousley/Documents/projects/github/raml-js-parser/lib/raml.js:233:24
at _fulfilled (/Users/patrickhousley/Documents/projects/github/raml-js-parser/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/Users/patrickhousley/Documents/projects/github/raml-js-parser/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/Users/patrickhousley/Documents/projects/github/raml-js-parser/node_modules/q/q.js:760:13)
at /Users/patrickhousley/Documents/projects/github/raml-js-parser/node_modules/q/q.js:574:44
at flush (/Users/patrickhousley/Documents/projects/github/raml-js-parser/node_modules/q/q.js:108:17)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
Warning: Use --force to continue.
Aborted due to warnings.
npm ERR! Test failed. See above for more details.
patrickhousley@phousley-mac ~/Documents/projects/github/raml-js-parser (master *+)$
I used https://github.com/raml2html/raml2html which depends on this library.
The bug is there also, if you use <<placeholder>>
statements. So I think it is an bug of this library. Would be nice if this can be fixed :).
Looks like
dereferenceSchemas
is attempting to JSON.parse a raml file.Below is a redacted version of my raml file.
I changed line 302 of
dereferenceSchemas
to:Output:
This leads me to believe it is attempting to parse
src/resourceTypes/collection.yaml
as JSON. Below is the contents of that file: