According to #50, the generator now supports file references, which is really nice.
But there is a minor hickup...
I've tested it using the following two yaml file:
# globalref.yaml
asyncapi: '2.0.0-rc1'
id: 'urn:hello-world-publisher'
info:
title: Hello world publisher application
version: '0.1.0'
servers:
- url: broker.mycomapny.com
protocol: amqp
description: This is "My Company" broker.
channels:
hello:
publish:
message:
$ref: 'file:./common.yaml#/components/messages/hello-msg'
# common.yaml
components:
messages:
hello-msg:
payload:
type: string
pattern: '^hello .+$'
md5-309543f0ba56087f05b5d44ef2ad5f9f
$ ag -o doc-autogen globalref.yaml markdown
Something went wrong:
Error: Error opening file "/./common.yaml"
ENOENT: no such file or directory, open '/./common.yaml'
at parse (/usr/lib/node_modules/asyncapi-generator/node_modules/asyncapi-parser/lib/parser.js:75:11)
at <anonymous>
md5-0a142b21e2aa64e227e68447c69234e8
$ sudo cp common.yaml /
$ ag -o doc-autogen globalref.yaml markdown
Done! ✨
Check out your shiny new generated files at ...
Am I doing something wrong or is this a bug?
It's a misconfiguration of the parser: https://github.com/asyncapi/generator/blob/master/lib/generator.js#L169.
The parse function accepts a second argument with options to configure this: https://github.com/asyncapi/parser-js/blob/master/API.md#module_Parser+parse.
Check out this example: https://github.com/asyncapi/parser-js/blob/master/test/parse_test.js#L58
Will patch it with a good default and the chance to configure it. Thanks for reporting!
Hy @jdall,
I was debugging this issue. It appears it's because of you have added file: prefix in you ref
If you make it like this, then it works fine
message:
$ref: './common.yaml#/components/messages/hello-msg'
@fmvilas I think we don't need to have a default path option. By default, it is auto set to root.
We can close this issue.
I can verify that it's also working on my side if I leave out the 'file:' part.
Thanks, guys.
Great find, Waleed. Thanks for having a look!
I wonder if there's a better default than the root directory. I think $refs should be resolved relative to the file it is defined. Otherwise, it's very complicated to reuse schemas across documents.
@fmvilas I agree to that. Having ref relative to the main file.
I'll create a separate PR for that as a feature. This ticket can be closed.