Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Circular References in the scheme #55

Open
florintene opened this issue Jul 14, 2022 · 5 comments
Open

Question: Circular References in the scheme #55

florintene opened this issue Jul 14, 2022 · 5 comments

Comments

@florintene
Copy link

Hi,

I do have a question, as I couldn't find in the docs, if circular references are supported by the asyncapi-validator ?
Currently, for a definition that has circular references the validation fails with:

/node_modules/json-schema-traverse/index.js:67
function _traverse(opts, pre, post, schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) {
                  ^

RangeError: Maximum call stack size exceeded
    at _traverse (/node_modules/json-schema-traverse/index.js:67:19)

Thank you,

@WaleedAshraf
Copy link
Owner

I haven't tested it, but I think it should work. Though it's possible that there is some bug.
Feel free to open a PR if you spot the issue, I'll try to look into this in the next few days.

@WaleedAshraf
Copy link
Owner

WaleedAshraf commented Jul 14, 2022

@florintene It seems that circular refs are not supported, as per AJV here: https://ajv.js.org/security.html#circular-references-in-javascript-objects. I'll update the readme.

@florintene
Copy link
Author

Thank you very much @WaleedAshraf.

Circular references are always a problem but i'm surprise that AJV doesn't support them.
I had a look through the AsyncAPI-Parser and they do support (mark & flag) the circular references.

There are options out there that can help in a combination with AJV.
For example, json-schema-ref-parser and json-schema-ref-parser(Github)

Used the bundle:

Bundles all referenced files/URLs into a single schema that only has internal $ref pointers.
...
This also eliminates the risk of circular references, so the schema can be safely serialized using JSON.stringify().

and then AJV can compile successfully the schema.

Not to mention that there is always the option to review the schema and drop the circular references - although that is not always possible.

Anyway, hope the above info might help others.

Thank you ;)

@WaleedAshraf
Copy link
Owner

I see your point. I think it's possible the way you suggested, though I'd prefer if it's done within asyncapi/parser-js as it handles the parsing. An optional parameter can be passed to remove circular references. It's already using json-schema-ref-parser. I suggest opening an issue there.

Another way you can try is to parse the schema with asyncapi/parser-js then remove the circular refs using json-schema-ref-parser and then use asyncpi-validator. This may work, but I haven't tested it yet.

@florintene
Copy link
Author

Yes, is something to explore.
I'll have a look over the week to see if I manage to make it play nicely together :)
I think one of the issue might be that asyncapi/parser-js is deferencing the schema so we might have to use a json stringify that can deal with circular references.

Anyway, i'll try to have a look and let you know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants