raml-org / ramldt2jsonschema

CLI & Library to convert a RAML 1.0 data type to a JSON Schema, and back
Apache License 2.0
59 stars 22 forks source link

Cannot handle !include #9

Closed dwarburt closed 6 years ago

dwarburt commented 8 years ago

A simple Hello World RAML project, that is modified only to !include a file, will generate this exception:

[~/git/tmp/raml-test]$ dt2js ./api.raml TestType { Error at generateError (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:162:10) at throwError (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:168:9) at composeNode (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1397:7) at readBlockMapping (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1056:11) at composeNode (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1326:12) at readBlockMapping (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1056:11) at composeNode (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1326:12) at readDocument (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1488:3) at loadDocuments (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1544:5) at load (/usr/local/lib/node_modules/ramldt2jsonschema/node_modules/js-yaml/lib/js-yaml/loader.js:1561:19) name: 'YAMLException', reason: 'unknown tag !<!include>', mark: Mark { name: null, buffer: '#%RAML 1.0\ntitle: Test Raml DT to JS schema\nversion: v1\nbaseUri: http://api.samplehost.com\ntypes:\n TestType: !include type1.yml\n/helloWorld:\n get:\n responses:\n 200:\n body:\n application/json:\n example: |\n {\n "message" : "Hello World"\n }\n\u0000', position: 128, line: 5, column: 30 }, message: 'unknown tag !<!include> at line 6, column 31:\n TestType: !include type1.yml\n ^' }

jstoiko commented 8 years ago

@dwarburt: you're right. That's a limitation of dt2js. Includes are not supported (yet?). you should be able to run it against the file that contains that type though.

dwarburt commented 8 years ago

@jstoiko well, I can't actually, because it's not the type that's being !included but other details (like examples).

sichvoge commented 7 years ago

Maybe one idea would be to replace the current js-yaml parser with https://github.com/mulesoft-labs/yaml-ast-parser. @jstoiko what do you think?

That fork supports resolving !includes.

Fuco1 commented 7 years ago

Is this being considered? It's quite hard to write a raml spec without include when the project has more than 2 endpoints.

sichvoge commented 7 years ago

Completely agree. @jstoiko any updates?

amritsinghbains commented 6 years ago

When can we have this complete by?

jstoiko commented 6 years ago

There is a PR waiting for @brevity to add some test cases before merging: https://github.com/raml-org/ramldt2jsonschema/pull/20

Feel free to pull the branch and try it though!