Redocly/redocly-cli

better error handling when $ref references an external file in asyncapi

marianobntz opened this issue · 8 comments

Is your feature request related to a problem? Please describe.

I am building my pipelines to publish APIs and when I tried to bundle the asyncapi files I found the error below

Describe the solution you'd like

Support for bundling asyncapi files is the expected solution.

Describe alternatives you've considered

not much since bunding is the whole idea...

Additional context

The error shown now is:

Something went wrong when processing .\cache-messages-1.0.json:

  • Cannot read properties of undefined (reading 'schemas')

Update
This comment is wrong, $schema and $ref are different things...
Anyway... when I use a $ref keyword referencing an external file I get the error... I tried different combinations:

  • "$ref": "components/schemas/type.json"
  • "$ref": "components/schemas/type.json#"

type.json is:

{
"type": "string",
"description": "dummy",
"pattern": "^[a-z0-9\-]+$",
"example": "supplier"
}

  • tried changing the type.json to (this is a sample, maybe I got a syntax error in this sample):

{ "components": { "schemas": { "record": {
"type": "string",
"description": "dummy",
"pattern": "^[a-z0-9\-]+$",
"example": "supplier"
}}}}

and tested

  • "$ref": "components/schemas/type.json#/components/schemas/record"

But no luck..

Original comment
After some debuging I discovered that in asyncapi schema references use the $schema keyword instead of $ref that is used in openapi.
It would be nice to have a lint check and better information when discovering this problem.

Thanks

Hi @marianobntz, this looks like a bug. Where did you put the $ref?

Tried to put the $ref in a message payload directly in a channel, inside a reusable component under components/messages with no luck.

weird thing is that the lint command supports the external ref, it is just the bundle command who breaks...

I'm sorry, only the lint command supports AsyncAPI (v2.6) at the moment. Bundle doesn't have AsyncAPI support yet (for any version)

ok.. can I change the issue title to "support bundle for asyncapi documents?" 😄

bundle actually works if you do not use the external $ref

bundle actually works if you do not use the external $ref

It also works for external $refs from some specific places (like channel servers and message examples). So at first I thought the bundle command was implemented 🙈. But yes, it needs to be implemented separately.